Merge lp:~elachuni/weblive/pep8-client into lp:weblive
- pep8-client
- Merge into ltsp-cluster-agent-weblive
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 161 |
Proposed branch: | lp:~elachuni/weblive/pep8-client |
Merge into: | lp:weblive |
Diff against target: |
286 lines (+85/-60) 1 file modified
client/weblive.py (+85/-60) |
To merge this branch: | bzr merge lp:~elachuni/weblive/pep8-client |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Registry Administrators | Pending | ||
Review via email: mp+98195@code.launchpad.net |
Commit message
Description of the change
A branch with whitespace fixes so that client/weblive.py passes the pep8 test.
In software-center we're adding a test that checks code statically using http://
Currently client/weblive.py is copied in as weblive_
To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'client/weblive.py' | |||
2 | --- client/weblive.py 2011-05-04 01:33:40 +0000 | |||
3 | +++ client/weblive.py 2012-03-19 13:15:25 +0000 | |||
4 | @@ -1,5 +1,8 @@ | |||
5 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
7 | 2 | import urllib, urllib2, json | 2 | import json |
8 | 3 | import urllib | ||
9 | 4 | import urllib2 | ||
10 | 5 | |||
11 | 3 | 6 | ||
12 | 4 | class WebLiveJsonError(Exception): | 7 | class WebLiveJsonError(Exception): |
13 | 5 | def __init__(self, value): | 8 | def __init__(self, value): |
14 | @@ -8,6 +11,7 @@ | |||
15 | 8 | def __str__(self): | 11 | def __str__(self): |
16 | 9 | return repr(self.value) | 12 | return repr(self.value) |
17 | 10 | 13 | ||
18 | 14 | |||
19 | 11 | class WebLiveError(Exception): | 15 | class WebLiveError(Exception): |
20 | 12 | def __init__(self, value): | 16 | def __init__(self, value): |
21 | 13 | self.value = value | 17 | self.value = value |
22 | @@ -15,19 +19,23 @@ | |||
23 | 15 | def __str__(self): | 19 | def __str__(self): |
24 | 16 | return repr(self.value) | 20 | return repr(self.value) |
25 | 17 | 21 | ||
26 | 22 | |||
27 | 18 | class WebLiveLocale(object): | 23 | class WebLiveLocale(object): |
28 | 19 | def __init__(self, locale, description): | 24 | def __init__(self, locale, description): |
29 | 20 | self.locale = locale | 25 | self.locale = locale |
30 | 21 | self.description = description | 26 | self.description = description |
31 | 22 | 27 | ||
32 | 28 | |||
33 | 23 | class WebLivePackage(object): | 29 | class WebLivePackage(object): |
34 | 24 | def __init__(self, pkgname, version, autoinstall): | 30 | def __init__(self, pkgname, version, autoinstall): |
35 | 25 | self.pkgname = pkgname | 31 | self.pkgname = pkgname |
36 | 26 | self.version = version | 32 | self.version = version |
37 | 27 | self.autoinstall = autoinstall | 33 | self.autoinstall = autoinstall |
38 | 28 | 34 | ||
39 | 35 | |||
40 | 29 | class WebLiveServer(object): | 36 | class WebLiveServer(object): |
42 | 30 | def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall): | 37 | def __init__(self, name, title, description, timelimit, userlimit, |
43 | 38 | users, autoinstall): | ||
44 | 31 | self.name = name | 39 | self.name = name |
45 | 32 | self.title = title | 40 | self.title = title |
46 | 33 | self.description = description | 41 | self.description = description |
47 | @@ -37,77 +45,94 @@ | |||
48 | 37 | self.autoinstall = autoinstall | 45 | self.autoinstall = autoinstall |
49 | 38 | 46 | ||
50 | 39 | def __repr__(self): | 47 | def __repr__(self): |
53 | 40 | return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s" % ( | 48 | return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, " |
54 | 41 | self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall) | 49 | "current_users=%s, autoinstall=%s") % ( |
55 | 50 | self.name, self.title, self.description, self.timelimit, | ||
56 | 51 | self.userlimit, self.current_users, self.autoinstall) | ||
57 | 52 | |||
58 | 42 | 53 | ||
59 | 43 | class WebLiveEverythingServer(WebLiveServer): | 54 | class WebLiveEverythingServer(WebLiveServer): |
61 | 44 | def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall, locales, packages): | 55 | def __init__(self, name, title, description, timelimit, userlimit, |
62 | 56 | users, autoinstall, locales, packages): | ||
63 | 45 | self.locales = [WebLiveLocale(x[0], x[1]) for x in locales] | 57 | self.locales = [WebLiveLocale(x[0], x[1]) for x in locales] |
64 | 46 | self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages] | 58 | self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages] |
65 | 47 | 59 | ||
67 | 48 | WebLiveServer.__init__(self, name, title, description, timelimit, userlimit, users, autoinstall) | 60 | WebLiveServer.__init__(self, name, title, description, timelimit, |
68 | 61 | userlimit, users, autoinstall) | ||
69 | 49 | 62 | ||
70 | 50 | def __repr__(self): | 63 | def __repr__(self): |
73 | 51 | return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s" % ( | 64 | return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, " |
74 | 52 | self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall, len(self.locales), len(self.packages)) | 65 | "current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s") % ( |
75 | 66 | self.name, self.title, self.description, self.timelimit, | ||
76 | 67 | self.userlimit, self.current_users, self.autoinstall, | ||
77 | 68 | len(self.locales), len(self.packages)) | ||
78 | 69 | |||
79 | 53 | 70 | ||
80 | 54 | class WebLive: | 71 | class WebLive: |
84 | 55 | def __init__(self,url,as_object=False): | 72 | def __init__(self, url, as_object=False): |
85 | 56 | self.url=url | 73 | self.url = url |
86 | 57 | self.as_object=as_object | 74 | self.as_object = as_object |
87 | 58 | 75 | ||
90 | 59 | def do_query(self,query): | 76 | def do_query(self, query): |
91 | 60 | page=urllib2.Request(self.url,urllib.urlencode({'query':json.dumps(query)})) | 77 | page = urllib2.Request(self.url, urllib.urlencode( |
92 | 78 | {'query': json.dumps(query)})) | ||
93 | 61 | 79 | ||
94 | 62 | try: | 80 | try: |
96 | 63 | response=urllib2.urlopen(page) | 81 | response = urllib2.urlopen(page) |
97 | 64 | except urllib2.HTTPError, e: | 82 | except urllib2.HTTPError, e: |
98 | 65 | raise WebLiveJsonError("HTTP return code: %s" % e.code) | 83 | raise WebLiveJsonError("HTTP return code: %s" % e.code) |
99 | 66 | except urllib2.URLError, e: | 84 | except urllib2.URLError, e: |
100 | 67 | raise WebLiveJsonError("Failed to reach server: %s" % e.reason) | 85 | raise WebLiveJsonError("Failed to reach server: %s" % e.reason) |
101 | 68 | 86 | ||
102 | 69 | try: | 87 | try: |
104 | 70 | reply=json.loads(response.read()) | 88 | reply = json.loads(response.read()) |
105 | 71 | except ValueError: | 89 | except ValueError: |
106 | 72 | raise WebLiveJsonError("Returned json object is invalid.") | 90 | raise WebLiveJsonError("Returned json object is invalid.") |
107 | 73 | 91 | ||
108 | 74 | if reply['status'] != 'ok': | 92 | if reply['status'] != 'ok': |
109 | 75 | if reply['message'] == -1: | 93 | if reply['message'] == -1: |
111 | 76 | raise WebliveJsonError("Missing 'action' field in query.") | 94 | raise WebLiveJsonError("Missing 'action' field in query.") |
112 | 77 | elif reply['message'] == -2: | 95 | elif reply['message'] == -2: |
113 | 78 | raise WebLiveJsonError("Missing parameter") | 96 | raise WebLiveJsonError("Missing parameter") |
114 | 79 | elif reply['message'] == -3: | 97 | elif reply['message'] == -3: |
116 | 80 | raise WebliveJsonError("Function '%s' isn't exported over JSON." % query['action']) | 98 | raise WebLiveJsonError("Function '%s' isn't exported " |
117 | 99 | "over JSON." % query['action']) | ||
118 | 81 | else: | 100 | else: |
120 | 82 | raise WebLiveJsonError("Unknown error code: %s" % reply['message']) | 101 | raise WebLiveJsonError("Unknown error code: %s" % |
121 | 102 | reply['message']) | ||
122 | 83 | 103 | ||
123 | 84 | if 'message' not in reply: | 104 | if 'message' not in reply: |
124 | 85 | raise WebLiveJsonError("Invalid json reply") | 105 | raise WebLiveJsonError("Invalid json reply") |
125 | 86 | 106 | ||
126 | 87 | return reply | 107 | return reply |
127 | 88 | 108 | ||
138 | 89 | def create_user(self,serverid,username,fullname,password,session,locale): | 109 | def create_user(self, serverid, username, fullname, password, |
139 | 90 | query={} | 110 | session, locale): |
140 | 91 | query['action']='create_user' | 111 | query = {} |
141 | 92 | query['serverid']=serverid | 112 | query['action'] = 'create_user' |
142 | 93 | query['username']=username | 113 | query['serverid'] = serverid |
143 | 94 | query['fullname']=fullname | 114 | query['username'] = username |
144 | 95 | query['password']=password | 115 | query['fullname'] = fullname |
145 | 96 | query['session']=session | 116 | query['password'] = password |
146 | 97 | query['locale']=locale | 117 | query['session'] = session |
147 | 98 | reply=self.do_query(query) | 118 | query['locale'] = locale |
148 | 119 | reply = self.do_query(query) | ||
149 | 99 | 120 | ||
150 | 100 | if type(reply['message']) != type([]): | 121 | if type(reply['message']) != type([]): |
151 | 101 | if reply['message'] == 1: | 122 | if reply['message'] == 1: |
152 | 102 | raise WebLiveError("Reached user limit, return false.") | 123 | raise WebLiveError("Reached user limit, return false.") |
153 | 103 | elif reply['message'] == 2: | 124 | elif reply['message'] == 2: |
155 | 104 | raise WebLiveError("Different user with same username already exists.") | 125 | raise WebLiveError("Different user with same username " |
156 | 126 | "already exists.") | ||
157 | 105 | elif reply['message'] == 3: | 127 | elif reply['message'] == 3: |
159 | 106 | raise WebLiveError("Invalid fullname, must only contain alphanumeric characters and spaces.") | 128 | raise WebLiveError("Invalid fullname, must only contain " |
160 | 129 | "alphanumeric characters and spaces.") | ||
161 | 107 | elif reply['message'] == 4: | 130 | elif reply['message'] == 4: |
163 | 108 | raise WebLiveError("Invalid login, must only contain lowercase letters.") | 131 | raise WebLiveError("Invalid login, must only contain " |
164 | 132 | "lowercase letters.") | ||
165 | 109 | elif reply['message'] == 5: | 133 | elif reply['message'] == 5: |
167 | 110 | raise WebLiveError("Invalid password, must contain only alphanumeric characters.") | 134 | raise WebLiveError("Invalid password, must contain only " |
168 | 135 | "alphanumeric characters.") | ||
169 | 111 | elif reply['message'] == 7: | 136 | elif reply['message'] == 7: |
170 | 112 | raise WebLiveError("Invalid server: %s" % serverid) | 137 | raise WebLiveError("Invalid server: %s" % serverid) |
171 | 113 | else: | 138 | else: |
172 | @@ -116,20 +141,20 @@ | |||
173 | 116 | return reply['message'] | 141 | return reply['message'] |
174 | 117 | 142 | ||
175 | 118 | def list_everything(self): | 143 | def list_everything(self): |
179 | 119 | query={} | 144 | query = {} |
180 | 120 | query['action']='list_everything' | 145 | query['action'] = 'list_everything' |
181 | 121 | reply=self.do_query(query) | 146 | reply = self.do_query(query) |
182 | 122 | 147 | ||
183 | 123 | if type(reply['message']) != type({}): | 148 | if type(reply['message']) != type({}): |
184 | 124 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." | 149 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
186 | 125 | % (type({}),type(reply['message']))) | 150 | % (type({}), type(reply['message']))) |
187 | 126 | 151 | ||
188 | 127 | if not self.as_object: | 152 | if not self.as_object: |
189 | 128 | return reply['message'] | 153 | return reply['message'] |
190 | 129 | else: | 154 | else: |
192 | 130 | servers=[] | 155 | servers = [] |
193 | 131 | for server in reply['message']: | 156 | for server in reply['message']: |
195 | 132 | attr=reply['message'][server] | 157 | attr = reply['message'][server] |
196 | 133 | servers.append(WebLiveEverythingServer( | 158 | servers.append(WebLiveEverythingServer( |
197 | 134 | server, | 159 | server, |
198 | 135 | attr['title'], | 160 | attr['title'], |
199 | @@ -142,15 +167,15 @@ | |||
200 | 142 | attr['packages'])) | 167 | attr['packages'])) |
201 | 143 | return servers | 168 | return servers |
202 | 144 | 169 | ||
208 | 145 | def list_locales(self,serverid): | 170 | def list_locales(self, serverid): |
209 | 146 | query={} | 171 | query = {} |
210 | 147 | query['action']='list_locales' | 172 | query['action'] = 'list_locales' |
211 | 148 | query['serverid']=serverid | 173 | query['serverid'] = serverid |
212 | 149 | reply=self.do_query(query) | 174 | reply = self.do_query(query) |
213 | 150 | 175 | ||
214 | 151 | if type(reply['message']) != type([]): | 176 | if type(reply['message']) != type([]): |
215 | 152 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." | 177 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
217 | 153 | % (type({}),type(reply['message']))) | 178 | % (type({}), type(reply['message']))) |
218 | 154 | 179 | ||
219 | 155 | if not self.as_object: | 180 | if not self.as_object: |
220 | 156 | return reply['message'] | 181 | return reply['message'] |
221 | @@ -158,28 +183,28 @@ | |||
222 | 158 | return [WebLiveLocale(x[0], x[1]) for x in reply['message']] | 183 | return [WebLiveLocale(x[0], x[1]) for x in reply['message']] |
223 | 159 | 184 | ||
224 | 160 | def list_package_blacklist(self): | 185 | def list_package_blacklist(self): |
228 | 161 | query={} | 186 | query = {} |
229 | 162 | query['action']='list_package_blacklist' | 187 | query['action'] = 'list_package_blacklist' |
230 | 163 | reply=self.do_query(query) | 188 | reply = self.do_query(query) |
231 | 164 | 189 | ||
232 | 165 | if type(reply['message']) != type([]): | 190 | if type(reply['message']) != type([]): |
233 | 166 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." | 191 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
235 | 167 | % (type({}),type(reply['message']))) | 192 | % (type({}), type(reply['message']))) |
236 | 168 | 193 | ||
237 | 169 | if not self.as_object: | 194 | if not self.as_object: |
238 | 170 | return reply['message'] | 195 | return reply['message'] |
239 | 171 | else: | 196 | else: |
240 | 172 | return [WebLivePackage(x, None, None) for x in reply['message']] | 197 | return [WebLivePackage(x, None, None) for x in reply['message']] |
241 | 173 | 198 | ||
247 | 174 | def list_packages(self,serverid): | 199 | def list_packages(self, serverid): |
248 | 175 | query={} | 200 | query = {} |
249 | 176 | query['action']='list_packages' | 201 | query['action'] = 'list_packages' |
250 | 177 | query['serverid']=serverid | 202 | query['serverid'] = serverid |
251 | 178 | reply=self.do_query(query) | 203 | reply = self.do_query(query) |
252 | 179 | 204 | ||
253 | 180 | if type(reply['message']) != type([]): | 205 | if type(reply['message']) != type([]): |
254 | 181 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." | 206 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
256 | 182 | % (type({}),type(reply['message']))) | 207 | % (type({}), type(reply['message']))) |
257 | 183 | 208 | ||
258 | 184 | if not self.as_object: | 209 | if not self.as_object: |
259 | 185 | return reply['message'] | 210 | return reply['message'] |
260 | @@ -187,20 +212,20 @@ | |||
261 | 187 | return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']] | 212 | return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']] |
262 | 188 | 213 | ||
263 | 189 | def list_servers(self): | 214 | def list_servers(self): |
267 | 190 | query={} | 215 | query = {} |
268 | 191 | query['action']='list_servers' | 216 | query['action'] = 'list_servers' |
269 | 192 | reply=self.do_query(query) | 217 | reply = self.do_query(query) |
270 | 193 | 218 | ||
271 | 194 | if type(reply['message']) != type({}): | 219 | if type(reply['message']) != type({}): |
272 | 195 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." | 220 | raise WebLiveError("Invalid value, expected '%s' and got '%s'." |
274 | 196 | % (type({}),type(reply['message']))) | 221 | % (type({}), type(reply['message']))) |
275 | 197 | 222 | ||
276 | 198 | if not self.as_object: | 223 | if not self.as_object: |
277 | 199 | return reply['message'] | 224 | return reply['message'] |
278 | 200 | else: | 225 | else: |
280 | 201 | servers=[] | 226 | servers = [] |
281 | 202 | for server in reply['message']: | 227 | for server in reply['message']: |
283 | 203 | attr=reply['message'][server] | 228 | attr = reply['message'][server] |
284 | 204 | servers.append(WebLiveServer( | 229 | servers.append(WebLiveServer( |
285 | 205 | server, | 230 | server, |
286 | 206 | attr['title'], | 231 | attr['title'], |
Could somone please have a look at this? Stephane :) ?