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