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'
35 pathre
= '^/(bin|sbin|usr/bin|usr/sbin|usr/games|opt/kde3/bin|opt/kde3/sbin|opt/gnome/bin|opt/gnome/sbin|lib|lib64|usr/lib|usr/lib64|include|boot)/'
38 package_ver
= 'unknown'
39 arch
= platform
.machine()
41 now
= int(time
.time())
44 ts
= rpm
.TransactionSet()
45 mi
= ts
.dbMatch('name', package_name
)
47 self
.package_ver
= h
['version']
50 def fill_packages(self
):
51 pathreprg
= re
.compile(pathre
)
52 ts
= rpm
.TransactionSet()
56 if name
== 'gpg-pubkey': continue
57 installed
= h
[rpm
.RPMTAG_INSTALLTIME
]
58 (accessed
, atime
) = (0, 0)
59 for file in h
[rpm
.RPMTAG_FILENAMES
]:
60 if not pathreprg
.match(file): continue
62 (atime
, ) = os
.stat(file)[7:8]
67 self
.packages
.append( (max(self
.now
-installed
, 0), '-' if accessed
==0 else max(self
.now
-accessed
, 0), name
) )
71 ret
+= '%s\n%s\n%s\n' % (self
.now
, self
.arch
, self
.package_ver
)
72 for pkg
in self
.packages
:
73 ret
+= '%s %s %s\n' % pkg
77 def submit(self
, body
, compress
= False):
78 conn
= httplib
.HTTPConnection(popcorn_server
)
79 conn
.putrequest('POST', '/popcorn')
80 conn
.putheader('content-type', 'application/octet-stream')
81 conn
.putheader('content-length', str(len(body
)))
89 # client.submit( stats.serialize() )
91 print stats
.serialize()