From: Jan Rękorajski Date: Sun, 25 Oct 2020 07:49:06 +0000 (+0100) Subject: Make ftp tools python3 ready X-Git-Url: http://git.pld-linux.org/gitweb.cgi?a=commitdiff_plain;h=94960bbc9900d9bf1385501fda80589f7e9c64b1;p=projects%2Fpld-ftp-admin.git Make ftp tools python3 ready --- diff --git a/wwwbin/clean-dups-archive.py b/wwwbin/clean-dups-archive.py index 4961c39..293e2ee 100755 --- a/wwwbin/clean-dups-archive.py +++ b/wwwbin/clean-dups-archive.py @@ -2,6 +2,8 @@ # arekm, 2008 # remove +from __future__ import print_function + import os import re import time @@ -18,13 +20,13 @@ def compare(f1, f2): try: fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY) except Exception, e: - print e + print(e) # ignore non-files return 0 try: fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY) except Exception, e: - print e + print(e) # ignore non-files return 0 h1 = ts.hdrFromFdno(fd1) @@ -53,7 +55,7 @@ for file in os.listdir(dir): m = re_nvr.match(file) if not m: - print "problem with: %s" % file + print("problem with: %s" % file) sys.exit(1) if len(sys.argv) == 0: @@ -73,6 +75,6 @@ for file in os.listdir(dir): else: files[name] = file -for i in dupes.iterkeys(): +for i in iter(dupes.keys()): for old in find_old(dupes[i])[1:]: os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py .archive/PLD %s" % old) diff --git a/wwwbin/clean-dups-old.py b/wwwbin/clean-dups-old.py index e0ba2a0..27a8e93 100755 --- a/wwwbin/clean-dups-old.py +++ b/wwwbin/clean-dups-old.py @@ -2,6 +2,8 @@ # arekm, 2008 # remove +from __future__ import print_function + import os import re import time @@ -44,7 +46,7 @@ for file in os.listdir(dir): m = re_nvr.match(file) if not m: - print "problem with: %s" % file + print("problem with: %s" % file) sys.exit(1) if len(sys.argv) == 0: @@ -64,6 +66,6 @@ for file in os.listdir(dir): else: files[name] = file -for i in dupes.iterkeys(): +for i in iter(dupes.keys()): for old in find_old(dupes[i])[1:]: os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old) diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py index 003b538..2806915 100755 --- a/wwwbin/clean-dups.py +++ b/wwwbin/clean-dups.py @@ -2,6 +2,8 @@ # arekm, 2008 # remove +from __future__ import print_function + import os import re import time @@ -49,19 +51,19 @@ def compare(f1, f2): try: fd1 = os.open(os.path.join(dir, f1), os.O_RDONLY) except Exception, e: - print e + print(e) # ignore non-files return 0 try: fd2 = os.open(os.path.join(dir, f2), os.O_RDONLY) except Exception, e: - print e + print(e) # ignore non-files return 0 try: h1 = ts.hdrFromFdno(fd1) except Exception, e: - print "hdrFromFdno for %s failed: %s" % (f1, e) + print("hdrFromFdno for %s failed: %s" % (f1, e)) os.close(fd1) os.close(fd2) return 0 @@ -69,7 +71,7 @@ def compare(f1, f2): try: h2 = ts.hdrFromFdno(fd2) except Exception, e: - print "hdrFromFdno for %s failed: %s" % (f2, e) + print("hdrFromFdno for %s failed: %s" % (f2, e)) os.close(fd1) os.close(fd2) return 0 @@ -101,7 +103,7 @@ for file in os.listdir(dir): m = re_nvr.match(file) if not m: - print "problem with: %s" % file + print("problem with: %s" % file) sys.exit(1) if len(sys.argv) == 0: @@ -121,7 +123,7 @@ for file in os.listdir(dir): else: files[name] = file -for i in dupes.iterkeys(): +for i in iter(dupes.keys()): for old in find_old(dupes[i])[1:]: - print "removing: %s" % old + print("removing: %s" % old) os.system("/home/pld/admins/th/pld-ftp-admin/scripts/remove.py test %s" % old) diff --git a/wwwbin/dump-packagenames.py b/wwwbin/dump-packagenames.py index 59f9e89..963026f 100755 --- a/wwwbin/dump-packagenames.py +++ b/wwwbin/dump-packagenames.py @@ -1,5 +1,7 @@ #!/usr/bin/python +from __future__ import print_function + import os import re @@ -36,7 +38,7 @@ for dir in dirs: try: hdr = ts.hdrFromFdno(fdno) except Exception, e: - print "hdrFromFdno: %s: %s" % (rpm_file, e) + print("hdrFromFdno: %s: %s" % (rpm_file, e)) os.close(fdno) continue os.close(fdno) @@ -45,13 +47,13 @@ for dir in dirs: sourcerpm = hdr[rpm.RPMTAG_SOURCERPM] m = re_nvr.match(sourcerpm) if not m: - print "%s: doesn't match src.rpm file name" % (sourcerpm) + print("%s: doesn't match src.rpm file name" % (sourcerpm)) continue srcname = m.group(1) pkgs[name] = srcname f = open(outname + ".tmp", "w") -for (pkg, spkg) in pkgs.iteritems(): +for (pkg, spkg) in iter(pkgs.items()): f.write("%s:%s\n" % (pkg, spkg)) f.close() os.chmod(outname + ".tmp", 0644) diff --git a/wwwbin/ftp-freshness.py b/wwwbin/ftp-freshness.py index 3208269..ddfe53f 100755 --- a/wwwbin/ftp-freshness.py +++ b/wwwbin/ftp-freshness.py @@ -1,6 +1,8 @@ #!/usr/bin/python # arekm, 2007 +from __future__ import print_function + import os import rpm import subprocess @@ -41,16 +43,16 @@ class Pkgs(object): for macro in ['rel', '_rel', 'snap', '_snap', 'rc', '_rc', 'subver', 'githash']: rpm.delMacro(macro) macros = rpm.getMacros() - for macro in macros.iterkeys(): + for macro in iter(macros.keys()): if macro[:5] == 'with_' or macro[:8] == 'without_': rpm.delMacro(macro.split()[0]) def __get_from_cvs(self, name): spec = os.path.join(specsdir, name + '.spec') if not os.path.isfile(spec): - print >>sys.stderr, 'Spec file does not exist: %s' % spec + print('Spec file does not exist: %s' % spec, file=sys.stderr) return ('','','') - print >>sys.stderr, 'Processing: %s.spec' % name + print('Processing: %s.spec' % name, file=sys.stderr) self.__clean_macros() try: s = self.ts.parseSpec(spec) @@ -60,7 +62,7 @@ class Pkgs(object): release = header[rpm.RPMTAG_RELEASE].partition('@')[0] return (name, version, release) except rpm.error: - print >>sys.stderr, 'Failed to parse: %s.spec' % name + print('Failed to parse: %s.spec' % name, file=sys.stderr) return ('','','') def __update_cvs(self, name): @@ -113,8 +115,8 @@ class Pkgs(object): ver_frac += msg else: ver_int += msg - print ver_int - print ver_frac + print(ver_int) + print(ver_frac) def print_nv(self): ver_int = "*** VERSION COMPARE ONLY ***\n" @@ -128,8 +130,8 @@ class Pkgs(object): ver_frac += msg else: ver_int += msg - print ver_int - print ver_frac + print(ver_int) + print(ver_frac) p = Pkgs() @@ -141,5 +143,5 @@ for d in dirs: p.prepare() p.print_nv() -print "\n\n" +print("\n\n") p.print_nvr()