-#!/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')
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]
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 = []
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
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)
-#!/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
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])
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)
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)
self.pkgliststartpad = 0
def __do_quit(self):
- raise DoQuit
+ raise DoQuit()
def __do_mark(self):
pkg=self.elements[self.pkglistselected]
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]):
-#!/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
import config
ftpio.connect()
-print ftpio.locks_dump()
+print(ftpio.locks_dump())
-#!/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
from ftptree import FtpTree, Pkg
import ftpio
-os.umask(022)
+os.umask(0o022)
def rm(file):
os.remove(file)
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):
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()
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" %
(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')
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')
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
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))
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')
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'
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']:
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
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)
-#!/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')
]
)
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
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
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))
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))
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))
-#!/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
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
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]
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 = []
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)
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)
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)
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):
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:
-#!/usr/bin/env python
+#!/usr/bin/env python3
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import sys, os
-#!/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
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':
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])
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:
if logs_list == None:
sys.exit(0)
-print 'Sending mail notification to %s...' % logs_list
+print('Sending mail notification to %s...' % logs_list)
pkgs = {}
ftpadmin = "(unknown)"
try:
ftpadmin = os.environ['FTPADM']
-except KeyError, e:
+except KeyError as e:
pass
m = Message()
m.set_headers(
m.send()
-print 'done.'
+print('done.')
-#!/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
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])
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:
-#!/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')
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]
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 = []
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:
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
[[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)
-#!/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
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])
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:
-#!/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
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])))
-#!/usr/bin/env python
+#!/usr/bin/env python3
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import sys, os
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':
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])
import time
import config
import common
-import md5
+import hashlib
import ftptree
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:
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)
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))
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]
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]
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:
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=''
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,
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()
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+from __future__ import print_function
+
import os, sys, config
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:
value = {}
-if os.environ.has_key('HOME'):
+if 'HOME' in os.environ:
path = os.environ['HOME']
else:
path = '../../' # cgi-bin interface
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()
if not newdata:
self.destroy()
else:
- self.data = self.data + newdata
+ self.data = self.data + newdata.decode("utf-8")
try:
cmds.parse(self)
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
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:
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:
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":
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
# 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
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:
else:
try:
os.remove(file)
- except OSError, e:
+ except OSError as e:
pinfo("os.remove(%s): %s" % (file, e))
#raise
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
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):
"""
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):
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))
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:
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):
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] = ""
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):
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):
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):
"""
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()
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
-#!/usr/bin/env python
+#!/usr/bin/env python3
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
import os
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)
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+from __future__ import print_function
+
import Cookie, time, ftpio
UserNotLoggedIn="UserNotLoggedIn"
#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()
C['ftpsessid']=''
C['ftpsessid']['expires']=time.strftime("%a, %d-%b-%y %H:%M:%S GMT",
time.gmtime(time.time()-31536000))
- print C
+ print(C)
# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+from __future__ import print_function
+
import cgi, Cookie, os
menu=[]
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()
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():
def sendhtml():
catfile('header')
- print '<div id="Header">'
+ print('<div id="Header">')
for i in header:
- print i
- print '</div>'
+ print(i)
+ print('</div>')
- print '<div id="Menu">'
+ print('<div id="Menu">')
for i in menu:
- print i
+ print(i)
catfile('menufooter')
- print '</div>'
+ print('</div>')
- print '<div id="Content">'
+ print('<div id="Content">')
for i in content:
- print i
- print '</div>'
+ print(i)
+ print('</div>')
catfile('footer')