3 # Copyright (c) 2009 Pavol Rusnak
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation
7 # files (the "Software"), to deal in the Software without
8 # restriction, including without limitation the rights to use,
9 # copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 # OTHER DEALINGS IN THE SOFTWARE.
33 package_name
= 'popcorn-client'
34 popcorn_server
= 'stats.opensuse.org'
39 pathre
= '^/(bin|boot|lib|lib64|opt/gnome/bin|opt/gnome/sbin|opt/kde3/bin|opt/kde3/sbin|sbin|usr/bin|usr/games|usr/include|usr/lib|usr/lib64|usr/libexec|usr/sbin|usr/share)/'
42 package_ver
= 'unknown'
43 arch
= platform
.machine()
47 ts
= rpm
.TransactionSet()
48 mi
= ts
.dbMatch('name', package_name
)
50 self
.package_ver
= h
['version']
53 def fill_packages(self
):
54 pathreprg
= re
.compile(pathre
)
55 now
= int(time
.time())
56 ts
= rpm
.TransactionSet()
60 if name
== 'gpg-pubkey': continue
61 installed
= h
[rpm
.RPMTAG_INSTALLTIME
]
62 (accessed
, atime
) = (0, 0)
63 for file in h
[rpm
.RPMTAG_FILENAMES
]:
64 if not pathreprg
.match(file): continue
66 (atime
, ) = os
.stat(file)[7:8]
72 cat
= 'nof' # no-files
74 if now
- installed
< 30 * 86400:
77 if now
- accessed
< 30 * 86400:
81 self
.packages
.append( (cat
, name
) )
85 ret
+= 'START %s %s\n' % (self
.package_ver
, self
.arch
)
86 for pkg
in self
.packages
:
87 ret
+= '%s %s\n' % pkg
92 def submit(self
, body
, compress
= False):
93 conn
= httplib
.HTTPConnection(popcorn_server
)
94 conn
.putrequest('POST', '/popcorn')
95 conn
.putheader('content-type', 'application/octet-stream')
96 conn
.putheader('content-length', str(len(body
)))
101 stats
.fill_packages()
104 # client.submit( stats.serialize() )
106 print stats
.serialize(),