From: Marcin Krol Date: Sun, 3 Apr 2022 12:46:42 +0000 (+0200) Subject: - merged PLD changes X-Git-Url: https://git.tld-linux.org/?a=commitdiff_plain;h=51b9814081f743180ffed6c80fd7945acb554ce2;p=tld-ftp-admin.git - merged PLD changes --- diff --git a/bin/pfa-checksign b/bin/pfa-checksign index 0da6f61..4e22373 100755 --- a/bin/pfa-checksign +++ b/bin/pfa-checksign @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import sys, os import getopt sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules') @@ -14,17 +16,17 @@ from sign import is_signed, signpkgs try: opts, args = getopt.getopt(sys.argv[1:], '') except getopt.GetoptError: - print >>sys.stderr, "ERR: options error" - print >>sys.stderr, "checksign.py tree package1 [package2...]" + print("ERR: options error", file=sys.stderr) + print("checksign.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) if len(args) < 1: - print >>sys.stderr, "ERR: missing tree name" - print >>sys.stderr, "checksign.py tree package1 [package2...]" + print("ERR: missing tree name", file=sys.stderr) + print("checksign.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) if sign_key == None: - print >>sys.stderr, "ERR: sign_key not defined in config" + print("ERR: sign_key not defined in config", file=sys.stderr) sys.exit(1) treename = args[0] @@ -35,7 +37,7 @@ checkdir(treename) ftpio.connect('sign') if not ftpio.lock(treename, True): - print >>sys.stderr, "ERR: %s tree already locked" % treename + print("ERR: %s tree already locked" % treename, file=sys.stderr) sys.exit(1) files = [] @@ -60,7 +62,7 @@ except ftptree.SomeError: ftpio.unlock(treename) -print "Checking signatures of %d packages" % len(tree.loadedpkgs) +print("Checking signatures of %d packages" % len(tree.loadedpkgs)) sign = [] for pkg in tree.marked4moving: unsigned = 0 @@ -69,8 +71,8 @@ for pkg in tree.marked4moving: unsigned += 1 if unsigned != 0: - print '%s: %d files NOT signed' % (pkg.nvr, unsigned) + print('%s: %d files NOT signed' % (pkg.nvr, unsigned)) else: - print '%s signed' % pkg.nvr + print('%s signed' % pkg.nvr) sys.exit(0) diff --git a/bin/pfa-checktree b/bin/pfa-checktree index b2e424a..6133082 100755 --- a/bin/pfa-checktree +++ b/bin/pfa-checktree @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -13,8 +15,8 @@ cval=config.value import curses if len(sys.argv) != 3: - print "ERR: wrong number of arguments" - print "check-tree.py srctree dsttree" + print("ERR: wrong number of arguments") + print("check-tree.py srctree dsttree") sys.exit(1) checkdir(sys.argv[1]) @@ -22,12 +24,12 @@ checkdir(sys.argv[1]) ftpio.connect('check-tree') if not ftpio.lock(sys.argv[1], True): - print "ERR: %s tree already locked" % sys.argv[1] + 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] + print("ERR: %s tree already locked" % sys.argv[2]) sys.exit(1) srctree=ftptree.FtpTree(sys.argv[1], loadall=True) @@ -211,9 +213,9 @@ class Screen: else: self.pkglist.bkgdset(ord(' '), self.COLOR_STANDARD) if i == self.pkglistselected: - self.pkglist.addstr(i, 2, `self.elements[i]`, curses.A_REVERSE) + self.pkglist.addstr(i, 2, repr(self.elements[i]), curses.A_REVERSE) else: - self.pkglist.addstr(i, 2, `self.elements[i]`, curses.A_BOLD) + self.pkglist.addstr(i, 2, repr(self.elements[i]), curses.A_BOLD) self.pkglist.bkgdset(ord(' '), self.COLOR_STANDARD) self.pkglist.noutrefresh(self.pkgliststartpad,0,1,0,self.pad_h,self.scr_w-1) @@ -260,7 +262,7 @@ class Screen: self.pkgliststartpad = 0 def __do_quit(self): - raise DoQuit + raise DoQuit() def __do_mark(self): pkg=self.elements[self.pkglistselected] @@ -289,7 +291,7 @@ class Screen: exec 'self._Screen__do_%s()' % bind[1] else: -# self.elements[0]=`key` +# self.elements[0]=repr(key) for bind in self.globalkeys+self.perwindowkeys[self.window-1]: if bind[0].startswith('KEY_'): if key == getattr(curses, bind[0]): diff --git a/bin/pfa-dump-locks b/bin/pfa-dump-locks index 84b9b95..a4c8253 100755 --- a/bin/pfa-dump-locks +++ b/bin/pfa-dump-locks @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -8,4 +10,4 @@ import ftpio import config ftpio.connect() -print ftpio.locks_dump() +print(ftpio.locks_dump()) diff --git a/bin/pfa-from-incoming b/bin/pfa-from-incoming index 3d7ea08..1ea2d59 100755 --- a/bin/pfa-from-incoming +++ b/bin/pfa-from-incoming @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import sys, os, stat, time, re sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules') from config import incoming_dir, default_to, ftp_archs @@ -11,7 +13,7 @@ from baseftptree import BaseFtpTree, BasePkg from ftptree import FtpTree, Pkg import ftpio -os.umask(022) +os.umask(0o022) def rm(file): os.remove(file) @@ -27,7 +29,7 @@ def is_debuginfo(nvr): if not config.separate_debuginfo: return False pkg = nvr.split('-')[:-2] - return pkg[-1] == 'debuginfo' + return pkg[-1] == 'debuginfo' or pkg[-1] == 'debugsource' def findfiles(dir): def filterinfos(x): @@ -77,8 +79,8 @@ Subject: %s if files_differ: f=open("%s/files.diff" % tmpdir, 'r') sm.write("Difference between %s (currently in %s) and %s FILES\n" % - (pkg.noarch_arch[rpmfile], `ftptree`, arch)), - for line in f.readlines(True)[2:]: + (pkg.noarch_arch[rpmfile], repr(ftptree), arch)), + for line in f.readlines()[2:]: sm.write(line) f.close() @@ -87,15 +89,15 @@ Subject: %s if reqs_differ: f=open("%s/reqs.diff" % tmpdir, 'r') sm.write("Difference between %s (currently in %s) and %s REQS\n" % - (pkg.noarch_arch[rpmfile], `ftptree`, arch)), - for line in f.readlines(True)[2:]: + (pkg.noarch_arch[rpmfile], repr(ftptree), arch)), + for line in f.readlines()[2:]: sm.write(line) f.close() sm.close() def move_noarch(f, arch, rpmfile, dstpkg): - if dstpkg.noarch_arch.has_key(rpmfile): + if rpmfile in dstpkg.noarch_arch: os.system("LC_ALL=C rpm -qlp %s | LC_ALL=C sort > %s/files.new" % (incoming_dir + arch + '/' + rpmfile, tmpdir)) os.system("rpm -qRp %s | LC_ALL=C sort | LC_ALL=C uniq > %s/reqs.new" % @@ -120,7 +122,7 @@ def move_noarch(f, arch, rpmfile, dstpkg): (incoming_dir + arch + '/' + rpmfile, noarchcachedir, rpmfile)) os.system("rpm -qRp %s | LC_ALL=C sort | LC_ALL=C uniq > %s/%s.reqlist" % (incoming_dir + arch + '/' + rpmfile, noarchcachedir, rpmfile)) - if not dstpkg.files.has_key(arch): + if arch not in dstpkg.files: f.write("file:noarch:%s\ninfo:noarch_arch:%s:%s\n" % (rpmfile, rpmfile, arch)) mv(incoming_dir + arch + '/' + rpmfile, default_to + 'noarch/RPMS') @@ -153,7 +155,7 @@ Subject: %s sm.write(msg) sm.write("Difference between %s SRPM (currently in %s) and %s RPM NVR:\n\n" % - (snvr[0], `ftptree`, arch)), + (snvr[0], repr(ftptree), arch)), sm.write("Expected (%s):\nV: %s\nR: %s\n\n" % snvr) sm.write("RPM:\nN: %s\nV: %s\nR: %s\n" % anvr) sm.write('\n') @@ -164,13 +166,13 @@ Subject: %s try: ftpio.connect('from-incoming-pid-%s' % os.getpid()) except: - print "Can't get ftpiod connection" + print("Can't get ftpiod connection") sys.exit(1) ftptree = BaseFtpTree(cval['default_to']) if not ftpio.lock(cval['default_to']): - print "Can't get lock: %s" % cval['default_to'] + print("Can't get lock: %s" % cval['default_to']) sys.exit(1) moved_anything = False @@ -187,11 +189,11 @@ for uploadinfo in findfiles(incoming_dir + 'SRPMS'): ftpio.log("%s file missing; skipping move until next round" % (srpm)) continue - if ftptree.has_key(`pkg`): + if ftptree.has_key(repr(pkg)): ftpio.log("%s already present in %s; removing older files" % (srpm, ftptree)) rm(default_to + 'SRPMS/RPMS/' + srpm) f = open(default_to + 'SRPMS/.metadata/' + srpm+'.info', 'a') - bid = pkg.build.keys()[0] + bid = list(pkg.build.keys())[0] build = pkg.build[bid] f.write("info:build:%s:requester:%s\ninfo:build:%s:requester_email:%s\n" % (bid, build.requester, bid, build.requester_email)) @@ -214,7 +216,7 @@ for arch in ftp_archs: srcpkg = BasePkg(uploadinfo[:-19], content = content) srpm = srcpkg.files['SRPMS'][0] - if not ftptree.has_key(`srcpkg`): + if not ftptree.has_key(repr(srcpkg)): continue # We require the src.rpm to be present renvr = re.compile(r'(.*)-(.*)-(.*)\.[^.]*\.rpm') @@ -226,10 +228,10 @@ for arch in ftp_archs: ftpio.log("%s file missing; skipping move until next round" % (filem)) continue - dstpkg = BasePkg(`srcpkg`, ftptree) + dstpkg = BasePkg(repr(srcpkg), ftptree) - if dstpkg.files.has_key(arch): - ftpio.log("files from %s for arch %s already present in %s; removing older files" % (`srcpkg`, arch, ftptree)) + if arch in dstpkg.files: + ftpio.log("files from %s for arch %s already present in %s; removing older files" % (repr(srcpkg), arch, ftptree)) for rpmfile in dstpkg.files[arch]: if is_debuginfo(rpmfile): dstfile = default_to + arch + '/debuginfo' @@ -237,10 +239,10 @@ for arch in ftp_archs: dstfile = default_to + arch + '/RPMS' try: rm(dstfile + '/' + rpmfile) - except OSError, e: + except OSError as e: l = "Removing %s problem: %s" % (dstfile + '/' + rpmfile, e) ftpio.log(l) - print l + print(l) f = open(default_to + 'SRPMS/.metadata/' + srpm + '.info', 'a') for rpmfile in srcpkg.files['ARCH']: @@ -254,7 +256,7 @@ for arch in ftp_archs: if rpmfile[-11:] == '.noarch.rpm' and config.separate_noarch: move_noarch(f, arch, rpmfile, dstpkg) else: - if not dstpkg.files.has_key(arch): + if arch not in dstpkg.files: f.write("file:%s:%s\n" % (arch, rpmfile)) srcfile = incoming_dir + arch + '/' + rpmfile @@ -265,10 +267,10 @@ for arch in ftp_archs: try: mv(srcfile, dstfile) - except OSError, e: + except OSError as e: l = "Moving %s to %s problem: %s" % (srcfile, dstfile, e) ftpio.log(l) - print l + print(l) f.close() rm(incoming_dir + arch + '/' + uploadinfo) diff --git a/bin/pfa-genindex b/bin/pfa-genindex index a5133c5..01ff1ee 100755 --- a/bin/pfa-genindex +++ b/bin/pfa-genindex @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import getopt import sys, os sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules') @@ -18,8 +20,8 @@ try: ] ) except getopt.GetoptError: - print >>sys.stderr, "ERR: not enough parameters given" - print >>sys.stderr, "gen-indexes.py [--quiet] [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]" + print("ERR: not enough parameters given", file=sys.stderr) + print("gen-indexes.py [--quiet] [--[no]poldek] [--[no]yum] [--[no]rpmrepo] tree [tree2...]", file=sys.stderr) sys.exit(1) do_poldek = True @@ -58,10 +60,10 @@ for o, a in opts: do_rpmrepo = True if not quiet: - print "poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo) + print("poldek: %s; yum: %s; rpmrepo: %s" % (do_poldek, do_yum, do_rpmrepo)) if not do_poldek and not do_yum and not do_rpmrepo: - print >>sys.stderr, "ERR: speciy at least one action" + print("ERR: speciy at least one action", file=sys.stderr) sys.exit(1) trees = args @@ -77,25 +79,24 @@ for tree in trees: if ftpio.lock(tree, True): locked.append(tree) else: - if not quiet: - print >>sys.stderr, "ERR: %s tree already locked" % tree + print("ERR: %s tree already locked" % tree, file=sys.stderr) for i in locked: ftpio.unlock(i) sys.exit(1) home = os.environ['HOME'] -os.umask(022) +os.umask(0o022) os.nice(19) if do_poldek: poldek = '%s.stat/bin/poldek-new --cachedir=%s/tmp/poldek --conf %s.stat/etc/poldek.conf --mkidxz' % (ftp_dir, home, ftp_dir) for tree in trees: - print '\n-------------------------- %s --------------------------' % tree + print('\n-------------------------- %s --------------------------' % tree) for arch in all_ftp_archs: - print '\ngenerate poldek index for %s' % arch - print '%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch) + print('\ngenerate poldek index for %s' % arch) + print('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) os.system('%s -s %s%s/%s/RPMS/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) if arch != 'noarch' and config.separate_debuginfo: os.system('%s -s %s%s/%s/debuginfo/ --mkidxz --mkidx-type pndir' % (poldek, ftp_dir, tree, arch)) @@ -105,20 +106,20 @@ if do_yum: yum = '%s.stat/bin/createrepo -d -v --update --checkts --skip-stat --workers=12 -g %s.stat/repodata/comps.xml' % (ftp_dir, ftp_dir) comps_file = '%s.stat/repodata/comps.xml' % ftp_dir for tree in trees: - print '\n-------------------------- %s --------------------------' % tree + print('\n-------------------------- %s --------------------------' % tree) cachedir = '%s/tmp/createrepo/%s' % (home, tree) treedir = "%s%s" % (ftp_dir, tree) for arch in all_ftp_archs: - print '\ngenerate repodata for %s using createrepo' % arch + print('\ngenerate repodata for %s using createrepo' % arch) archdir = "%s/%s" % (treedir, arch) poldek_idx = "%s/RPMS/packages.ndir.md" % archdir repodata_idx = "%s/RPMS/repodata/repomd.xml" % archdir if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \ and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \ and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx): - print "repodata indexes already fresh" + print("repodata indexes already fresh") continue - print ('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir)) + print('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir)) os.system('%s %s --cache %s-%s %s/RPMS' % ("" if quiet else "time", yum, cachedir, arch, archdir)) if arch != 'noarch' and config.separate_debuginfo: os.system('%s %s --cache %s-%s %s/debuginfo' % ("" if quiet else "time", yum, cachedir, arch, archdir)) @@ -126,14 +127,14 @@ if do_yum: if do_rpmrepo: os.system('%s cd %s.stat/repodata && cvs %s up comps.xml' % ("" if quiet else "set -x;", ftp_dir, "" if quiet else "-Q")) for tree in trees: - print '\n-------------------------- %s --------------------------' % tree + print('\n-------------------------- %s --------------------------' % tree) for arch in all_ftp_archs: dir = '%s/%s/%s/RPMS' % (ftp_dir, tree, arch) if not quiet: - print '\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir) + print('\ngenerate repodata for %s using rpmrepo (in %s)' % (arch, dir)) os.system('%s rpmrepo %s -o %s' % ("" if quiet else "set -x;", dir, dir)) if not quiet: - print 'copy comps.xml' + print('copy comps.xml') comps = '%s.stat/repodata/comps.xml' % ftp_dir os.system('%s cp -p %s %s/repodata' % ("" if quiet else "set -x;", comps, dir)) diff --git a/bin/pfa-lintpkg b/bin/pfa-lintpkg index dca510f..5fe2a10 100755 --- a/bin/pfa-lintpkg +++ b/bin/pfa-lintpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import sys, os, re import getopt import subprocess @@ -12,8 +14,8 @@ import ftpio try: opts, args = getopt.getopt(sys.argv[1:], 'qsdo:', [ "quiet" ]) except getopt.GetoptError: - print >>sys.stderr, "ERR: options error" - print >>sys.stderr, "rpmlint.py tree package1 [package2...]" + print("ERR: options error", file=sys.stderr) + print("rpmlint.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) quiet = False @@ -31,8 +33,8 @@ for o, a in opts: outstream = open(a, 'w') if len(args) < 1: - print >>sys.stderr, "ERR: missing tree name" - print >>sys.stderr, "rpmlint.py tree package1 [package2...]" + print("ERR: missing tree name", file=sys.stderr) + print("rpmlint.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) treename = args[0] @@ -43,7 +45,7 @@ checkdir(treename) ftpio.connect('rpmlint') if not ftpio.lock(treename, True): - print >>sys.stderr, "ERR: %s tree already locked" % treename + print("ERR: %s tree already locked" % treename, file=sys.stderr) sys.exit(1) files = [] @@ -63,7 +65,7 @@ try: tree.mark4moving(packages) files = tree.rpmfiles(debugfiles = debugfiles, sourcefiles = False) -except (ftptree.SomeError, KeyboardInterrupt), e: +except (ftptree.SomeError, KeyboardInterrupt) as e: # In case of problems we need to unlock the tree before exiting ftpio.unlock(treename) sys.exit(1) @@ -97,7 +99,7 @@ class LintPkg: def get_stats(self, file): cachefile = self.cachefile(file) - if not os.path.exists(cachefile): + if not os.path.exists(cachefile) or os.path.getsize(cachefile) <= 0: return None # show last line (that contains status) @@ -129,13 +131,13 @@ class LintPkg: def print_stats(self, file = None): if file: (dirname, filename) = os.path.split(file) - print >>self.outstream, "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (self.packages, self.specfiles, self.errors, self.warnings, filename), + print("\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (self.packages, self.specfiles, self.errors, self.warnings, filename), file=self.outstream) else: - print >>self.outstream, "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings) + print("\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings), file=self.outstream) sys.stdout.flush() def cat(self, file): - print >>self.outstream, "".join(open(file, 'r').readlines()) + print("".join(open(file, 'r').readlines()), file=self.outstream) def show_results(self, file): m = self.get_stats(file) @@ -144,11 +146,11 @@ class LintPkg: cachefile = self.cachefile(file) if not os.path.exists(cachefile): - print >>self.outsteram, "MISSING: report: %s" % file + print("MISSING: report: %s" % file, file=self.outstream) if m['errors'] > 0 or m['warnings'] > 0: (dirname, filename) = os.path.split(file) - print >>self.outstream, "rpmlint: %s" % filename + print("rpmlint: %s" % filename, file=self.outstream) self.cat(cachefile) def rpmlint(self, file): @@ -177,11 +179,11 @@ class LintPkg: try: lock = 'rpmlint:'+treename if not ftpio.lock(lock, True): - print >>sys.stderr, "ERR: %s tree already locked for rpmlint" % treename + print("ERR: %s tree already locked for rpmlint" % treename, file=sys.stderr) sys.exit(1) if not quiet: - print >>outstream, "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) + print("rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)), file=outstream) lint = LintPkg("~/tmp/rpmlint") lint.outstream = outstream for file in files: diff --git a/bin/pfa-maintainer b/bin/pfa-maintainer index 87fe48b..31b60a1 100755 --- a/bin/pfa-maintainer +++ b/bin/pfa-maintainer @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import sys, os diff --git a/bin/pfa-mvpkg b/bin/pfa-mvpkg index dc225d1..a103670 100755 --- a/bin/pfa-mvpkg +++ b/bin/pfa-mvpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -9,7 +11,7 @@ import ftpio from mailer import Message from config import archived_trees, logs_list -os.umask(022) +os.umask(0o022) nocheckbuild = False if len(sys.argv) > 4 and sys.argv[1] == '-nb': @@ -17,10 +19,10 @@ if len(sys.argv) > 4 and sys.argv[1] == '-nb': sys.argv = sys.argv[1:] if len(sys.argv) < 4: - print >>sys.stderr, "ERR: not enough parameters given" - print >>sys.stderr, "move.py [options] src-tree dst-tree package [package2 package3 ...]" - print >>sys.stderr, "\nOptions:" - print >>sys.stderr, " -nb Do not check if builds are finished.\n" + print("ERR: not enough parameters given", file=sys.stderr) + print("move.py [options] src-tree dst-tree package [package2 package3 ...]", file=sys.stderr) + print("\nOptions:", file=sys.stderr) + print(" -nb Do not check if builds are finished.\n", file=sys.stderr) sys.exit(1) checkdir(sys.argv[1]) @@ -35,18 +37,18 @@ else: ftpio.connect('move') if not ftpio.lock(sys.argv[1], True): - print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1] + print("ERR: %s tree already locked" % sys.argv[1], file=sys.stderr) sys.exit(1) if not ftpio.lock(sys.argv[2], True): ftpio.unlock(sys.argv[1]) - print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[2] + print("ERR: %s tree already locked" % sys.argv[2], file=sys.stderr) 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 + print("ERR: %s tree already locked" % archivetreename, file=sys.stderr) sys.exit(1) try: @@ -78,7 +80,7 @@ if archivetreename != None and archivetreename != sys.argv[1]: if logs_list == None: sys.exit(0) -print 'Sending mail notification to %s...' % logs_list +print('Sending mail notification to %s...' % logs_list) pkgs = {} @@ -92,7 +94,7 @@ for pkg in srctree.marked4moving: ftpadmin = "(unknown)" try: ftpadmin = os.environ['FTPADM'] -except KeyError, e: +except KeyError as e: pass m = Message() m.set_headers( @@ -117,4 +119,4 @@ for nvr in sorted(pkgs.keys()): m.send() -print 'done.' +print('done.') diff --git a/bin/pfa-rmpkg b/bin/pfa-rmpkg index d5ee340..d44bac4 100755 --- a/bin/pfa-rmpkg +++ b/bin/pfa-rmpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -8,8 +10,8 @@ from common import checkdir import ftpio if len(sys.argv) < 3: - print "ERR: not enough parameters given" - print "remove.py tree package1 [package2...]" + print("ERR: not enough parameters given") + print("remove.py tree package1 [package2...]") sys.exit(1) checkdir(sys.argv[1]) @@ -17,7 +19,7 @@ checkdir(sys.argv[1]) ftpio.connect('remove') if not ftpio.lock(sys.argv[1], True): - print "ERR: %s tree already locked" % sys.argv[1] + print("ERR: %s tree already locked" % sys.argv[1]) sys.exit(1) try: diff --git a/bin/pfa-signpkg b/bin/pfa-signpkg index e976b2f..7df7f43 100755 --- a/bin/pfa-signpkg +++ b/bin/pfa-signpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import sys, os import getopt sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules') @@ -11,22 +13,22 @@ import ftpio from config import sign_key from sign import is_signed, signpkgs -os.umask(022) +os.umask(0o022) try: opts, args = getopt.getopt(sys.argv[1:], '') except getopt.GetoptError: - print >>sys.stderr, "ERR: options error" - print >>sys.stderr, "sign.py tree package1 [package2...]" + print("ERR: options error", file=sys.stderr) + print("sign.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) if len(args) < 1: - print >>sys.stderr, "ERR: missing tree name" - print >>sys.stderr, "sign.py tree package1 [package2...]" + print("ERR: missing tree name", file=sys.stderr) + print("sign.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) if sign_key == None: - print >>sys.stderr, "ERR: sign_key not defined in config" + print("ERR: sign_key not defined in config", file=sys.stderr) sys.exit(1) treename = args[0] @@ -37,7 +39,7 @@ checkdir(treename) ftpio.connect('sign') if not ftpio.lock(treename, True): - print >>sys.stderr, "ERR: %s tree already locked" % treename + print("ERR: %s tree already locked" % treename, file=sys.stderr) sys.exit(1) files = [] @@ -63,7 +65,7 @@ except ftptree.SomeError: ftpio.unlock(treename) -print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) +print("Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))) sign = [] n = c = 0 for file in files: @@ -71,12 +73,12 @@ for file in files: sign.append(file) c += 1 n += 1 - print "\r%d/%d %s\033[0K" % (n, c, file), + print("\r%d/%d %s\033[0K" % (n, c, file), end='') -print "" +print() if len(sign) == 0: - print "No files to sign" + print("No files to sign") sys.exit(0) # http://mail.python.org/pipermail/python-list/2009-February/700658.html @@ -95,22 +97,22 @@ def chunk(seq, size, pad=None): [[1], [2], [3], [4], [5], [6], [7], [8], [9]] >>> list(chunk(range(1,10),9)) [[1, 2, 3, 4, 5, 6, 7, 8, 9]] - >>> for X in chunk([],3): print X + >>> for X in chunk([],3): print(X) >>> ''' n = len(seq) mod = n % size - for i in xrange(0, n - mod, size): + for i in range(0, n - mod, size): yield seq[i : i + size] if mod: yield seq[-mod:] -print "Total %d files to sign" % len(sign) +print("Total %d files to sign" % len(sign)) password = getpass.getpass("Enter signing password: ") try: for x in chunk(sign, 512): - print "Signing %d files" % len(x) + print("Signing %d files" % len(x)) signpkgs(x, password) -except OSError, e: - print >>sys.stderr, "ERR: %s" % e +except OSError as e: + print("ERR: %s" % e, file=sys.stderr) exit(1) diff --git a/bin/pfa-testmvpkg b/bin/pfa-testmvpkg index c35c71e..ba2b3ce 100755 --- a/bin/pfa-testmvpkg +++ b/bin/pfa-testmvpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -9,8 +11,8 @@ 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 ...]" + print("ERR: not enough parameters given") + print("test-move.py src-tree dst-tree package [package2 package3 ...]") sys.exit(1) checkdir(sys.argv[1]) @@ -25,18 +27,18 @@ else: ftpio.connect('test-move') if not ftpio.lock(sys.argv[1], True): - print "ERR: %s tree already locked" % sys.argv[1] + 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] + 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 + print("ERR: %s tree already locked" % archivetreename) sys.exit(1) try: diff --git a/bin/pfa-unlocktree b/bin/pfa-unlocktree index 32e06a4..b439120 100755 --- a/bin/pfa-unlocktree +++ b/bin/pfa-unlocktree @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/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 @@ -8,10 +10,10 @@ import ftpio import config if len(sys.argv) < 2: - print "ERR: not enough parameters given" - print "unlock.py tree" + print("ERR: not enough parameters given") + print("unlock.py tree") sys.exit(1) for tree in sys.argv[1:]: ftpio.connect() - print "Unlock %s: %s" % (tree, ftpio.unlock(sys.argv[1])) + print("Unlock %s: %s" % (tree, ftpio.unlock(sys.argv[1]))) diff --git a/ftpiod/ftpiod.py b/ftpiod/ftpiod.py index 00f2a2e..2ca9fca 100755 --- a/ftpiod/ftpiod.py +++ b/ftpiod/ftpiod.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import sys, os diff --git a/modules/baseftptree.py b/modules/baseftptree.py index 1f3febc..64f81a4 100644 --- a/modules/baseftptree.py +++ b/modules/baseftptree.py @@ -31,12 +31,12 @@ class BasePkg: f.close() for entry in lines: - i=string.split(string.strip(entry), ':') + i=str.split(str.strip(entry), ':') if i[0] == 'info': if len(i)==3: self.info[i[1]]=i[2] elif i[1]=='build': - if not self.build.has_key(i[2]): + if i[2] not in self.build: self.build[i[2]]=Build() self.lastbid=i[2] if i[3]=='requester': @@ -48,7 +48,7 @@ class BasePkg: else: self.info[i[1]]=i[2:] elif i[0] == 'file': - if not self.files.has_key(i[1]): + if i[1] not in self.files: self.files[i[1]]=[] self.files[i[1]].append(i[2]) diff --git a/modules/cmds.py b/modules/cmds.py index 192dbf6..9fa2b19 100644 --- a/modules/cmds.py +++ b/modules/cmds.py @@ -4,7 +4,7 @@ import os import time import config import common -import md5 +import hashlib import ftptree @@ -17,7 +17,7 @@ def parse(con): con.data=con.data[len(cmd)+1:] cmdname=cmd[:4] if not con.authorized and cmdname not in ('linp', 'linc', 'name'): - raise BailOut + raise BailOut() # TODO: log unauthorized access if cmdname in cmdlist_noargs: if len(cmd)==4: @@ -32,24 +32,24 @@ def parse(con): pass # TODO: log malicious msg else: - raise BailOut + raise BailOut() # TODO: log this def lock(con, arg, hard): if arg not in locks: locks[arg]={'hard': hard, 'name': con.name, 'time': int(time.time())} - con.sock.send("OK") + con.sock.send(bytearray("OK", encoding='utf-8')) elif locks[arg]['hard']: - con.sock.send("HARD") # Hard lock - you can go get a cup of tea + con.sock.send(bytearray("HARD", encoding='utf-8')) # Hard lock - you can go get a cup of tea else: - con.sock.send("SOFT") # Soft lock - try in a second or two + con.sock.send(bytearray("SOFT", encoding='utf-8')) # Soft lock - try in a second or two def cmd_unlock(con, arg): if arg in locks: del locks[arg] - con.sock.send("OK") + con.sock.send(bytearray("OK", encoding='utf-8')) else: - con.sock.send("FAIL") + con.sock.send(bytearray("FAIL", encoding='utf-8')) def cmd_lock_soft(con, arg): lock(con, arg, False) @@ -61,17 +61,17 @@ def cmd_show_locks(con): cmd_log(con, "Dumping locks data:"); if len(locks): res = "" - for lockdata in locks.iteritems(): + for lockdata in locks.items(): tree, data = lockdata msg = "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s" % ( tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time']))) cmd_log(con, msg) res = res + msg -# con.sock.send("BLOB:%d" % len(res)) - con.sock.send(res) +# con.sock.send(bytearray("BLOB:%d" % len(res), encoding='utf-8'))) + con.sock.send(bytearray(res, encoding='utf-8')) else: - cmd_log(con, "No locks found."); - con.sock.send("NLCK"); + cmd_log(con, "No locks found.") + con.sock.send(bytearray("NLCK", encoding='utf-8')) def cmd_log(con, msg): logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), con.name, msg)) @@ -88,7 +88,7 @@ def load_creds(): return else: f=open(common.ftpadmdir+'/var/passwd', 'r') - for line in f.xreadlines(): + for line in f: x=line.strip().split(':') if len(x)>=2: users[x[0]]=x[1] @@ -97,7 +97,7 @@ def load_creds(): return else: f=open(common.ftpadmdir+'/var/cookies', 'r') - for line in f.xreadlines(): + for line in f: x=line.strip().split(':') if len(x)>=2: users[x[0]]=x[1] @@ -112,31 +112,32 @@ def write_cookies(): def cmd_login_passwd(con, data): tmp=data.split('\n') if len(tmp)!=2: - raise BailOut + raise BailOut() login=tmp[0] passwd=tmp[1] - md5pass=md5.new(passwd).hexdigest() - if login in users and users[login]==md5pass: - cookie=`time.time()`.split('.')[0]+'_'+md5.new(md5pass+salt).hexdigest() + md5pass=hashlib.md5(passwd.encode('utf-8')).hexdigest() + if login in users and users[login] == md5pass: + fullpass = md5pass+salt + cookie=repr(time.time()).split('.')[0]+'_'+hashlib.md5(fullpass.encode('utf-8')).hexdigest() cookies[cookie]=login write_cookies() con.username=login con.authorized=True - con.sock.send('OK '+cookie) + con.sock.send(bytearray('OK '+cookie, encoding='utf-8')) else: # TODO: log this - con.sock.send('FAIL') - raise BailOut + con.sock.send(bytearray('FAIL', encoding='utf-8')) + raise BailOut() def cmd_login_cookie(con, cookie): if cookie in cookies: con.cookie=cookie con.authorized=True con.username=cookies[cookie] - con.sock.send('OK '+cookies[cookie]) + con.sock.send(bytearray('OK '+cookies[cookie], encoding='utf-8')) else: # TODO: log this (or not) - con.sock.send('FAIL') + con.sock.send(bytearray('FAIL')) def cmd_logout(con): if con.cookie in cookies: @@ -146,8 +147,7 @@ def cmd_logout(con): def reloadftptree(): global srctree, pkglist srctree=ftptree.FtpTree(config.value['default_to'], loadall=True) - pkglist=srctree.keys() - pkglist.sort() + pkglist=sorted(srctree.keys()) def cmd_gettree(con): buf='' @@ -165,10 +165,10 @@ def cmd_gettree(con): line=line+'\n0' buf=buf+'\0'+line if buf: - con.sock.send('%.6d' % (len(buf)-1)) - con.sock.send(buf[1:]) + con.sock.send(bytearray('%.6d' % (len(buf)-1), encoding='utf-8')) + con.sock.send(bytearray(buf[1:], encoding='utf-8')) else: - con.sock.send('000000') + con.sock.send(bytearray('000000', encoding='utf-8')) cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock, @@ -184,5 +184,5 @@ locks={} logfile=open(common.ftpadmdir+'/var/log', 'a') load_creds() reloadftptree() -salt=md5.new(`time.time()`).hexdigest() +salt=hashlib.md5(repr(time.time()).encode('utf-8')).hexdigest() diff --git a/modules/common.py b/modules/common.py index 39279de..59f715d 100644 --- a/modules/common.py +++ b/modules/common.py @@ -1,5 +1,7 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import os, sys, config def fileexists(path): @@ -11,7 +13,7 @@ def fileexists(path): def checkdir(dir): if not fileexists(dir): - print >>sys.stderr, 'ERR: ' + config.value['ftp_dir']+'/' + dir + " does not exist" + print('ERR: ' + config.value['ftp_dir']+'/' + dir + " does not exist", file=sys.stderr) sys.exit(1) if 'HOME' in os.environ: diff --git a/modules/config.py b/modules/config.py index ee32dfa..cab0594 100644 --- a/modules/config.py +++ b/modules/config.py @@ -4,7 +4,7 @@ import string, os value = {} -if os.environ.has_key('HOME'): +if 'HOME' in os.environ: path = os.environ['HOME'] else: path = '../../' # cgi-bin interface @@ -12,13 +12,13 @@ else: f = open(path + '/.ftpadmrc', 'r') for line in f.readlines(): - if line[0] == '#' or string.find(line, '=') == -1: + if line[0] == '#' or str.find(line, '=') == -1: continue - tuple = string.split(string.strip(line), '=') + tuple = str.split(str.strip(line), '=') if tuple[1][0] == '"': - value[string.strip(tuple[0])] = tuple[1][1:-1] + value[str.strip(tuple[0])] = tuple[1][1:-1] else: - value[string.strip(tuple[0])] = string.strip(tuple[1]) + value[str.strip(tuple[0])] = str.strip(tuple[1]) f.close() diff --git a/modules/cons.py b/modules/cons.py index 61569f6..dae0587 100644 --- a/modules/cons.py +++ b/modules/cons.py @@ -30,7 +30,7 @@ class Connection: if not newdata: self.destroy() else: - self.data = self.data + newdata + self.data = self.data + newdata.decode("utf-8") try: cmds.parse(self) @@ -58,9 +58,9 @@ def createlistener(path): s.setblocking(False) s.bind(path) if path==ftpio.pubsock: - os.chmod(path, 0606) + os.chmod(path, 0o606) else: - os.chmod(path, 0600) + os.chmod(path, 0o600) s.listen(3) return s diff --git a/modules/ftpio.py b/modules/ftpio.py index 96fbc53..453f6d0 100644 --- a/modules/ftpio.py +++ b/modules/ftpio.py @@ -8,7 +8,7 @@ import config pubsock=config.value['pubsock'] -if os.environ.has_key('HOME'): +if 'HOME' in os.environ: privsock=os.environ['HOME']+'/tld-ftp-admin/var/privsock' socketname=privsock else: @@ -20,12 +20,12 @@ def connect(name=None): sock.connect(socketname) if not name: name = "pid_%d_name_%s" % (os.getpid(), sys.argv[0]) - sock.send('name %s\0' % name) + sock.send(bytearray('name %s\0' % name, encoding='utf-8')) def login_passwd(login, passwd): 'Return cookie if ok' - sock.send('linp %s\n%s\0' % (login, passwd)) - retval=sock.recv(256) + sock.send(bytearray('linp %s\n%s\0' % (login, passwd), encoding='utf-8')) + retval=sock.recv(256).decode("utf-8") if retval=='FAIL': return '' else: @@ -33,23 +33,23 @@ def login_passwd(login, passwd): def login_cookie(cookie): 'Return login if ok' - sock.send('linc %s\0' % cookie) - retval=sock.recv(256) + sock.send(bytearray('linc %s\0' % cookie, encoding='utf-8')) + retval=sock.recv(256).decode('utf-8') if retval=='FAIL': return '' else: return retval[3:] def logout(): - sock.send('lout\0') + sock.send(bytearray('lout\0', encoding='utf-8')) def lock(path, hard=False): def dolock(): if hard: - sock.send('lckh %s\0' % path) + sock.send(bytearray('lckh %s\0' % path, encoding='utf-8')) else: - sock.send('lcks %s\0' % path) - return sock.recv(20) + sock.send(bytearray('lcks %s\0' % path, encoding='utf-8')) + return sock.recv(20).decode("utf-8") for i in range(3): retcode=dolock() if retcode=="OK": @@ -61,31 +61,31 @@ def lock(path, hard=False): return False def unlock(path): - sock.send('ulck %s\0' % path) - ret = sock.recv(20) + sock.send(bytearray('ulck %s\0' % path, encoding='utf-8')) + ret = sock.recv(20).decode("utf-8") if ret == "OK": return True return False def log(msg): - sock.send('log1 %s\0' % msg) + sock.send(bytearray('log1 %s\0' % msg, encoding='utf-8')) def locks_dump(): - sock.send('slck\0') - ret = sock.recv(4096) + sock.send(bytearray('slck\0', encoding='utf-8')) + ret = sock.recv(4096).decode("utf-8") if ret == "NLCK": return "No locks held" # nbytes = int(ret.split("BLOB:")[1]) -# ret = sock.recv(nbytes) +# ret = sock.recv(nbytes).decode("utf-8") return ret def gettree(): - sock.send('gett\0') + sock.send(bytearray('gett\0', encoding='utf-8')) pkgs=[] - len=int(sock.recv(6)) + len=int(sock.recv(6).decode("utf-8")) if len: - for pkg in sock.recv(len).split('\0'): + for pkg in sock.recv(len).decode("utf-8").split('\0'): tmp=pkg.split('\n') pkgs.append((tmp[0], int(tmp[1]), int(tmp[2]))) return pkgs diff --git a/modules/ftptree.py b/modules/ftptree.py index 70db8a0..aa00e02 100644 --- a/modules/ftptree.py +++ b/modules/ftptree.py @@ -1,6 +1,17 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et -import os, config, string, urllib, re, rpm +from __future__ import print_function + +import os +import config +import string +try: + import urllib.request as urlmess +except ImportError: + import urllib as urlmess + pass +import re +import rpm from common import fileexists, noarchcachedir from baseftptree import BasePkg, BaseFtpTree from sign import is_signed @@ -13,23 +24,23 @@ class SomeError(Exception): return def __str__(self): - print "","An Error occured!" + return "An Error occured!" def bailoutonerror(): if not errnum == 0: - print "%d error(s) encountered... aborting" % errnum - raise SomeError + print("%d error(s) encountered... aborting" % errnum) + raise SomeError() def pinfo(msg): - print 'INFO: ' + msg + print('INFO: ' + msg) def perror(msg): global errnum errnum = errnum + 1 - print 'ERR: ' + msg + print('ERR: ' + msg) def pwarning(msg): - print 'WARN: ' + msg + print('WARN: ' + msg) def rm(file, test = False): if test: @@ -38,7 +49,7 @@ def rm(file, test = False): else: try: os.remove(file) - except OSError, e: + except OSError as e: pinfo("os.remove(%s): %s" % (file, e)) #raise @@ -53,14 +64,14 @@ def mv(src, dst, test = False): else: try: os.rename(fsrc, fdst) - except OSError, e: + except OSError as e: pinfo("os.rename(%s, %s): %s" % (fsrc, fdst, e)) raise class Pkg(BasePkg): def __init__(self, nvr, tree): BasePkg.__init__(self, nvr, tree) - self.name = string.join(nvr.split('-')[:-2], '-') + self.name = '-'.join(nvr.split('-')[:-2]) self.version = nvr.split('-')[-2] self.release = nvr.split('-')[-1] self.marked4removal = False @@ -88,7 +99,7 @@ class Pkg(BasePkg): if not config.separate_debuginfo: return False pkg = nvr.split('-')[:-2] - return pkg[-1] == 'debuginfo' + return pkg[-1] == 'debuginfo' or pkg[-1] == 'debugsource' def is_sourcefile(self, file): """ @@ -139,7 +150,7 @@ class Pkg(BasePkg): def load(self, content=None): BasePkg.load(self, content) - if self.info.has_key('move'): + if 'move' in self.info: self.mark4moving() def writeinfo(self): @@ -147,7 +158,7 @@ class Pkg(BasePkg): for bid in self.build.keys(): f.write("info:build:%s:requester:%s\ninfo:build:%s:requester_email:%s\n" % (bid, self.build[bid].requester, bid, self.build[bid].requester_email)) for key in self.info.keys(): - f.write("info:%s:%s\n" % (key, string.join(self.info[key], ':'))) + f.write("info:%s:%s\n" % (key, ':'.join(self.info[key]))) for arch in self.files.keys(): for rpm in self.files[arch]: f.write("file:%s:%s\n" % (arch, rpm)) @@ -273,14 +284,14 @@ class FtpTree(BaseFtpTree): self.do_checkbuild = True def __getitem__(self, key): - if self.loadedpkgs.has_key(key): + if key in self.loadedpkgs: return self.loadedpkgs[key] elif key in self.pkgnames: pkg=Pkg(key, self) self.loadedpkgs[key]=pkg return pkg else: - raise KeyError, key + raise KeyError(key) def has_key(self, key): if key in self.pkgnames: @@ -369,8 +380,8 @@ class FtpTree(BaseFtpTree): return True else: return False - list = filter(checkfiletype, os.listdir(self.basedir+'/SRPMS/.metadata')) - self.pkgnames = map((lambda x: x[:-13]), list) + pkglist = list(filter(checkfiletype, os.listdir(self.basedir+'/SRPMS/.metadata'))) + self.pkgnames = list(map((lambda x: x[:-13]), pkglist)) def __mark4something(self, wannabepkgs, markfunction): def chopoffextension(pkg): @@ -396,11 +407,11 @@ class FtpTree(BaseFtpTree): Reads config.builderqueue to grab the info """ - f = urllib.urlopen(config.builderqueue) + f = urlmess.urlopen(config.builderqueue) requests = {} reid = re.compile(r'^.*id=(.*) pri.*$') regb = re.compile(r'^group:.*$|builders:.*$', re.M) - for i in re.findall(regb, f.read()): + for i in re.findall(regb, f.read().decode('utf-8')): if i[0] == 'g': id = reid.sub(r'\1', i) requests[id] = "" @@ -410,7 +421,7 @@ class FtpTree(BaseFtpTree): for pkg in marked: for bid in pkg.build.keys(): - if requests.has_key(bid) and not requests[bid].find('?') == -1: + if bid in requests and not requests[bid].find('?') == -1: pkg.error("(buildid %s) building not finished" % bid) def __checkarchs(self, dsttree, marked): @@ -487,7 +498,7 @@ class FtpTree(BaseFtpTree): return True else: return False - return filter(filter_other_pkgs, tree.pkgnames) + return list(filter(filter_other_pkgs, tree.pkgnames)) def __find_older_pkgs(self, pkg): def filter_older_pkgs(x): @@ -498,7 +509,7 @@ class FtpTree(BaseFtpTree): return True else: return False - return filter(filter_older_pkgs, self.__find_other_pkgs(pkg, self)) + return list(filter(filter_older_pkgs, self.__find_other_pkgs(pkg, self))) def __checksigns(self, tree, pkgs, test = False): """ @@ -535,7 +546,7 @@ class FtpTree(BaseFtpTree): def findbyname(name): def x(nvr): return '-'.join(nvr.split('-')[:-2]) == name - return filter(x, tree.pkgnames) + return list(filter(x, tree.pkgnames)) for pkg in pkgs: obsoletes = pkg.obsoletes() diff --git a/modules/mailer.py b/modules/mailer.py index bf13ef5..825446f 100644 --- a/modules/mailer.py +++ b/modules/mailer.py @@ -3,7 +3,10 @@ import time import os import sys -import StringIO +if sys.version_info[0] == 2: + import StringIO +else: + import io as StringIO import config cval=config.value diff --git a/modules/sign.py b/modules/sign.py index 377ee51..dc5cc4f 100644 --- a/modules/sign.py +++ b/modules/sign.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import os @@ -40,20 +40,24 @@ def is_signed(rpm_file): def signpkgs(files, password): if not os.path.isfile('/usr/bin/gpg'): - raise OSError, 'Missing gnupg binary' + raise OSError('Missing gnupg binary') if not os.path.isfile('/bin/rpm'): - raise OSError, 'Missing rpm binary' + raise OSError('Missing rpm binary') os.putenv('LC_ALL', 'C') args = ['--resign', '--define', '_signature gpg', '--define', '_gpg_name ' + sign_key] + files - child = pexpect.spawn('/bin/rpm', args) + child = pexpect.spawn('/bin/rpm', args, encoding='utf-8') child.logfile_read = sys.stderr - child.expect('Enter pass phrase:', timeout=30) - child.sendline(password) + # TODO: we need a smarter way to figuring out if rpm already stored password in gpg-agent + try: + child.expect(u'Enter pass phrase:', timeout=30) + child.sendline(password) + except pexpect.exceptions.TIMEOUT: + print('WARN: rpm did not ask for password', file=sys.stderr) child.expect(pexpect.EOF, timeout=None) child.close() rc = child.exitstatus if rc != 0: - raise OSError, 'package signing failed' + raise OSError('package signing failed') for rpm in files: - os.chmod(rpm, 0644) + os.chmod(rpm, 0o644) diff --git a/modules/user.py b/modules/user.py index 2b31f1a..7f41958 100644 --- a/modules/user.py +++ b/modules/user.py @@ -1,5 +1,7 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import Cookie, time, ftpio UserNotLoggedIn="UserNotLoggedIn" @@ -31,8 +33,8 @@ class User: #C['ftpsessid']['expires']=time.strftime( #"%a, %d-%b-%y %H:%M:%S GMT", #time.gmtime(time.time()+86400)) - print C - + print(C) + def logout(self): self.loggedin=False ftpio.logout() @@ -40,5 +42,5 @@ class User: C['ftpsessid']='' C['ftpsessid']['expires']=time.strftime("%a, %d-%b-%y %H:%M:%S GMT", time.gmtime(time.time()-31536000)) - print C + print(C) diff --git a/modules/wwwiface.py b/modules/wwwiface.py index bc215ae..4e65630 100644 --- a/modules/wwwiface.py +++ b/modules/wwwiface.py @@ -1,5 +1,7 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import cgi, Cookie, os menu=[] @@ -14,11 +16,11 @@ def getfile(file): def catfile(file): f=open("../html/" + file + ".html", 'r') - print f.read() + print(f.read()) f.close() def sendhttpheaders(): - print "Content-Type: text/html\n" + print("Content-Type: text/html\n") def getopts(): form = cgi.FieldStorage() @@ -28,7 +30,7 @@ def getopts(): cookies = {} - if os.environ.has_key('HTTP_COOKIE'): + if 'HTTP_COOKIE' in os.environ: c = Cookie.SimpleCookie() c.load(os.environ['HTTP_COOKIE']) for key in c.keys(): @@ -39,21 +41,21 @@ def getopts(): def sendhtml(): catfile('header') - print '') - print '') - print '
' + print('
') for i in content: - print i - print '
' + print(i) + print('
') catfile('footer')