From e6e0150e07be32b91624b460b67be39b8f6b0ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 2 Jul 2012 08:05:06 +0200 Subject: Make exception syntax consistent --- gbp/scripts/buildpackage.py | 30 +++++++++++++++--------------- gbp/scripts/clone.py | 2 +- gbp/scripts/common/buildpackage.py | 8 ++++---- gbp/scripts/common/pq.py | 4 ++-- gbp/scripts/dch.py | 14 +++++++------- gbp/scripts/import_dsc.py | 12 ++++++------ gbp/scripts/import_dscs.py | 6 +++--- gbp/scripts/import_orig.py | 36 ++++++++++++++++++------------------ gbp/scripts/pq.py | 14 +++++++------- gbp/scripts/pull.py | 2 +- 10 files changed, 64 insertions(+), 64 deletions(-) (limited to 'gbp/scripts') diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 91a13bb5..daa791cd 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -46,7 +46,7 @@ def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submo try: comp_opts = compressor_opts[comp_type][0] except KeyError: - raise GbpError, "Unsupported compression type '%s'" % comp_type + raise GbpError("Unsupported compression type '%s'" % comp_type) output = os.path.join(output_dir, du.orig_file(cp, comp_type)) prefix = "%s-%s" % (cp['Source'], cp['Upstream-Version']) @@ -63,7 +63,7 @@ def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submo except CommandExecFailed: gbp.log.err("Error generating submodules' archives") return False - except OSError, err: + except OSError as err: gbp.log.err("Error creating %s: %s" % (output, err[0])) return False except GbpError: @@ -148,7 +148,7 @@ def export_source(repo, tree, cp, options, dest_dir, tarball_dir): # Extract orig tarball if git-overlay option is selected: if options.overlay: if cp.is_native(): - raise GbpError, "Cannot overlay Debian native package" + raise GbpError("Cannot overlay Debian native package") extract_orig(os.path.join(tarball_dir, du.orig_file(cp, options.comp_type)), dest_dir) gbp.log.info("Exporting '%s' to '%s'" % (options.export, dest_dir)) @@ -160,7 +160,7 @@ def move_old_export(target): """move a build tree away if it exists""" try: os.mkdir(target) - except OSError, (e, msg): + except OSError as (e, msg): if e == errno.EEXIST: os.rename(target, "%s.obsolete.%s" % (target, time.time())) @@ -194,11 +194,11 @@ def fetch_changelog(repo, options, tree): else: cp = ChangeLog(filename=changelog) except NoChangeLogError: - raise GbpError, "'%s' does not exist, not a debian package" % changelog - except ParseChangeLogError, err: - raise GbpError, "Error parsing Changelog: %s" % err + raise GbpError("'%s' does not exist, not a debian package" % changelog) + except ParseChangeLogError as err: + raise GbpError("Error parsing Changelog: %s" % err) except KeyError: - raise GbpError, "Can't parse version from changelog" + raise GbpError("Can't parse version from changelog") return cp @@ -211,9 +211,9 @@ def prepare_output_dir(dir): try: os.mkdir(output_dir) - except OSError, (e, msg): + except OSError as (e, msg): if e != errno.EEXIST: - raise GbpError, "Cannot create output dir %s" % output_dir + raise GbpError("Cannot create output dir %s" % output_dir) return output_dir def pristine_tar_build_orig(repo, cp, output_dir, options): @@ -306,7 +306,7 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): for comp in compressor_opts.keys(): if du.DebianPkgPolicy.has_orig(du.orig_file(cp, comp), tarball_dir): if detected is not None: - raise GbpError, "Multiple orig tarballs found." + raise GbpError("Multiple orig tarballs found.") detected = comp if detected is not None: comp_type = detected @@ -356,7 +356,7 @@ def parse_args(argv, prefix): try: parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix=prefix) - except ConfigParser.ParsingError, err: + except ConfigParser.ParsingError as err: gbp.log.err(err) return None, None, None @@ -470,7 +470,7 @@ def main(argv): if not ret: gbp.log.err("You have uncommitted changes in your source tree:") gbp.log.err(out) - raise GbpError, "Use --git-ignore-new to ignore." + raise GbpError("Use --git-ignore-new to ignore.") try: branch = repo.get_branch() @@ -482,7 +482,7 @@ def main(argv): if not options.ignore_new and not options.ignore_branch: if branch != options.debian_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) - raise GbpError, "Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name." + raise GbpError("Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name.") tree = write_tree(repo, options) cp = fetch_changelog(repo, options, tree) @@ -564,7 +564,7 @@ def main(argv): 'GBP_SHA1': sha})() except CommandExecFailed: retval = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index 5dffbd09..f8933448 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -102,7 +102,7 @@ def main(argv): except CommandExecFailed: retval = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 921bc159..8bbf1436 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -97,7 +97,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules): try: ret = pipe.copy('', '') if ret: - raise GbpError, "Error in dump_tree archive pipe" + raise GbpError("Error in dump_tree archive pipe") if with_submodules: if repo.has_submodules(): @@ -113,11 +113,11 @@ def dump_tree(repo, export_dir, treeish, with_submodules): ret = pipe.copy('', '') os.chdir(top) if ret: - raise GbpError, "Error in dump_tree archive pipe in submodule %s" % subdir - except OSError, err: + raise GbpError("Error in dump_tree archive pipe in submodule %s" % subdir) + except OSError as err: gbp.log.err("Error dumping tree to %s: %s" % (output_dir, err[0])) return False - except GbpError, err: + except GbpError as err: gbp.log.err(err) return False except Exception as e: diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 2c4fa092..0e0b75bd 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -139,8 +139,8 @@ def switch_to_pq_branch(repo, branch): try: repo.create_branch(pq_branch) except CommandExecFailed: - raise GbpError, ("Cannot create patch-queue branch '%s'. Try 'rebase' instead." - % pq_branch) + raise GbpError("Cannot create patch-queue branch '%s'. Try 'rebase' instead." + % pq_branch) gbp.log.info("Switching to '%s'" % pq_branch) repo.set_branch(pq_branch) diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 6d88ea6e..dd5503ad 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -215,8 +215,8 @@ def mangle_changelog(changelog, cp, snapshot=''): cr.close() os.unlink(changelog) os.rename(tmpfile, changelog) - except OSError, e: - raise GbpError, "Error mangling changelog %s" % e + except OSError as e: + raise GbpError("Error mangling changelog %s" % e) def do_release(changelog, repo, cp, git_author, dch_options): @@ -337,7 +337,7 @@ def main(argv): try: parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] paths') - except ConfigParser.ParsingError, err: + except ConfigParser.ParsingError as err: gbp.log.errror(err) return 1 range_group = GbpOptionGroup(parser, "commit range options", @@ -418,12 +418,12 @@ def main(argv): try: repo = DebianGitRepository('.') except GitRepositoryError: - raise GbpError, "%s is not a git repository" % (os.path.abspath('.')) + raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) branch = repo.get_branch() if options.debian_branch != branch and not options.ignore_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) - raise GbpError, "Use --ignore-branch to ignore or --debian-branch to set the branch name." + raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.") cp = ChangeLog(filename=changelog) @@ -441,7 +441,7 @@ def main(argv): if not since: since = repo.find_version(options.debian_tag, cp['Version']) if not since: - raise GbpError, "Version %s not found" % cp['Version'] + raise GbpError("Version %s not found" % cp['Version']) if args: gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) @@ -537,7 +537,7 @@ def main(argv): repo.commit_files([changelog], msg) gbp.log.info("Changelog has been committed for version %s" % version) - except (GbpError, GitRepositoryError, NoChangeLogError), err: + except (GbpError, GitRepositoryError, NoChangeLogError) as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index 879b537a..15fa7ea1 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -71,7 +71,7 @@ def apply_patch(diff): if ret: gbp.log.err("Error import %s: %d" % (diff, ret)) return False - except OSError, err: + except OSError as err: gbp.log.err("Error importing %s: %s" % (diff, err[0])) return False return True @@ -183,7 +183,7 @@ def parse_args(argv): try: parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] /path/to/package.dsc') - except ConfigParser.ParsingError, err: + except ConfigParser.ParsingError as err: gbp.log.err(err) return None, None @@ -261,7 +261,7 @@ def main(argv): src = parse_dsc(dsc) if src.pkgformat not in [ '1.0', '3.0' ]: - raise GbpError, "Importing %s source format not yet supported." % src.pkgformat + raise GbpError("Importing %s source format not yet supported." % src.pkgformat) if options.verbose: print_dsc(src) @@ -272,7 +272,7 @@ def main(argv): (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") - raise GbpError, out + raise GbpError(out) except GitRepositoryError: # no repo found, create one @@ -357,10 +357,10 @@ def main(argv): gbp.log.err("Interrupted. Aborting.") except gbpc.CommandExecFailed: ret = 1 - except GitRepositoryError, msg: + except GitRepositoryError as msg: gbp.log.err("Git command failed: %s" % msg) ret = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index 7cc19f3c..32565346 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -61,7 +61,7 @@ def fetch_snapshots(pkg, downloaddir): dscs = glob.glob(os.path.join(downloaddir, '*.dsc')) if not dscs: - raise GbpError, 'No package downloaded' + raise GbpError('No package downloaded') return [os.path.join(downloaddir, dsc) for dsc in dscs] @@ -136,7 +136,7 @@ def main(argv): (clean, out) = repo.is_clean() if not clean: gbp.log.err("Repository has uncommitted changes, commit these first: ") - raise GbpError, out + raise GbpError(out) else: dirs['pkg'] = dirs['top'] except GitRepositoryError: @@ -149,7 +149,7 @@ def main(argv): for dsc in dscs[1:]: importer.importdsc(dsc) - except (GbpError, gbpc.CommandExecFailed), err: + except (GbpError, gbpc.CommandExecFailed) as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index feb5a605..c7e2b183 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -62,8 +62,8 @@ def symlink_orig(archive, pkg, version): try: if not is_link_target(archive, link): os.symlink(os.path.abspath(archive), link) - except OSError, err: - raise GbpError, "Cannot symlink '%s' to '%s': %s" % (archive, link, err[1]) + except OSError as err: + raise GbpError("Cannot symlink '%s' to '%s': %s" % (archive, link, err[1])) return link else: return archive @@ -98,7 +98,7 @@ def detect_name_and_version(repo, source, options): if guessed_package: sourcepackage = guessed_package else: - raise GbpError, "Couldn't determine upstream package name. Use --interactive." + raise GbpError("Couldn't determine upstream package name. Use --interactive.") # Try to find the version. if options.version: @@ -112,7 +112,7 @@ def detect_name_and_version(repo, source, options): if guessed_version: version = guessed_version else: - raise GbpError, "Couldn't determine upstream version. Use '-u' or --interactive." + raise GbpError("Couldn't determine upstream version. Use '-u' or --interactive.") return (sourcepackage, version) @@ -125,27 +125,27 @@ def find_source(options, args): """ if options.uscan: # uscan mode if args: - raise GbpError, "you can't pass both --uscan and a filename." + raise GbpError("you can't pass both --uscan and a filename.") gbp.log.info("Launching uscan...") try: status, source = do_uscan() except KeyError: - raise GbpError, "error running uscan - debug by running uscan --verbose" + raise GbpError("error running uscan - debug by running uscan --verbose") if status: if source: gbp.log.info("using %s" % source) args.append(source) else: - raise GbpError, "uscan didn't download anything, and no source was found in ../" + raise GbpError("uscan didn't download anything, and no source was found in ../") else: gbp.log.info("package is up to date, nothing to do.") return None if len(args) > 1: # source specified - raise GbpError, "More than one archive specified. Try --help." + raise GbpError("More than one archive specified. Try --help.") elif len(args) == 0: - raise GbpError, "No archive to import specified. Try --help." + raise GbpError("No archive to import specified. Try --help.") else: archive = OrigUpstreamSource(args[0]) return archive @@ -165,7 +165,7 @@ def parse_args(argv): try: parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan') - except ConfigParser.ParsingError, err: + except ConfigParser.ParsingError as err: gbp.log.err(err) return None, None @@ -241,7 +241,7 @@ def main(argv): try: repo = DebianGitRepository('.') except GitRepositoryError: - raise GbpError, "%s is not a git repository" % (os.path.abspath('.')) + raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) # an empty repo has now branches: initial_branch = repo.get_branch() @@ -256,7 +256,7 @@ def main(argv): (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") - raise GbpError, out + raise GbpError(out) if repo.bare: set_bare_repo_options(options) @@ -275,7 +275,7 @@ def main(argv): # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): - raise GbpError, "The orig tarball contains .git metadata - giving up." + raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass @@ -303,7 +303,7 @@ def main(argv): other_parents=parents, ) if not commit: - raise GbpError, "Import of upstream version %s failed." % version + raise GbpError("Import of upstream version %s failed." % version) if options.pristine_tar: if pristine_orig: @@ -326,7 +326,7 @@ def main(argv): try: repo.merge(tag) except gbpc.CommandExecFailed: - raise GbpError, """Merge failed, please resolve.""" + raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): @@ -340,12 +340,12 @@ def main(argv): env = { 'GBP_BRANCH': options.debian_branch } gbpc.Command(options.postimport % info, extra_env=env, shell=True)() except gbpc.CommandExecFailed: - raise GbpError, "Import of %s failed" % source.path - except GbpNothingImported, err: + raise GbpError("Import of %s failed" % source.path) + except GbpNothingImported as err: gbp.log.err(err) repo.set_branch(initial_branch) ret = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 2fcc0c83..44b88192 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -49,9 +49,9 @@ def export_patches(repo, branch, options): pq_branch = pq_branch_name(branch) try: shutil.rmtree(PATCH_DIR) - except OSError, (e, msg): + except OSError as (e, msg): if e != errno.ENOENT: - raise GbpError, "Failed to remove patch dir: %s" % msg + raise GbpError("Failed to remove patch dir: %s" % msg) else: gbp.log.debug("%s does not exist." % PATCH_DIR) @@ -122,8 +122,8 @@ def import_quilt_patches(repo, branch, series, tries, force): if force: drop_pq(repo, branch) else: - raise GbpError, ("Patch queue branch '%s'. already exists. Try 'rebase' instead." - % pq_branch) + raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' instead." + % pq_branch) commits = repo.get_commits(num=tries, first_parent=True) # If we go back in history we have to safe our pq so we always try to apply @@ -137,7 +137,7 @@ def import_quilt_patches(repo, branch, series, tries, force): gbp.log.info("Trying to apply patches at '%s'" % commit) repo.create_branch(pq_branch, commit) except CommandExecFailed: - raise GbpError, ("Cannot create patch-queue branch '%s'." % pq_branch) + raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch) repo.set_branch(pq_branch) for patch in queue: @@ -152,7 +152,7 @@ def import_quilt_patches(repo, branch, series, tries, force): # All patches applied successfully break else: - raise GbpError, "Couldn't apply patches" + raise GbpError("Couldn't apply patches") if tmpdir: gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir) @@ -251,7 +251,7 @@ def main(argv): switch_pq(repo, current) except CommandExecFailed: retval = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index d50ffc23..adfe2bc7 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -127,7 +127,7 @@ def main(argv): repo.set_branch(current) except CommandExecFailed: retval = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 -- cgit v1.2.3