diff --git a/test/minimail.py b/test/minimail.py index c60115f..6e57279 100644 --- a/test/minimail.py +++ b/test/minimail.py @@ -77,7 +77,7 @@ def recv_all(inbox, marker): r = [] while not r: - for p in inbox.glob("*.eml"): + for p in reversed([ path for path in inbox.glob("*.eml") ]): if newer(p, inbox / marker): with Lock(inbox): with open(p, "rb") as f: diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 103e903..f733d37 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -24,6 +24,7 @@ import minimail inbox = pathlib.Path("..") / "TestInbox" +device = "" def messageToSend(msg): @@ -37,11 +38,13 @@ def messageToSend(msg): class UserInterface(pEp.UserInterface): def notifyHandshake(self, me, partner, signal): - print("signal " + str(signal) + " for identities " + str(me) + " " + - str(partner)) + print("on " + device + " signal " + str(signal) + " for identities " + str(me.fpr) + " " + + str(partner.fpr)) def run(name): + global device + device = name me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman") pEp.myself(me) pEp.messageToSend = messageToSend diff --git a/test/sync_test.py b/test/sync_test.py index 607878f..84b6eb0 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -15,6 +15,7 @@ $ python3 sync_test.py import os +import shutil import pathlib @@ -73,8 +74,17 @@ if __name__ == "__main__": optParser.description = __doc__ optParser.add_option("-c", "--clean", action="store_true", dest="clean", help="remove all generated files") + optParser.add_option("-b", "--backup", action="store_true", dest="backup", + help="make a backup of all generated files (old backup will be overwritten)") + optParser.add_option("-r", "--restore", action="store_true", dest="restore", + help="restore generated files from backup") + optParser.add_option("-C", "--clean-all", action="store_true", dest="cleanall", + help="remove all generated files including backup files") options, args = optParser.parse_args() + if options.cleanall: + options.clean = True + if options.clean: from minimail import unlock @@ -83,6 +93,36 @@ if __name__ == "__main__": rmrf("Phone") rmrf("Laptop") + if options.cleanall: + rmrf("Backup") + + elif options.backup: + from minimail import unlock + + rmrf("Backup") + unlock(pathlib.Path("TestInbox")) + + try: + os.mkdir("Backup") + except FileExistsError: + pass + + shutil.copytree("Phone", "Backup/Phone", symlinks=True, copy_function=shutil.copy2) + shutil.copytree("Laptop", "Backup/Laptop", symlinks=True, copy_function=shutil.copy2) + shutil.copytree("TestInbox", "Backup/TestInbox", symlinks=True, copy_function=shutil.copy2) + + elif options.restore: + from minimail import unlock + + rmrf("TestInbox") + unlock(pathlib.Path("TestInbox")) + rmrf("Phone") + rmrf("Laptop") + + shutil.copytree("Backup/Phone", "Phone", symlinks=True, copy_function=shutil.copy2) + shutil.copytree("Backup/Laptop", "Laptop", symlinks=True, copy_function=shutil.copy2) + shutil.copytree("Backup/TestInbox", "TestInbox", symlinks=True, copy_function=shutil.copy2) + else: from multiprocessing import Process