diff options
author | Guido Günther <agx@sigxcpu.org> | 2014-06-19 18:43:12 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-06-19 19:09:51 +0200 |
commit | d5662f99db18df6704d55092af08e3d9b4d9c599 (patch) | |
tree | 9ae4d5ca38fb0b3ca7c8813796d3be6f216d7116 | |
parent | 17c2ee87ee338b2634d51bde18f4eeb216e562e5 (diff) |
Python3 cleanups
-rw-r--r-- | stagepkg/command.py | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/stagepkg/command.py b/stagepkg/command.py index 1d71f81..bc84803 100644 --- a/stagepkg/command.py +++ b/stagepkg/command.py @@ -41,7 +41,7 @@ def get_files(changes_file): """Get all the files referenced in a changes file""" files = [] try: - cf = file(changes_file) + cf = open(changes_file) except: return [] fre=re.compile(" [a-f0-9]{32}\s+[0-9]{2,}\s+[a-z0-9/-]+\s+[a-z-]+\s+(?P<fname>.*_(?P<arch>(all|i386|.*))\.(?P<ext>(dsc|gz|bz2|deb|udeb)))") @@ -92,7 +92,7 @@ def copy_files(files, repo_path, incoming_path): for f in files: src = "%s/%s" % (repo_path, f) if simulate: - print "Copy: %s to %s" % (src, dst) + print("Copy: %s to %s" % (src, dst)) else: shutil.copy(src, dst) @@ -103,7 +103,7 @@ def link_files(files, repo_path, incoming_path): for f in files: src = "%s/%s" % (repo_path, f) if simulate: - print "Linking: %s to %s" % (src, dst) + print("Linking: %s to %s" % (src, dst)) else: os.link(src, dst) @@ -113,7 +113,7 @@ def mangle_changes_file(changes_file, pkg, version, from_repo, to_repo, arch): """we might have things like unstable/foo, but the distribution (as noted in the changelog/changes file) is only foo.""" return dist.split('/')[-1] - cf = file(changes_file) + cf = open(changes_file) distline = "Distribution: %s" distre = re.compile(distline % (get_dist(from_repo), )) chline = r" %s \(%s\) %s; urgency=" @@ -143,12 +143,12 @@ def mangle_changes_file(changes_file, pkg, version, from_repo, to_repo, arch): continue changes += [ line ] changes = "".join(changes) - + filename = get_changes_file_path(get_subarchive(to_repo)+"mini-dinstall/incoming", pkg, version, arch) if simulate: print - print "Changes file %s" % (filename, ) - print changes + print("Changes file %s" % (filename, )) + print(changes) print return matched, changes, filename @@ -163,8 +163,8 @@ def sign_changes_file(changes, signas, dest): p.write(changes) p.close() else: - print cmd - + print(cmd) + def dump_changes_file(changes, dest): """writeout unsigned changes file""" @@ -173,13 +173,13 @@ def dump_changes_file(changes, dest): f.write(changes) f.close() else: - print "writing changes file to '%s'" % dest + print("writing changes file to '%s'" % dest) def remove_files(files, repo_path): for tounlink in [ "%s/%s" % (repo_path, f) for f in files ]: if simulate: - print "Unlink: %s" % (tounlink, ) + print("Unlink: %s" % (tounlink, )) else: os.unlink(tounlink) @@ -192,9 +192,9 @@ def parse_pkg_list(list): list = os.path.join(list_dir, list) if not os.access(list, os.R_OK): - raise ListNotFound, "List '%s' not found" % list + raise ListNotFound("List '%s' not found" % list) - lf = file(list) + lf = open(list) for line in lf: pkg = line.strip() if pkg.startswith("#"): @@ -211,13 +211,13 @@ def parachute(from_repo, to_repo): try: from_suite, from_comp = from_repo.split("/") except ValueError: - raise ValueError, "Source repository has no '/'" + raise ValueError("Source repository has no '/'") try: to_suite, to_comp = to_repo.split("/") except ValueError: - raise ValueError, "Target repository has no '/'" + raise ValueError("Target repository has no '/'") if from_suite != to_suite: - raise ValueError, "Source suite '%s' is different from destination suite '%s'" % (from_suite, to_suite) + raise ValueError("Source suite '%s' is different from destination suite '%s'" % (from_suite, to_suite)) from_level = from_comp.split("-")[-1] to_level = to_comp.split("-")[-1] if to_level not in order: @@ -225,26 +225,26 @@ def parachute(from_repo, to_repo): if from_level not in order: from_level = "stable" if from_level == "stable": - raise ValueError, "Refusing to remove out of a stable archive" + raise ValueError("Refusing to remove out of a stable archive") index = order.index(from_level)+1 if order[index] != to_level: - raise ValueError, "'%s' is not the next step after '%s'" % (to_level, from_level) - except ValueError, msg: - print >>sys.stderr, "%s - use --force to override" % msg + raise ValueError("'%s' is not the next step after '%s'" % (to_level, from_level)) + except ValueError as e: + print >>sys.stderr, "%s - use --force to override" % e return False return True -def check_repo(path): +def check_repo(path): try: if not stat.S_ISDIR(os.stat(path).st_mode): print >>sys.stderr, "Target '%s' is not a directory" % path return False - except OSError, (errnum, errmsg): - if errnum == errno.ENOENT: + except OSError as e: + if e.errno == errno.ENOENT: msg = "Target archive '%s' does not exist" % path else: - msg = errmsg + msg = e.strerror print >>sys.stderr, msg return False if not os.access (path, os.R_OK): @@ -346,16 +346,16 @@ def run(): try: dropoff(files, get_repo_path(from_repo), get_incoming_path(get_subarchive(to_repo))) - except IOError, (num, msg): - if num == errno.ENOENT: - print >>sys.stderr, "%s, skipping package %s." % (msg, pkg) + except IOError as e: + if e.errno == errno.ENOENT: + print >>sys.stderr, "Error handling '%s': %s, skipping package %s." % (e.filename, e.strerror, pkg) retval = 1 continue else: - raise IOError, (num, msg) + raise (ret, changes, dest) = mangle_changes_file(changes_file, pkglist[0], version, from_repo, to_repo, options.arch) if not ret: - print "Couldn't find %s in changes file %s - bad changes file - skipping package '%s'." % (from_repo, changes_file, pkg) + print("Couldn't find %s in changes file %s - bad changes file - skipping package '%s'." % (from_repo, changes_file, pkg)) retval = 1 continue try: @@ -372,6 +372,6 @@ def run(): return retval if __name__ == "__main__": - sys.exit(main()) + sys.exit(run()) # vim:et:ts=4:sw=4: |