From d7405a7396fc41d29219575b596ffb8fddefaf43 Mon Sep 17 00:00:00 2001
Message-Id: <d7405a7396fc41d29219575b596ffb8fddefaf43.1336686222.git.humitos@gmail.com>
From: Manuel Kaufmann <humitos@gmail.com>
Date: Thu, 10 May 2012 17:47:48 -0300
Subject: [PATCH Log 1/2] pep8-ized logcollect.py
Passed pep8.py script to remove a lot of trailling whitespaces and
things related.
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
---
logcollect.py | 278 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 146 insertions(+), 132 deletions(-)
diff --git a/logcollect.py b/logcollect.py
index 82c1bba..956cc24 100644
a
|
b
|
|
1 | | # Copyright (C) 2007, Pascal Scheffers <pascal@scheffers.net> |
| 1 | # Copyright (C) 2007, Pascal Scheffers <pascal@scheffers.net> |
2 | 2 | # |
3 | 3 | # Permission is hereby granted, free of charge, to any person |
4 | 4 | # obtaining a copy of this software and associated documentation |
… |
… |
|
33 | 33 | # ** ... |
34 | 34 | # * Installed packages list |
35 | 35 | # * All relevant log files (all of them, at first) |
36 | | # |
| 36 | # |
37 | 37 | # The report is output as a tarfile |
38 | 38 | # |
39 | 39 | # This file has two modes: |
… |
… |
class MachineProperties: |
78 | 78 | return '#/etc/issue not found' |
79 | 79 | |
80 | 80 | # Needed, because we want to default to the first non blank line: |
81 | | first_line = '' |
| 81 | first_line = '' |
82 | 82 | |
83 | 83 | for line in self.__read_file('/etc/issue').splitlines(): |
84 | 84 | if line.lower().find('olpc build') > -1: |
85 | | return line |
| 85 | return line |
86 | 86 | if first_line == '': |
87 | | first_line=line |
| 87 | first_line = line |
88 | 88 | |
89 | 89 | return first_line |
90 | 90 | |
91 | 91 | def uptime(self): |
92 | 92 | for line in self.__read_file('/proc/uptime').splitlines(): |
93 | 93 | if line != '': |
94 | | return line |
| 94 | return line |
95 | 95 | return '' |
96 | 96 | |
97 | 97 | def loadavg(self): |
98 | 98 | for line in self.__read_file('/proc/loadavg').splitlines(): |
99 | 99 | if line != '': |
100 | | return line |
| 100 | return line |
101 | 101 | return '' |
102 | 102 | |
103 | 103 | def kernel_version(self): |
104 | 104 | for line in self.__read_file('/proc/version').splitlines(): |
105 | 105 | if line != '': |
106 | | return line |
| 106 | return line |
107 | 107 | return '' |
108 | 108 | |
109 | 109 | def memfree(self): |
… |
… |
class MachineProperties: |
126 | 126 | |
127 | 127 | v = self.__read_file(mfg_path) |
128 | 128 | # Remove trailing 0 character, if any: |
129 | | if v != '' and ord(v[len(v)-1]) == 0: |
130 | | v = v[:len(v)-1] |
131 | | |
| 129 | if v != '' and ord(v[len(v) - 1]) == 0: |
| 130 | v = v[:len(v) - 1] |
| 131 | |
132 | 132 | return v |
133 | | |
| 133 | |
134 | 134 | def laptop_serial_number(self): |
135 | 135 | return self._mfg_data('SN') |
136 | 136 | |
… |
… |
class MachineProperties: |
141 | 141 | s = self._mfg_data('SG')[0:1] |
142 | 142 | if s == '': |
143 | 143 | return '' |
144 | | |
| 144 | |
145 | 145 | return '%02X' % ord(self._mfg_data('SG')[0:1]) |
146 | | |
147 | 146 | |
148 | 147 | def laptop_uuid(self): |
149 | 148 | return self._mfg_data('U#') |
… |
… |
class MachineProperties: |
165 | 164 | |
166 | 165 | def laptop_localization(self): |
167 | 166 | return self._mfg_data('LO') |
168 | | |
| 167 | |
169 | 168 | def _battery_info(self, item): |
170 | 169 | """ from /sys/class/power-supply/olpc-battery/ """ |
171 | 170 | root = '/sys/class/power_supply/olpc-battery/' |
172 | | if not os.path.exists(root+item): |
| 171 | if not os.path.exists(root + item): |
173 | 172 | return '' |
174 | | |
175 | | return self.__read_file(root+item).strip() |
| 173 | |
| 174 | return self.__read_file(root + item).strip() |
176 | 175 | |
177 | 176 | def battery_serial_number(self): |
178 | 177 | return self._battery_info('serial_number') |
179 | | |
| 178 | |
180 | 179 | def battery_capacity(self): |
181 | 180 | return self._battery_info('capacity') + ' ' + \ |
182 | 181 | self._battery_info('capacity_level') |
… |
… |
class MachineProperties: |
184 | 183 | def battery_info(self): |
185 | 184 | #Should be just: |
186 | 185 | #return self._battery_info('uevent') |
187 | | |
| 186 | |
188 | 187 | #But because of a bug in the kernel, that has trash, lets filter: |
189 | | bi = '' |
| 188 | bi = '' |
190 | 189 | for line in self._battery_info('uevent').splitlines(): |
191 | 190 | if line.startswith('POWER_'): |
192 | 191 | bi += line + '\n' |
193 | | |
| 192 | |
194 | 193 | return bi |
195 | | |
| 194 | |
196 | 195 | def disksize(self, path): |
197 | 196 | return os.statvfs(path).f_bsize * os.statvfs(path).f_blocks |
198 | | |
| 197 | |
199 | 198 | def diskfree(self, path): |
200 | 199 | return os.statvfs(path).f_bsize * os.statvfs(path).f_bavail |
201 | | |
| 200 | |
202 | 201 | def _read_popen(self, cmd): |
203 | 202 | p = os.popen(cmd) |
204 | 203 | s = '' |
205 | 204 | try: |
206 | 205 | for line in p: |
207 | | s += line |
| 206 | s += line |
208 | 207 | finally: |
209 | | p.close() |
210 | | |
| 208 | p.close() |
| 209 | |
211 | 210 | return s |
212 | | |
213 | | def ifconfig(self): |
| 211 | |
| 212 | def ifconfig(self): |
214 | 213 | return self._read_popen('/sbin/ifconfig') |
215 | | |
216 | | def route_n(self): |
| 214 | |
| 215 | def route_n(self): |
217 | 216 | return self._read_popen('/sbin/route -n') |
218 | | |
| 217 | |
219 | 218 | def df_a(self): |
220 | 219 | return self._read_popen('/bin/df -a') |
221 | | |
| 220 | |
222 | 221 | def ps_auxfwww(self): |
223 | 222 | return self._read_popen('/bin/ps auxfwww') |
224 | | |
| 223 | |
225 | 224 | def usr_bin_free(self): |
226 | 225 | return self._read_popen('/usr/bin/free') |
227 | 226 | |
228 | 227 | def top(self): |
229 | 228 | return self._read_popen('/usr/bin/top -bn2') |
230 | | |
231 | | def installed_activities(self): |
232 | | s = '' |
| 229 | |
| 230 | def installed_activities(self): |
| 231 | s = '' |
233 | 232 | for path in glob.glob('/usr/share/activities/*.activity'): |
234 | 233 | s += os.path.basename(path) + '\n' |
235 | 234 | |
236 | 235 | for path in glob.glob('/home/olpc/Activities/*'): |
237 | 236 | s += '~' + os.path.basename(path) + '\n' |
238 | | |
| 237 | |
239 | 238 | return s |
240 | | |
241 | | |
| 239 | |
242 | 240 | |
243 | 241 | class LogCollect: |
244 | 242 | """Collect XO logfiles and machine metadata for reporting to OLPC |
… |
… |
class LogCollect: |
248 | 246 | self._mp = MachineProperties() |
249 | 247 | |
250 | 248 | def write_logs(self, archive='', logbytes=15360): |
251 | | """Write a zipfile containing the tails of the logfiles and machine info of the XO |
252 | | |
| 249 | """Write a zipfile containing the tails of the logfiles and |
| 250 | machine info of the XO |
| 251 | |
253 | 252 | Arguments: |
254 | 253 | archive - Specifies the location where to store the data |
255 | 254 | defaults to /dev/shm/logs-<xo-serial>.zip |
256 | | |
| 255 | |
257 | 256 | logbytes - Maximum number of bytes to read from each log file. |
258 | 257 | 0 means complete logfiles, not just the tail |
259 | 258 | -1 means only save machine info, no logs |
260 | 259 | """ |
261 | 260 | #This function is crammed with try...except to make sure we get as much |
262 | 261 | #data as possible, if anything fails. |
263 | | |
264 | | if archive=='': |
| 262 | |
| 263 | if archive == '': |
265 | 264 | archive = '/dev/shm/logs.zip' |
266 | 265 | try: |
267 | 266 | #With serial number is more convenient, but might fail for some |
268 | 267 | #Unknown reason... |
269 | | archive = '/dev/shm/logs-%s.zip' % self._mp.laptop_serial_number() |
| 268 | archive = '/dev/shm/logs-%s.zip' % \ |
| 269 | self._mp.laptop_serial_number() |
270 | 270 | except Exception: |
271 | 271 | pass |
272 | | |
| 272 | |
273 | 273 | z = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED) |
274 | | |
275 | | try: |
276 | | try: |
| 274 | |
| 275 | try: |
| 276 | try: |
277 | 277 | z.writestr('info.txt', self.laptop_info()) |
278 | 278 | except Exception, e: |
279 | 279 | z.writestr('info.txt', |
280 | 280 | "logcollect: could not add info.txt: %s" % e) |
281 | | |
282 | | if logbytes > -1: |
| 281 | if logbytes > -1: |
283 | 282 | # Include some log files from /var/log. |
284 | | for fn in ['dmesg', 'messages', 'cron', 'maillog','rpmpkgs', |
| 283 | for fn in ['dmesg', 'messages', 'cron', 'maillog', 'rpmpkgs', |
285 | 284 | 'Xorg.0.log', 'spooler']: |
286 | 285 | try: |
287 | | if os.access('/var/log/'+fn, os.F_OK): |
| 286 | if os.access('/var/log/' + fn, os.F_OK): |
288 | 287 | if logbytes == 0: |
289 | | z.write('/var/log/'+fn, 'var-log/'+fn) |
| 288 | z.write('/var/log/' + fn, 'var-log/' + fn) |
290 | 289 | else: |
291 | | z.writestr('var-log/'+fn, |
292 | | self.file_tail('/var/log/'+fn, logbytes)) |
| 290 | z.writestr('var-log/' + fn, |
| 291 | self.file_tail('/var/log/' + fn, |
| 292 | logbytes)) |
293 | 293 | except Exception, e: |
294 | | z.writestr('var-log/'+fn, |
295 | | "logcollect: could not add %s: %s" % (fn, e)) |
296 | | |
| 294 | z.writestr('var-log/' + fn, |
| 295 | "logcollect: could not add %s: %s" % \ |
| 296 | (fn, e)) |
| 297 | |
297 | 298 | # Include all current ones from sugar/logs |
298 | 299 | for path in glob.glob('/home/olpc/.sugar/default/logs/*.log'): |
299 | 300 | try: |
300 | 301 | if os.access(path, os.F_OK): |
301 | 302 | if logbytes == 0: |
302 | | z.write(path, 'sugar-logs/'+os.path.basename(path)) |
| 303 | z.write(path, 'sugar-logs/' + \ |
| 304 | os.path.basename(path)) |
303 | 305 | else: |
304 | | z.writestr('sugar-logs/'+os.path.basename(path), |
| 306 | z.writestr('sugar-logs/' + \ |
| 307 | os.path.basename(path), |
305 | 308 | self.file_tail(path, logbytes)) |
306 | 309 | except Exception, e: |
307 | | z.writestr('sugar-logs/'+fn, |
308 | | "logcollect: could not add %s: %s" % (fn, e)) |
309 | | try: |
| 310 | z.writestr('sugar-logs/' + fn, |
| 311 | "logcollect: could not add %s: %s" % \ |
| 312 | (fn, e)) |
| 313 | try: |
310 | 314 | z.write('/etc/resolv.conf') |
311 | 315 | except Exception, e: |
312 | 316 | z.writestr('/etc/resolv.conf', |
313 | 317 | "logcollect: could not add resolv.conf: %s" % e) |
314 | | |
| 318 | |
315 | 319 | except Exception, e: |
316 | | print 'While creating zip archive: %s' % e |
317 | | |
318 | | z.close() |
319 | | |
| 320 | print 'While creating zip archive: %s' % e |
| 321 | |
| 322 | z.close() |
| 323 | |
320 | 324 | return archive |
321 | 325 | |
322 | 326 | def file_tail(self, filename, tailbytes): |
323 | 327 | """Read the tail (end) of the file |
324 | | |
| 328 | |
325 | 329 | Arguments: |
326 | 330 | filename The name of the file to read |
327 | 331 | tailbytes Number of bytes to include or 0 for entire file |
… |
… |
class LogCollect: |
332 | 336 | f = open(filename) |
333 | 337 | try: |
334 | 338 | fsize = os.stat(filename).st_size |
335 | | |
| 339 | |
336 | 340 | if tailbytes > 0 and fsize > tailbytes: |
337 | 341 | f.seek(-tailbytes, 2) |
338 | | |
| 342 | |
339 | 343 | data = f.read() |
340 | 344 | finally: |
341 | 345 | f.close() |
342 | 346 | |
343 | | return data |
344 | | |
| 347 | return data |
345 | 348 | |
346 | 349 | def make_report(self, target='stdout'): |
347 | 350 | """Create the report |
348 | 351 | |
349 | 352 | Arguments: |
350 | | target - where to save the logs, a path or stdout |
| 353 | target - where to save the logs, a path or stdout |
351 | 354 | |
352 | 355 | """ |
353 | 356 | |
354 | 357 | li = self.laptop_info() |
355 | 358 | for k, v in li.iteritems(): |
356 | | print k + ': ' +v |
357 | | |
| 359 | print k + ': ' + v |
| 360 | |
358 | 361 | print self._mp.battery_info() |
359 | 362 | |
360 | 363 | def laptop_info(self): |
361 | | """Return a string with laptop serial, battery type, build, memory info, etc.""" |
| 364 | """Return a string with laptop serial, battery type, build, |
| 365 | memory info, etc.""" |
362 | 366 | |
363 | | s = '' |
| 367 | s = '' |
364 | 368 | try: |
365 | 369 | # Do not include UUID! |
366 | 370 | s += 'laptop-info-version: 1.0\n' |
… |
… |
class LogCollect: |
368 | 372 | s += 'date: %s' % time.strftime("%a, %d %b %Y %H:%M:%S +0000", |
369 | 373 | time.gmtime()) |
370 | 374 | s += 'memfree: %s\n' % self._mp.memfree() |
371 | | s += 'disksize: %s MB\n' % ( self._mp.disksize('/') / (1024*1024) ) |
372 | | s += 'diskfree: %s MB\n' % ( self._mp.diskfree('/') / (1024*1024) ) |
| 375 | s += 'disksize: %s MB\n' % \ |
| 376 | (self._mp.disksize('/') / (1024 * 1024)) |
| 377 | s += 'diskfree: %s MB\n' % \ |
| 378 | (self._mp.diskfree('/') / (1024 * 1024)) |
373 | 379 | s += 'olpc_build: %s\n' % self._mp.olpc_build() |
374 | 380 | s += 'kernel_version: %s\n' % self._mp.kernel_version() |
375 | 381 | s += 'uptime: %s\n' % self._mp.uptime() |
376 | | s += 'loadavg: %s\n' % self._mp.loadavg() |
| 382 | s += 'loadavg: %s\n' % self._mp.loadavg() |
377 | 383 | s += 'serial-number: %s\n' % self._mp.laptop_serial_number() |
378 | | s += 'motherboard-number: %s\n' % self._mp.laptop_motherboard_number() |
379 | | s += 'board-revision: %s\n' % self._mp.laptop_board_revision() |
380 | | s += 'keyboard: %s\n' % self._mp.laptop_keyboard() |
381 | | s += 'wireless_mac: %s\n' % self._mp.laptop_wireless_mac() |
382 | | s += 'firmware: %s\n' % self._mp.laptop_bios_version() |
| 384 | s += 'motherboard-number: %s\n' % \ |
| 385 | self._mp.laptop_motherboard_number() |
| 386 | s += 'board-revision: %s\n' % \ |
| 387 | self._mp.laptop_board_revision() |
| 388 | s += 'keyboard: %s\n' % \ |
| 389 | self._mp.laptop_keyboard() |
| 390 | s += 'wireless_mac: %s\n' % \ |
| 391 | self._mp.laptop_wireless_mac() |
| 392 | s += 'firmware: %s\n' % \ |
| 393 | self._mp.laptop_bios_version() |
383 | 394 | s += 'country: %s\n' % self._mp.laptop_country() |
384 | 395 | s += 'localization: %s\n' % self._mp.laptop_localization() |
385 | | |
| 396 | |
386 | 397 | s += self._mp.battery_info() |
387 | | |
| 398 | |
388 | 399 | s += "\n[/sbin/ifconfig]\n%s\n" % self._mp.ifconfig() |
389 | 400 | s += "\n[/sbin/route -n]\n%s\n" % self._mp.route_n() |
390 | | |
391 | | s += '\n[Installed Activities]\n%s\n' % self._mp.installed_activities() |
392 | | |
| 401 | |
| 402 | s += '\n[Installed Activities]\n%s\n' % \ |
| 403 | self._mp.installed_activities() |
| 404 | |
393 | 405 | s += '\n[df -a]\n%s\n' % self._mp.df_a() |
394 | 406 | s += '\n[ps auxwww]\n%s\n' % self._mp.ps_auxfwww() |
395 | 407 | s += '\n[free]\n%s\n' % self._mp.usr_bin_free() |
396 | 408 | s += '\n[top -bn2]\n%s\n' % self._mp.top() |
397 | 409 | except Exception, e: |
398 | 410 | s += '\nException while building info:\n%s\n' % e |
399 | | |
| 411 | |
400 | 412 | return s |
401 | 413 | |
| 414 | |
402 | 415 | class LogSend: |
403 | | |
404 | 416 | # post_multipart and encode_multipart_formdata have been taken from |
405 | | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 |
| 417 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 |
406 | 418 | def post_multipart(self, host, selector, fields, files): |
407 | 419 | """ |
408 | 420 | Post fields and files to an http host as multipart/form-data. |
409 | | fields is a sequence of (name, value) elements for regular form fields. |
410 | | files is a sequence of (name, filename, value) elements for data to be uploaded as files |
411 | | Return the server's response page. |
| 421 | fields is a sequence of (name, value) elements for regular |
| 422 | form fields. |
| 423 | |
| 424 | files is a sequence of (name, filename, value) elements for |
| 425 | data to be uploaded as files Return the server's response |
| 426 | page. |
412 | 427 | """ |
| 428 | |
413 | 429 | content_type, body = self.encode_multipart_formdata(fields, files) |
414 | 430 | h = httplib.HTTP(host) |
415 | 431 | h.putrequest('POST', selector) |
… |
… |
class LogSend: |
420 | 436 | h.send(body) |
421 | 437 | errcode, errmsg, headers = h.getreply() |
422 | 438 | return h.file.read() |
423 | | |
| 439 | |
424 | 440 | def encode_multipart_formdata(self, fields, files): |
425 | 441 | """ |
426 | 442 | fields is a sequence of (name, value) elements for regular form fields. |
427 | | files is a sequence of (name, filename, value) elements for data to be uploaded as files |
428 | | Return (content_type, body) ready for httplib.HTTP instance |
| 443 | |
| 444 | files is a sequence of (name, filename, value) elements for |
| 445 | data to be uploaded as files Return (content_type, body) ready |
| 446 | for httplib.HTTP instance |
429 | 447 | """ |
| 448 | |
430 | 449 | BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' |
431 | 450 | CRLF = '\r\n' |
432 | 451 | L = [] |
… |
… |
class LogSend: |
437 | 456 | L.append(value) |
438 | 457 | for (key, filename, value) in files: |
439 | 458 | L.append('--' + BOUNDARY) |
440 | | L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) |
| 459 | L.append('Content-Disposition: form-data; name="%s"; ' |
| 460 | 'filename="%s"' % (key, filename)) |
441 | 461 | L.append('Content-Type: %s' % self.get_content_type(filename)) |
442 | 462 | L.append('') |
443 | 463 | L.append(value) |
… |
… |
class LogSend: |
446 | 466 | body = CRLF.join(L) |
447 | 467 | content_type = 'multipart/form-data; boundary=%s' % BOUNDARY |
448 | 468 | return content_type, body |
449 | | |
| 469 | |
450 | 470 | def read_file(self, filename): |
451 | 471 | """Read the entire contents of a file and return it as a string""" |
452 | 472 | |
… |
… |
class LogSend: |
462 | 482 | |
463 | 483 | def get_content_type(self, filename): |
464 | 484 | return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
465 | | |
| 485 | |
466 | 486 | def http_post_logs(self, url, archive): |
467 | 487 | #host, selector, fields, files |
468 | 488 | files = ('logs', os.path.basename(archive), self.read_file(archive)), |
469 | | |
| 489 | |
470 | 490 | # Client= olpc will make the server return just "OK" or "FAIL" |
471 | 491 | fields = ('client', 'xo'), |
472 | 492 | urlparts = urlparse.urlsplit(url) |
… |
… |
class LogSend: |
475 | 495 | print r |
476 | 496 | return (r == 'OK') |
477 | 497 | |
478 | | |
479 | 498 | # This script is dual-mode, it can be used as a command line tool and as |
480 | | # a library. |
| 499 | # a library. |
481 | 500 | if sys.argv[0].endswith('logcollect.py') or \ |
482 | 501 | sys.argv[0].endswith('logcollect'): |
483 | 502 | print 'log-collect utility 1.0' |
484 | | |
| 503 | |
485 | 504 | lc = LogCollect() |
486 | 505 | ls = LogSend() |
487 | 506 | |
488 | 507 | logs = '' |
489 | 508 | mode = 'http' |
490 | | |
491 | | if len(sys.argv)==1: |
| 509 | |
| 510 | if len(sys.argv) == 1: |
492 | 511 | print """logcollect.py - send your XO logs to OLPC |
493 | | |
| 512 | |
494 | 513 | Usage: |
495 | 514 | logcollect.py http://server.name/submit.php |
496 | 515 | - submit logs to a server |
497 | | |
| 516 | |
498 | 517 | logcollect.py file:/media/xxxx-yyyy/mylog.zip |
499 | 518 | - save the zip file on a USB device or SD card |
500 | | |
| 519 | |
501 | 520 | logcollect.py all file:/media/xxxx-yyyy/mylog.zip |
502 | 521 | - Save to zip file and include ALL logs |
503 | 522 | |
… |
… |
Usage: |
510 | 529 | If you specify 'all' or 'none' you must specify http or file as well. |
511 | 530 | """ |
512 | 531 | sys.exit() |
513 | | |
514 | | |
515 | | logbytes = 15360 |
516 | | if len(sys.argv)>1: |
517 | | mode = sys.argv[len(sys.argv)-1] |
| 532 | |
| 533 | logbytes = 15360 |
| 534 | if len(sys.argv) > 1: |
| 535 | mode = sys.argv[len(sys.argv) - 1] |
518 | 536 | if sys.argv[1] == 'all': |
519 | 537 | logbytes = 0 |
520 | 538 | if sys.argv[1] == 'none': |
521 | 539 | logbytes = -1 |
522 | | |
523 | 540 | |
524 | 541 | if mode.startswith('file'): |
525 | 542 | # file:// |
526 | 543 | logs = mode[5:] |
527 | | |
| 544 | |
528 | 545 | #if mode.lower().startswith('http'): |
529 | 546 | # pass |
530 | 547 | #else if mode.lower().startswith('usb'): |
531 | 548 | # pass |
532 | 549 | #else if mode.lower().startswith('sd'): |
533 | 550 | # pass |
534 | | |
| 551 | |
535 | 552 | logs = lc.write_logs(logs, logbytes) |
536 | 553 | print 'Logs saved in %s' % logs |
537 | | |
| 554 | |
538 | 555 | sent_ok = False |
539 | | if len(sys.argv)>1: |
540 | | mode = sys.argv[len(sys.argv)-1] |
541 | | |
| 556 | if len(sys.argv) > 1: |
| 557 | mode = sys.argv[len(sys.argv) - 1] |
| 558 | |
542 | 559 | if mode.startswith('http'): |
543 | 560 | print "Trying to send the logs using HTTP (web)" |
544 | 561 | if len(mode) == 4: |
… |
… |
Usage: |
546 | 563 | sys.exit(1) |
547 | 564 | else: |
548 | 565 | url = mode |
549 | | |
| 566 | |
550 | 567 | if ls.http_post_logs(url, logs): |
551 | 568 | print "Logs were sent." |
552 | | sent_ok = True |
| 569 | sent_ok = True |
553 | 570 | else: |
554 | 571 | print "FAILED to send logs." |
555 | | |
556 | 572 | |
557 | 573 | if sent_ok: |
558 | 574 | os.remove(logs) |
559 | 575 | print "Logs were sent, tempfile deleted." |
560 | | |
561 | | |