| 536 | |
| 537 | # ------------------------[ edit <file> ]----------------------------- |
| 538 | def do_edit(self, arg): |
| 539 | # get name of temporary file |
| 540 | t = tempfile.NamedTemporaryFile(delete=False) |
| 541 | lpath = t.name |
| 542 | t.close |
| 543 | # download to temporary file |
| 544 | self.do_get(arg, lpath) |
| 545 | # get md5sum for original file |
| 546 | chksum1 = hashlib.md5(open(lpath, "rb").read()).hexdigest() |
| 547 | try: |
| 548 | subprocess.call([self.editor, lpath]) |
| 549 | # get md5sum for edited file |
| 550 | chksum2 = hashlib.md5(open(lpath, "rb").read()).hexdigest() |
| 551 | # upload file, if changed |
| 552 | if chksum1 == chksum2: |
| 553 | print("File not changed.") |
| 554 | else: |
| 555 | self.do_put(lpath, arg) |
| 556 | except Exception as e: |
| 557 | output().errmsg("Cannot edit file - Set self.editor", e) |
| 558 | # delete temporary file |
| 559 | os.remove(lpath) |
| 560 | |
| 561 | # define alias but do not show alias in help |
| 562 | do_vim = do_edit |