Gentoo Archives: gentoo-commits

From: Vikraman Choudhury <vikraman.choudhury@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoostats:master commit in: client/bin/
Date: Fri, 06 May 2011 13:25:11
Message-Id: 3c62442a093c2ac94f4bc1335d074e285c18b0b0.vikraman@gentoo
1 commit: 3c62442a093c2ac94f4bc1335d074e285c18b0b0
2 Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
3 AuthorDate: Fri May 6 13:24:17 2011 +0000
4 Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
5 CommitDate: Fri May 6 13:24:17 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=3c62442a
7
8 changes to client to post collected data to server
9
10 ---
11 client/bin/client | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
12 1 files changed, 45 insertions(+), 8 deletions(-)
13
14 diff --git a/client/bin/client b/client/bin/client
15 index c41de84..f920250 100755
16 --- a/client/bin/client
17 +++ b/client/bin/client
18 @@ -3,18 +3,55 @@
19 from packages import Packages
20 from useflags import UseFlags
21 from environment import Environment
22 +import json
23 +import urllib, httplib
24
25 -def main():
26 +def getAuthInfo():
27 + #TODO: Return public uuid and md5sum of password
28 + auth_info = {
29 + "UUID": "254e308c-d6a0-405c-aa1f-f21d9c1ea6e1",
30 + "PASSWD": "5f4dcc3b5aa765d61d8327deb882cf99"
31 + }
32 + return auth_info
33 +
34 +def getPostData():
35 p = Packages()
36 u = UseFlags()
37 - for cpv in p.getInstalledCPVs():
38 - print cpv,
39 - for x in u.getUseFlags(cpv):
40 - print x,
41 - print
42 e = Environment()
43 - for var in ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CHOST', 'FEATURES'):
44 - print e.getVar(var)
45 +
46 + post_data = {}
47 + post_data['PROTOCOL'] = 1
48 + post_data['AUTH'] = getAuthInfo()
49 + for key in ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CHOST', 'FEATURES'):
50 + post_data[key] = e.getVar(key)
51 +
52 + packages = {}
53 + for cpv in p.getInstalledCPVs(sort=True):
54 + packages[cpv] = u.getUseFlags(cpv)
55 + post_data['PACKAGES'] = packages
56 +
57 + return post_data
58 +
59 +def serialize(object, human=False):
60 + if human:
61 + indent = 2
62 + sort_keys = True
63 + else:
64 + indent = None
65 + sort_keys = False
66 + return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
67 +
68 +def main():
69 + post_body = serialize(getPostData(), human=True)
70 + print post_body
71 + post_headers = {"Content-type": "application/json"}
72 + myuuid = getAuthInfo()['UUID']
73 + conn = httplib.HTTPConnection("127.0.0.1:8080")
74 + conn.request('POST', '/' + myuuid, headers=post_headers, body=post_body)
75 + #TODO: Handle exceptions
76 + response = conn.getresponse()
77 + print response.status, response.reason
78 + print 'Server response: ' + response.read()
79
80 if __name__ == "__main__":
81 main()