149 QThread.msleep(10) |
148 QThread.msleep(10) |
150 self.__serial.readAll() # read all data and discard it |
149 self.__serial.readAll() # read all data and discard it |
151 self.__serial.write(b"\r\x01") # send CTRL-A to enter raw mode |
150 self.__serial.write(b"\r\x01") # send CTRL-A to enter raw mode |
152 self.__serial.readUntil(rawReplMessage) |
151 self.__serial.readUntil(rawReplMessage) |
153 if self.__serial.hasTimedOut(): |
152 if self.__serial.hasTimedOut(): |
154 return False |
153 # it timed out; try it again and than fail |
155 self.__serial.write(b"\x04") # send CTRL-D to soft reset |
|
156 self.__serial.readUntil(softRebootMessage) |
|
157 if self.__serial.hasTimedOut(): |
|
158 return False |
|
159 |
|
160 # some MicroPython devices seem to need to be convinced in some |
|
161 # special way |
|
162 data = self.__serial.readUntil(rawReplMessage) |
|
163 if not data.endswith(rawReplMessage): |
|
164 self.__serial.write(b"\r\x01") # send CTRL-A again |
154 self.__serial.write(b"\r\x01") # send CTRL-A again |
165 self.__serial.readUntil(rawReplMessage) |
155 self.__serial.readUntil(rawReplMessage) |
166 if self.__serial.hasTimedOut(): |
156 if self.__serial.hasTimedOut(): |
167 return False |
157 return False |
|
158 |
168 QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents) |
159 QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents) |
169 self.__serial.readAll() # read all data and discard it |
160 self.__serial.readAll() # read all data and discard it |
170 return True |
161 return True |
171 |
162 |
172 def __rawOff(self): |
163 def __rawOff(self): |
197 return b"", b"Device not connected or not switched on." |
188 return b"", b"Device not connected or not switched on." |
198 |
189 |
199 result = bytearray() |
190 result = bytearray() |
200 err = b"" |
191 err = b"" |
201 |
192 |
|
193 # switch on raw mode |
202 self.__blockReadyRead = True |
194 self.__blockReadyRead = True |
203 ok = self.__rawOn() |
195 ok = self.__rawOn() |
204 if not ok: |
196 if not ok: |
205 self.__blockReadyRead = False |
197 self.__blockReadyRead = False |
206 return ( |
198 return ( |
207 b"", |
199 b"", |
208 b"Could not switch to raw mode. Is the device switched on?" |
200 b"Could not switch to raw mode. Is the device switched on?" |
209 ) |
201 ) |
210 |
202 |
|
203 # send commands |
211 QThread.msleep(10) |
204 QThread.msleep(10) |
212 for command in commands: |
205 for command in commands: |
213 if command: |
206 if command: |
214 commandBytes = command.encode("utf-8") |
207 commandBytes = command.encode("utf-8") |
215 self.__serial.write(commandBytes + b"\x04") |
208 self.__serial.write(commandBytes + b"\x04") |
|
209 QCoreApplication.processEvents( |
|
210 QEventLoop.ExcludeUserInputEvents) |
|
211 ok = self.__serial.readUntil(b"OK") |
|
212 if ok != b"OK": |
|
213 return ( |
|
214 b"", |
|
215 "Expected 'OK', got '{0}', followed by '{1}'".format( |
|
216 ok, self.__serial.readAll()).encode("utf-8") |
|
217 ) |
|
218 |
216 # read until prompt |
219 # read until prompt |
217 response = self.__serial.readUntil(b"\x04>") |
220 response = self.__serial.readUntil(b"\x04>") |
218 if self.__serial.hasTimedOut(): |
221 if self.__serial.hasTimedOut(): |
219 self.__blockReadyRead = False |
222 self.__blockReadyRead = False |
220 return b"", b"Timeout while processing commands." |
223 return b"", b"Timeout while processing commands." |
221 if b"\x04" in response[2:-2]: |
224 if b"\x04" in response[:-2]: |
222 # split stdout, stderr |
225 # split stdout, stderr |
223 out, err = response[2:-2].split(b"\x04") |
226 out, err = response[:-2].split(b"\x04") |
224 result += out |
227 result += out |
225 else: |
228 else: |
226 err = b"invalid response received: " + response |
229 err = b"invalid response received: " + response |
227 if err: |
230 if err: |
228 self.__blockReadyRead = False |
231 self.__blockReadyRead = False |
229 return b"", err |
232 return b"", err |
|
233 |
|
234 # switch off raw mode |
230 QThread.msleep(10) |
235 QThread.msleep(10) |
231 self.__rawOff() |
236 self.__rawOff() |
232 self.__blockReadyRead = False |
237 self.__blockReadyRead = False |
233 |
238 |
234 return bytes(result), err |
239 return bytes(result), err |
282 @return tuple containg the directory listing |
287 @return tuple containg the directory listing |
283 @rtype tuple of str |
288 @rtype tuple of str |
284 @exception IOError raised to indicate an issue with the device |
289 @exception IOError raised to indicate an issue with the device |
285 """ |
290 """ |
286 commands = [ |
291 commands = [ |
287 "import os", |
292 "import os as __os_", |
288 "print(os.listdir('{0}'))".format(dirname), |
293 "print(__os_.listdir('{0}'))".format(dirname), |
|
294 "del __os_", |
289 ] |
295 ] |
290 out, err = self.execute(commands) |
296 out, err = self.execute(commands) |
291 if err: |
297 if err: |
292 raise IOError(self.__shortError(err)) |
298 raise IOError(self.__shortError(err)) |
293 return ast.literal_eval(out.decode("utf-8")) |
299 return ast.literal_eval(out.decode("utf-8")) |
307 directory doesn't exist. |
313 directory doesn't exist. |
308 @rtype tuple of (str, tuple) |
314 @rtype tuple of (str, tuple) |
309 @exception IOError raised to indicate an issue with the device |
315 @exception IOError raised to indicate an issue with the device |
310 """ |
316 """ |
311 commands = [ |
317 commands = [ |
312 "import os", |
318 "import os as __os_", |
|
319 "\n".join([ |
|
320 "def is_visible(filename):", |
|
321 " return (not filename.startswith('.') and" |
|
322 " not filename.endswith('~'))", |
|
323 ]), |
313 "\n".join([ |
324 "\n".join([ |
314 "def stat(filename):", |
325 "def stat(filename):", |
315 " try:", |
326 " try:", |
316 " rstat = os.lstat(filename)", |
327 " rstat = __os_.lstat(filename)", |
317 " except:", |
328 " except:", |
318 " rstat = os.stat(filename)", |
329 " rstat = __os_.stat(filename)", |
319 " return tuple(rstat)", |
330 " return tuple(rstat)", |
320 ]), |
331 ]), |
321 "\n".join([ |
332 "\n".join([ |
322 "def listdir_stat(dirname):", |
333 "def listdir_stat(dirname):", |
323 " try:", |
334 " try:", |
324 " files = os.listdir(dirname)", |
335 " files = __os_.listdir(dirname)", |
325 " except OSError:", |
336 " except OSError:", |
326 " return None", |
337 " return None", |
327 " if dirname in ('', '/'):", |
338 " if dirname in ('', '/'):", |
328 " return list((f, stat(f)) for f in files)", |
339 " return list((f, stat(f)) for f in files if" |
329 " return list((f, stat(dirname + '/' + f)) for f in files)", |
340 " is_visible(f))", |
|
341 " return list((f, stat(dirname + '/' + f)) for f in files" |
|
342 " if is_visible(f))", |
330 ]), |
343 ]), |
331 "print(listdir_stat('{0}'))".format(dirname), |
344 "print(listdir_stat('{0}'))".format(dirname), |
|
345 "del __os_, stat, listdir_stat", |
332 ] |
346 ] |
333 out, err = self.execute(commands) |
347 out, err = self.execute(commands) |
334 if err: |
348 if err: |
335 raise IOError(self.__shortError(err)) |
349 raise IOError(self.__shortError(err)) |
336 fileslist = ast.literal_eval(out.decode("utf-8")) |
350 fileslist = ast.literal_eval(out.decode("utf-8")) |
367 @return current directory |
382 @return current directory |
368 @rtype str |
383 @rtype str |
369 @exception IOError raised to indicate an issue with the device |
384 @exception IOError raised to indicate an issue with the device |
370 """ |
385 """ |
371 commands = [ |
386 commands = [ |
372 "import os", |
387 "import os as __os_", |
373 "print(os.getcwd())", |
388 "print(__os_.getcwd())", |
|
389 "del __os_", |
374 ] |
390 ] |
375 out, err = self.execute(commands) |
391 out, err = self.execute(commands) |
376 if err: |
392 if err: |
377 raise IOError(self.__shortError(err)) |
393 raise IOError(self.__shortError(err)) |
378 return out.decode("utf-8").strip() |
394 return out.decode("utf-8").strip() |
379 |
395 |
|
396 # TODO: test this |
380 def rm(self, filename): |
397 def rm(self, filename): |
381 """ |
398 """ |
382 Public method to remove a file from the connected device. |
399 Public method to remove a file from the connected device. |
383 |
400 |
384 @param filename name of the file to be removed |
401 @param filename name of the file to be removed |
386 @exception IOError raised to indicate an issue with the device |
403 @exception IOError raised to indicate an issue with the device |
387 """ |
404 """ |
388 assert filename |
405 assert filename |
389 |
406 |
390 commands = [ |
407 commands = [ |
391 "import os", |
408 "import os as __os_", |
392 "os.remove('{0}')".format(filename), |
409 "__os_.remove('{0}')".format(filename), |
393 ] |
410 "del __os_", |
394 out, err = self.execute(commands) |
411 ] |
395 if err: |
412 out, err = self.execute(commands) |
396 raise IOError(self.__shortError(err)) |
413 if err: |
397 |
414 raise IOError(self.__shortError(err)) |
|
415 |
|
416 # TODO: test this |
398 def rmrf(self, name, recursive=False, force=False): |
417 def rmrf(self, name, recursive=False, force=False): |
399 """ |
418 """ |
400 Public method to remove a file or directory recursively. |
419 Public method to remove a file or directory recursively. |
401 |
420 |
402 @param name of the file or directory to remove |
421 @param name of the file or directory to remove |
410 @exception IOError raised to indicate an issue with the device |
429 @exception IOError raised to indicate an issue with the device |
411 """ |
430 """ |
412 assert name |
431 assert name |
413 |
432 |
414 commands = [ |
433 commands = [ |
415 "import os", |
434 "import os as __os_", |
416 "\n".join([ |
435 "\n".join([ |
417 "def remove_file(name, recursive=False, force=False):", |
436 "def remove_file(name, recursive=False, force=False):", |
418 " try:", |
437 " try:", |
419 " mode = os.stat(name)[0]", |
438 " mode = __os_.stat(name)[0]", |
420 " if mode & 0x4000 != 0:", |
439 " if mode & 0x4000 != 0:", |
421 " if recursive:", |
440 " if recursive:", |
422 " for file in os.listdir(name):", |
441 " for file in __os_.listdir(name):", |
423 " success = remove_file(name + '/' + file," |
442 " success = remove_file(name + '/' + file," |
424 " recursive, force)", |
443 " recursive, force)", |
425 " if not success and not force:", |
444 " if not success and not force:", |
426 " return False", |
445 " return False", |
427 " os.rmdir(name)", |
446 " __os_.rmdir(name)", |
428 " else:", |
447 " else:", |
429 " if not force:", |
448 " if not force:", |
430 " return False", |
449 " return False", |
431 " else:", |
450 " else:", |
432 " os.remove(name)", |
451 " __os_.remove(name)", |
433 " except:", |
452 " except:", |
434 " if not force:", |
453 " if not force:", |
435 " return False", |
454 " return False", |
436 " return True", |
455 " return True", |
437 ]), |
456 ]), |
438 "print(remove_file('{0}', {1}, {2}))".format(name, recursive, |
457 "print(remove_file('{0}', {1}, {2}))".format(name, recursive, |
439 force), |
458 force), |
|
459 "del __os_, remove_file", |
440 ] |
460 ] |
441 out, err = self.execute(commands) |
461 out, err = self.execute(commands) |
442 if err: |
462 if err: |
443 raise IOError(self.__shortError(err)) |
463 raise IOError(self.__shortError(err)) |
444 return ast.literal_eval(out.decode("utf-8")) |
464 return ast.literal_eval(out.decode("utf-8")) |
445 |
465 |
|
466 # TODO: test this |
446 def mkdir(self, dirname): |
467 def mkdir(self, dirname): |
447 """ |
468 """ |
448 Public method to create a new directory. |
469 Public method to create a new directory. |
449 |
470 |
450 @param dirname name of the directory to create |
471 @param dirname name of the directory to create |
452 @exception IOError raised to indicate an issue with the device |
473 @exception IOError raised to indicate an issue with the device |
453 """ |
474 """ |
454 assert dirname |
475 assert dirname |
455 |
476 |
456 commands = [ |
477 commands = [ |
457 "import os", |
478 "import os as __os_", |
458 "os.mkdir('{0}')".format(dirname), |
479 "__os_.mkdir('{0}')".format(dirname), |
459 ] |
480 "del __os_", |
460 out, err = self.execute(commands) |
481 ] |
461 if err: |
482 out, err = self.execute(commands) |
462 raise IOError(self.__shortError(err)) |
483 if err: |
463 |
484 raise IOError(self.__shortError(err)) |
|
485 |
|
486 # TODO: test this |
464 def rmdir(self, dirname): |
487 def rmdir(self, dirname): |
465 """ |
488 """ |
466 Public method to remove a directory. |
489 Public method to remove a directory. |
467 |
490 |
468 @param dirname name of the directory to be removed |
491 @param dirname name of the directory to be removed |
470 @exception IOError raised to indicate an issue with the device |
493 @exception IOError raised to indicate an issue with the device |
471 """ |
494 """ |
472 assert dirname |
495 assert dirname |
473 |
496 |
474 commands = [ |
497 commands = [ |
475 "import os", |
498 "import os as __os_", |
476 "os.rmdir('{0}')".format(dirname), |
499 "__os_.rmdir('{0}')".format(dirname), |
477 ] |
500 "del __os_", |
478 out, err = self.execute(commands) |
501 ] |
479 if err: |
502 out, err = self.execute(commands) |
480 raise IOError(self.__shortError(err)) |
503 if err: |
481 |
504 raise IOError(self.__shortError(err)) |
|
505 |
|
506 # TODO: test this |
482 def put(self, hostFileName, deviceFileName=None): |
507 def put(self, hostFileName, deviceFileName=None): |
483 """ |
508 """ |
484 Public method to copy a local file to the connected device. |
509 Public method to copy a local file to the connected device. |
485 |
510 |
486 @param hostFileName name of the file to be copied |
511 @param hostFileName name of the file to be copied |
509 ] |
534 ] |
510 while content: |
535 while content: |
511 chunk = content[:64] |
536 chunk = content[:64] |
512 commands.append("f(" + repr(chunk) + ")") |
537 commands.append("f(" + repr(chunk) + ")") |
513 content = content[64:] |
538 content = content[64:] |
514 commands.append("fd.close()") |
539 commands.extend([ |
|
540 "fd.close()", |
|
541 "del f, fd", |
|
542 ]) |
515 |
543 |
516 out, err = self.execute(commands) |
544 out, err = self.execute(commands) |
517 if err: |
545 if err: |
518 raise IOError(self.__shortError(err)) |
546 raise IOError(self.__shortError(err)) |
519 return True |
547 return True |
520 |
548 |
|
549 # TODO: test this |
521 def get(self, deviceFileName, hostFileName=None): |
550 def get(self, deviceFileName, hostFileName=None): |
522 """ |
551 """ |
523 Public method to copy a file from the connected device. |
552 Public method to copy a file from the connected device. |
524 |
553 |
525 @param deviceFileName name of the file to copy |
554 @param deviceFileName name of the file to copy |
533 if not hostFileName: |
562 if not hostFileName: |
534 hostFileName = deviceFileName |
563 hostFileName = deviceFileName |
535 |
564 |
536 commands = [ |
565 commands = [ |
537 "\n".join([ |
566 "\n".join([ |
538 "try:", |
567 "def send_data():", |
539 " from microbit import uart as u", |
|
540 "except ImportError:", |
|
541 " try:", |
568 " try:", |
542 " from machine import UART", |
569 " from microbit import uart as u", |
543 " u = UART(0, {0})".format(115200), |
570 " except ImportError:", |
544 " except Exception:", |
|
545 " try:", |
571 " try:", |
546 " from sys import stdout as u", |
572 " from machine import UART", |
|
573 " u = UART(0, {0})".format(115200), |
547 " except Exception:", |
574 " except Exception:", |
548 " raise Exception('Could not find UART module in" |
575 " try:", |
549 " device.')", |
576 " from sys import stdout as u", |
550 ]), |
577 " except Exception:", |
551 "f = open('{0}', 'rb')".format(deviceFileName), |
578 " raise Exception('Could not find UART module" |
552 "r = f.read", |
579 " in device.')", |
553 "result = True", |
580 " f = open('{0}', 'rb')".format(deviceFileName), |
554 "\n".join([ |
581 " r = f.read", |
555 "while result:", |
582 " result = True", |
556 " result = r(32)", |
583 " while result:", |
557 " if result:", |
584 " result = r(32)", |
558 " u.write(result)", |
585 " if result:", |
559 ]), |
586 " u.write(result)", |
560 "f.close()", |
587 " f.close()", |
|
588 ]), |
|
589 "send_data()", |
561 ] |
590 ] |
562 out, err = self.execute(commands) |
591 out, err = self.execute(commands) |
563 if err: |
592 if err: |
564 raise IOError(self.__shortError(err)) |
593 raise IOError(self.__shortError(err)) |
565 |
594 |
580 size, the used size and the free size |
609 size, the used size and the free size |
581 @rtype tuple of tuples of (str, int, int, int) |
610 @rtype tuple of tuples of (str, int, int, int) |
582 @exception IOError raised to indicate an issue with the device |
611 @exception IOError raised to indicate an issue with the device |
583 """ |
612 """ |
584 commands = [ |
613 commands = [ |
585 "import os", |
614 "import os as __os_", |
586 "\n".join([ |
615 "\n".join([ |
587 "def fsinfo():", |
616 "def fsinfo():", |
588 " infolist = []", |
617 " infolist = []", |
589 " fsnames = os.listdir('/')", |
618 " info = __os_.statvfs('/')", |
590 " for fs in fsnames:", |
619 " if info[0] == 0:", |
591 " fs = '/' + fs", |
620 # assume it is just mount points |
592 " infolist.append((fs, os.statvfs(fs)))", |
621 " fsnames = __os_.listdir('/')", |
|
622 " for fs in fsnames:", |
|
623 " fs = '/' + fs", |
|
624 " infolist.append((fs, __os_.statvfs(fs)))", |
|
625 " else:", |
|
626 " infolist.append(('/', info))", |
593 " return infolist", |
627 " return infolist", |
594 ]), |
628 ]), |
595 "print(fsinfo())", |
629 "print(fsinfo())", |
|
630 "del __os_, fsinfo", |
596 ] |
631 ] |
597 out, err = self.execute(commands) |
632 out, err = self.execute(commands) |
598 if err: |
633 if err: |
599 raise IOError(self.__shortError(err)) |
634 raise IOError(self.__shortError(err)) |
600 infolist = ast.literal_eval(out.decode("utf-8")) |
635 infolist = ast.literal_eval(out.decode("utf-8")) |
648 @return dictionary containing the implementation information |
684 @return dictionary containing the implementation information |
649 @rtype dict |
685 @rtype dict |
650 @exception IOError raised to indicate an issue with the device |
686 @exception IOError raised to indicate an issue with the device |
651 """ |
687 """ |
652 commands = [ |
688 commands = [ |
653 "import sys", |
689 "import sys as __sys_", |
654 "res = {}", # __IGNORE_WARNING_M613__ |
690 "res = {}", # __IGNORE_WARNING_M613__ |
655 "\n".join([ |
691 "\n".join([ |
656 "try:", |
692 "try:", |
657 " res['name'] = sys.implementation.name", |
693 " res['name'] = __sys_.implementation.name", |
658 "except AttributeError:", |
694 "except AttributeError:", |
659 " res['name'] = 'unknown'", |
695 " res['name'] = 'unknown'", |
660 ]), |
696 ]), |
661 "\n".join([ |
697 "\n".join([ |
662 "try:", |
698 "try:", |
663 " res['version'] = '.'.join((str(i) for i in" |
699 " res['version'] = '.'.join((str(i) for i in" |
664 " sys.implementation.version))", |
700 " __sys_.implementation.version))", |
665 "except AttributeError:", |
701 "except AttributeError:", |
666 " res['version'] = 'unknown'", |
702 " res['version'] = 'unknown'", |
667 ]), |
703 ]), |
668 "print(res)", |
704 "print(res)", |
|
705 "del res, __sys_", |
669 ] |
706 ] |
670 out, err = self.execute(commands) |
707 out, err = self.execute(commands) |
671 if err: |
708 if err: |
672 raise IOError(self.__shortError(err)) |
709 raise IOError(self.__shortError(err)) |
673 return ast.literal_eval(out.decode("utf-8")) |
710 return ast.literal_eval(out.decode("utf-8")) |
683 commands = [ |
720 commands = [ |
684 "\n".join([ |
721 "\n".join([ |
685 "def set_time(rtc_time):", |
722 "def set_time(rtc_time):", |
686 " rtc = None", |
723 " rtc = None", |
687 " try:", # Pyboard (it doesn't have machine.RTC()) |
724 " try:", # Pyboard (it doesn't have machine.RTC()) |
688 " import pyb", |
725 " import pyb as __pyb_", |
689 " rtc = pyb.RTC()", |
726 " rtc = __pyb_.RTC()", |
690 " clock_time = rtc_time[:6] + (rtc_time[6] + 1, 0)", |
727 " clock_time = rtc_time[:6] + (rtc_time[6] + 1, 0)", |
691 " rtc.datetime(clock_time)", |
728 " rtc.datetime(clock_time)", |
692 " except:", |
729 " del __pyb_", |
|
730 " except Exception:", |
693 " try:", |
731 " try:", |
694 " import machine", |
732 " import machine as __machine_", |
695 " rtc = machine.RTC()", |
733 " rtc = __machine_.RTC()", |
696 " try:", # ESP8266 may use rtc.datetime() |
734 " try:", # ESP8266 may use rtc.datetime() |
697 " clock_time = rtc_time[:6] +" |
735 " clock_time = rtc_time[:6] +" |
698 " (rtc_time[6] + 1, 0)", |
736 " (rtc_time[6] + 1, 0)", |
699 " rtc.datetime(clock_time)", |
737 " rtc.datetime(clock_time)", |
700 " except:", # ESP32 uses rtc.init() |
738 " except Exception:", # ESP32 uses rtc.init() |
701 " rtc.init(rtc_time[:6])", |
739 " rtc.init(rtc_time[:6])", |
|
740 " del __machine_", |
702 " except:", |
741 " except:", |
703 " try:", |
742 " try:", |
704 " import rtc, time", |
743 " import rtc as __rtc_", |
705 " clock=rtc.RTC()", |
744 " import time as __time_", |
706 " clock.datetime = time.struct_time(rtc_time +" |
745 " clock=__rtc_.RTC()", |
707 " (-1, -1))", |
746 " clock.datetime = __time_.struct_time(" |
|
747 "rtc_time + (-1, -1))", |
|
748 " del __rtc_, __time_", |
708 " except:", |
749 " except:", |
709 " pass", |
750 " pass", |
710 ]), |
751 ]), |
711 "set_time({0})".format((now.tm_year, now.tm_mon, now.tm_mday, |
752 "set_time({0})".format((now.tm_year, now.tm_mon, now.tm_mday, |
712 now.tm_hour, now.tm_min, now.tm_sec, |
753 now.tm_hour, now.tm_min, now.tm_sec, |
713 now.tm_wday)) |
754 now.tm_wday)), |
|
755 "del set_time", |
714 ] |
756 ] |
715 out, err = self.execute(commands) |
757 out, err = self.execute(commands) |
716 if err: |
758 if err: |
717 raise IOError(self.__shortError(err)) |
759 raise IOError(self.__shortError(err)) |
718 |
760 |
723 @return time of the device |
765 @return time of the device |
724 @rtype str |
766 @rtype str |
725 @exception IOError raised to indicate an issue with the device |
767 @exception IOError raised to indicate an issue with the device |
726 """ |
768 """ |
727 commands = [ |
769 commands = [ |
728 "import time", |
770 "import time as __time_", |
729 "\n".join([ |
771 "\n".join([ |
730 "try:", |
772 "try:", |
731 " print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()" |
773 " print(__time_.strftime('%Y-%m-%d %H:%M:%S'," |
732 "))", |
774 " __time_.localtime()))", |
733 # __IGNORE_WARNING_M601__ |
775 # __IGNORE_WARNING_M601__ |
734 "except AttributeError:", |
776 "except AttributeError:", |
735 " tm = time.localtime()", |
777 " tm = __time_.localtime()", |
736 " print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'" |
778 " print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'" |
737 ".format(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour," |
779 ".format(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour," |
738 " tm.tm_min, tm.tm_sec))", |
780 " tm.tm_min, tm.tm_sec))", |
739 ]), |
781 " del tm", |
|
782 ]), |
|
783 "del __time_" |
740 ] |
784 ] |
741 out, err = self.execute(commands) |
785 out, err = self.execute(commands) |
742 if err: |
786 if err: |
743 raise IOError(self.__shortError(err)) |
787 raise IOError(self.__shortError(err)) |
744 return out.decode("utf-8").strip() |
788 return out.decode("utf-8").strip() |