From: Mariusz Mazur Date: Thu, 20 Jan 2005 17:20:25 +0000 (+0000) Subject: - all scripts use ftpiod for locking and logging X-Git-Url: http://git.pld-linux.org/?a=commitdiff_plain;h=0a108b7f519e658426cee3888811f5792909c533;p=projects%2Fpld-ftp-admin.git - all scripts use ftpiod for locking and logging Changed files: bin/pfa-from-incoming -> 1.6 bin/pfa-mvpkg -> 1.7 bin/pfa-rmpkg -> 1.4 bin/pfa-testmvpkg -> 1.2 modules/ftptree.py -> 1.11 --- diff --git a/bin/pfa-from-incoming b/bin/pfa-from-incoming index 4fe4d18..c59cb3c 100644 --- a/bin/pfa-from-incoming +++ b/bin/pfa-from-incoming @@ -8,23 +8,12 @@ import config from common import noarchcachedir, tmpdir, fileexists from baseftptree import BaseFtpTree, BasePkg cval=config.value +import ftpio -lockfile=os.environ['HOME']+'/pld-ftp-admin/var/lock-'+cval['default_to'] - -def lock(): - if not fileexists(lockfile): - open(lockfile, 'w').close() - return True - else: - return False - -def unlock(): - rm(lockfile) - -def log(msg): - f=open(os.environ['HOME']+'/pld-ftp-admin/var/log', 'a') - f.write(msg+'\n') - f.close() +try: + ftpio.connect('from-incoming') +except: + sys.exit(0) def rm(file): os.remove(file) @@ -53,8 +42,7 @@ def getcontent(file): ftptree=BaseFtpTree(cval['default_to']) -if not lock(): - log('Tree '+cval['default_to']+' locked') +if not ftpio.lock(cval['default_to']): sys.exit(0) for uploadinfo in findfiles(incoming_dir+'SRPMS'): @@ -66,7 +54,7 @@ for uploadinfo in findfiles(incoming_dir+'SRPMS'): srpm=pkg.files['SRPMS'][0] if ftptree.has_key(`pkg`): - log("%s already present in %s; removing newer files" % + ftpio.log("%s already present in %s; removing newer files" % (srpm, ftptree)) rm(incoming_dir+'SRPMS/'+srpm) f=open(default_to+'SRPMS/.metadata/'+srpm+'.info', 'a') @@ -176,7 +164,7 @@ for arch in ftp_archs: dstpkg=BasePkg(`srcpkg`, ftptree) if dstpkg.files.has_key(arch): - log("files from %s for arch %s already present in %s; removing newer files" % (`srcpkg`, arch, ftptree)) + ftpio.log("files from %s for arch %s already present in %s; removing newer files" % (`srcpkg`, arch, ftptree)) for rpm in srcpkg.files['ARCH']: rm(incoming_dir+arch+'/'+rpm) rm(incoming_dir+arch+'/'+uploadinfo) @@ -193,5 +181,5 @@ for arch in ftp_archs: rm(incoming_dir+arch+'/'+uploadinfo) -unlock() +ftpio.unlock(cval['default_to']) diff --git a/bin/pfa-mvpkg b/bin/pfa-mvpkg index 8c17ac3..be72351 100644 --- a/bin/pfa-mvpkg +++ b/bin/pfa-mvpkg @@ -14,9 +14,29 @@ if len(sys.argv) < 3: checkdir(sys.argv[1]) checkdir(sys.argv[2]) -srctree=FtpTree(sys.argv[1], loadall=True) -dsttree=FtpTree(sys.argv[2]) -srctree.mark4moving(sys.argv[3:]) +ftpio.connect('move') -srctree.movepkgs(dsttree) +if not ftpio.lock(sys.argv[1], True): + print "%s tree already locked" %s sys.argv[1] + sys.exit(1) + +if not ftpio.lock(sys.argv[2], True): + ftpio.unlock(sys.argv[1]) + print "%s tree already locked" %s sys.argv[2] + sys.exit(1) + +try: + srctree=FtpTree(sys.argv[1], loadall=True) + dsttree=FtpTree(sys.argv[2]) + srctree.mark4moving(sys.argv[3:]) + + srctree.movepkgs(dsttree) +except ftptree.SomeError: + # In case of problems we need to unlock the tree before exiting + ftpio.unlock(sys.argv[1]) + ftpio.unlock(sys.argv[2]) + sys.exit(1) + +ftpio.unlock(sys.argv[1]) +ftpio.unlock(sys.argv[2]) diff --git a/bin/pfa-rmpkg b/bin/pfa-rmpkg index faa4f3b..bfcec7a 100755 --- a/bin/pfa-rmpkg +++ b/bin/pfa-rmpkg @@ -5,6 +5,7 @@ import sys, os sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') from ftptree import FtpTree from common import checkdir +import ftpio if len(sys.argv) < 3: print "Not enough parameters given" @@ -13,8 +14,20 @@ if len(sys.argv) < 3: checkdir(sys.argv[1]) -tree=FtpTree(sys.argv[1]) +ftpio.connect('remove') -tree.mark4removal(sys.argv[2:]) -tree.removepkgs() +if not ftpio.lock(sys.argv[1], True): + print "%s tree already locked" % sys.argv[1] + sys.exit(1) + +try: + tree=FtpTree(sys.argv[1]) + tree.mark4removal(sys.argv[2:]) + tree.removepkgs() +except ftptree.SomeError: + # In case of problems we need to unlock the tree before exiting + ftpio.unlock(sys.argv[1]) + sys.exit(1) + +ftpio.unlock(sys.argv[1]) diff --git a/bin/pfa-testmvpkg b/bin/pfa-testmvpkg index 3c0f123..2c1a6cd 100755 --- a/bin/pfa-testmvpkg +++ b/bin/pfa-testmvpkg @@ -5,6 +5,7 @@ import sys, os sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') from ftptree import FtpTree from common import checkdir +import ftpio if len(sys.argv) < 3: print "Not enough parameters given" @@ -14,9 +15,24 @@ if len(sys.argv) < 3: checkdir(sys.argv[1]) checkdir(sys.argv[2]) +ftpio.connect('test-move') + +if not ftpio.lock(sys.argv[1], True): + print "%s tree already locked" %s sys.argv[1] + sys.exit(1) + +if not ftpio.lock(sys.argv[2], True): + ftpio.unlock(sys.argv[1]) + print "%s tree already locked" %s sys.argv[2] + sys.exit(1) + +# We don't 'try' as in move.py cause these functions don't force exit srctree=FtpTree(sys.argv[1], loadall=True) dsttree=FtpTree(sys.argv[2]) srctree.mark4moving(sys.argv[3:]) srctree.testmove(dsttree) +ftpio.unlock(sys.argv[1]) +ftpio.unlock(sys.argv[2]) + diff --git a/modules/ftptree.py b/modules/ftptree.py index d453b6e..47a3fa4 100644 --- a/modules/ftptree.py +++ b/modules/ftptree.py @@ -1,14 +1,16 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et -import sys, os, config, string, urllib, re +import os, config, string, urllib, re from common import fileexists, noarchcachedir from baseftptree import BasePkg, BaseFtpTree errnum=0 +SomeError="Oh no" + def bailoutonerror(): if not errnum == 0: print "%d error(s) encountered... aborting" % errnum - sys.exit(1) + raise SomeError def pinfo(msg): print msg