#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et from __future__ import print_function import sys, os sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules') import ftptree from common import checkdir import ftpio from config import archived_trees, logs_list if len(sys.argv) < 4: print("ERR: not enough parameters given") print("test-move.py src-tree dst-tree package [package2 package3 ...]") sys.exit(1) checkdir(sys.argv[1]) checkdir(sys.argv[2]) if sys.argv[2] in archived_trees: archivetreename = "archive" checkdir(archivetreename) else: archivetreename = None ftpio.connect('test-move') if not ftpio.lock(sys.argv[1], True): print("ERR: %s tree already locked" % sys.argv[1]) sys.exit(1) if not ftpio.lock(sys.argv[2], True): ftpio.unlock(sys.argv[1]) print("ERR: %s tree already locked" % sys.argv[2]) sys.exit(1) if archivetreename != None and archivetreename != sys.argv[1] and not ftpio.lock(archivetreename, True): ftpio.unlock(sys.argv[2]) ftpio.unlock(sys.argv[1]) print("ERR: %s tree already locked" % archivetreename) sys.exit(1) try: srctree = ftptree.FtpTree(sys.argv[1], loadall = True) dsttree = ftptree.FtpTree(sys.argv[2]) if archivetreename != None: archivetree = ftptree.FtpTree(archivetreename) else: archivetree = None pkgs = list(set(sys.argv[3:])) srctree.mark4moving(pkgs) except ftptree.SomeError: # In case of problems we need to unlock the trees before exiting ftpio.unlock(sys.argv[1]) ftpio.unlock(sys.argv[2]) if archivetreename != None: ftpio.unlock(archivetreename) sys.exit(1) # We don't 'try' as in move.py cause this function doesn't force exit srctree.testmove(dsttree, archivetree = archivetree) ftpio.unlock(sys.argv[1]) ftpio.unlock(sys.argv[2]) if archivetreename != None and archivetreename != sys.argv[1]: ftpio.unlock(archivetreename)