diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-09-09 10:41:19 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-09-12 08:52:07 +0200 |
commit | d1c163401153329363a010373cb512f8e59ef1e2 (patch) | |
tree | 4360253804301e13b626a47d3ee9b7740dc9fbec /gbp | |
parent | f7db3b77c491e5f76f441a1155aa87b1e5dedde6 (diff) |
pep8/pyflakes cleanups
Diffstat (limited to 'gbp')
31 files changed, 151 insertions, 115 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index c33b4d97..fb630892 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -21,7 +21,6 @@ git-buildpackage and friends import subprocess import os -import os.path import signal import gbp.log as log diff --git a/gbp/deb/__init__.py b/gbp/deb/__init__.py index b3b82254..6a240ec1 100644 --- a/gbp/deb/__init__.py +++ b/gbp/deb/__init__.py @@ -27,6 +27,7 @@ from gbp.git import GitRepositoryError from gbp.deb.changelog import ChangeLog, NoChangeLogError from gbp.deb.policy import DebianPkgPolicy + class DpkgCompareVersions(gbpc.Command): dpkg = '/usr/bin/dpkg' @@ -43,16 +44,16 @@ class DpkgCompareVersions(gbpc.Command): @raises CommandExecFailed: if the version comparison fails """ self.run_error = "Couldn't compare %s with %s" % (version1, version2) - res = self.call([ version1, 'lt', version2 ]) - if res not in [ 0, 1 ]: + res = self.call([version1, 'lt', version2]) + if res not in [0, 1]: if self.stderr: self.run_error += ' (%s)' % self.stderr raise gbpc.CommandExecFailed("%s: bad return code %d" % (self.run_error, res)) if res == 0: return -1 elif res == 1: - res = self.call([ version1, 'gt', version2 ]) - if res not in [ 0, 1 ]: + res = self.call([version1, 'gt', version2]) + if res not in [0, 1]: if self.stderr: self.run_error += ' (%s)' % self.stderr raise gbpc.CommandExecFailed("%s: bad return code %d" % (self.run_error, res)) diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py index fa4ba10e..06daebe2 100644 --- a/gbp/deb/changelog.py +++ b/gbp/deb/changelog.py @@ -23,10 +23,12 @@ import os import subprocess from gbp.command_wrappers import Command + class NoChangeLogError(Exception): """No changelog found""" pass + class ParseChangeLogError(Exception): """Problem parsing changelog""" pass @@ -92,9 +94,9 @@ class ChangeLog(object): def _parse(self): """Parse a changelog based on the already read contents.""" cmd = subprocess.Popen(['dpkg-parsechangelog', '-l-'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) (output, errors) = cmd.communicate(self._contents) if cmd.returncode: raise ParseChangeLogError("Failed to parse changelog. " @@ -138,8 +140,8 @@ class ChangeLog(object): @property def version(self): - """The full version string""" - return self._cp['Version'] + """The full version string""" + return self._cp['Version'] @property def upstream_version(self): @@ -198,7 +200,7 @@ class ChangeLog(object): """ section = '' for line in self._contents.split('\n'): - if line and line[0] not in [ ' ', '\t' ]: + if line and line[0] not in [' ', '\t']: section += line else: if section: diff --git a/gbp/deb/control.py b/gbp/deb/control.py index 603b3de7..efa92cac 100644 --- a/gbp/deb/control.py +++ b/gbp/deb/control.py @@ -19,14 +19,17 @@ import email import os + class NoControlError(Exception): """No control found""" pass + class ParseControlError(Exception): """Problem parsing control""" pass + class Control(object): """A Debian control""" diff --git a/gbp/deb/dscfile.py b/gbp/deb/dscfile.py index e64cf565..e81e0bbd 100644 --- a/gbp/deb/dscfile.py +++ b/gbp/deb/dscfile.py @@ -29,16 +29,16 @@ class DscFile(object): compressions = r"(%s)" % '|'.join(DebianUpstreamSource.known_compressions()) pkg_re = re.compile(r'Source:\s+(?P<pkg>.+)\s*') version_re = re.compile(r'Version:\s((?P<epoch>\d+)\:)?' - '(?P<version>[%s]+)\s*$' + '(?P<version>[%s]+)\s*$' % DebianPkgPolicy.debianversion_chars) tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+' - '(\.orig)?\.tar\.%s)' % compressions) + '(\.orig)?\.tar\.%s)' % compressions) add_tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+' '\.orig-(?P<dir>[a-z0-9-]+)\.tar\.%s)' % compressions) diff_re = re.compile(r'^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+' - '\.diff.(gz|bz2))') + '\.diff.(gz|bz2))') deb_tgz_re = re.compile(r'^\s\w+\s\d+\s+(?P<deb_tgz>[^_]+_[^_]+' - '\.debian.tar.%s)' % compressions) + '\.debian.tar.%s)' % compressions) format_re = re.compile(r'Format:\s+(?P<format>[0-9.]+)\s*') def __init__(self, dscfile): @@ -63,7 +63,7 @@ class DscFile(object): self.upstream_version = "-".join(m.group('version').split("-")[0:-1]) self.native = False else: - self.native = True # Debian native package + self.native = True # Debian native package self.upstream_version = m.group('version') if m.group('epoch'): self.epoch = m.group('epoch') @@ -113,7 +113,7 @@ class DscFile(object): self.additional_tarballs = dict(add_tars) def _get_version(self): - version = [ "", self.epoch + ":" ][len(self.epoch) > 0] + version = ["", self.epoch + ":"][len(self.epoch) > 0] if self.native: version += self.upstream_version else: diff --git a/gbp/deb/format.py b/gbp/deb/format.py index b9c4eb0f..f3d444a7 100644 --- a/gbp/deb/format.py +++ b/gbp/deb/format.py @@ -16,9 +16,11 @@ # <http://www.gnu.org/licenses/> """Parse debian/source/format""" + class DebianSourceFormatError(Exception): pass + class DebianSourceFormat(object): """ Contents of debian/source/format @@ -47,8 +49,7 @@ class DebianSourceFormat(object): self._version = parts[0] if len(parts) == 2: - if (parts[1][0] == '(' and - parts[1][-1] == ')'): + if (parts[1][0] == '(' and parts[1][-1] == ')'): self._type = parts[1][1:-1] else: raise DebianSourceFormatError("Cannot get source format from " diff --git a/gbp/deb/pristinetar.py b/gbp/deb/pristinetar.py index ab7fbd65..a80fd4b3 100644 --- a/gbp/deb/pristinetar.py +++ b/gbp/deb/pristinetar.py @@ -20,6 +20,7 @@ from gbp.pkg import compressor_opts from gbp.pkg.pristinetar import PristineTar from gbp.deb import DebianPkgPolicy + class DebianPristineTar(PristineTar): """The pristine-tar branch in a Debian git repository""" def has_commit(self, package, version, comp_type=None): @@ -63,4 +64,3 @@ class DebianPristineTar(PristineTar): output_dir, component=component) super(DebianPristineTar, self).checkout(name) - diff --git a/gbp/deb/source.py b/gbp/deb/source.py index 2466ab90..7b8ef98e 100644 --- a/gbp/deb/source.py +++ b/gbp/deb/source.py @@ -22,6 +22,7 @@ from gbp.deb.changelog import ChangeLog import six + class FileVfs(object): def __init__(self, dir): """ @@ -36,9 +37,11 @@ class FileVfs(object): flags = flags or 'r' return open(os.path.join(self._dir, path), flags) + class DebianSourceError(Exception): pass + class DebianSource(object): """ A debianized source tree @@ -68,10 +71,10 @@ class DebianSource(object): if f.type: return f.type == 'native' except IOError as e: - pass # Fall back to changelog parsing + pass # Fall back to changelog parsing try: - return not '-' in self.changelog.version + return '-' not in self.changelog.version except IOError as e: raise DebianSourceError("Failed to determine source format: %s" % e) diff --git a/gbp/deb/uscan.py b/gbp/deb/uscan.py index d81492a5..4613b960 100644 --- a/gbp/deb/uscan.py +++ b/gbp/deb/uscan.py @@ -16,11 +16,15 @@ # <http://www.gnu.org/licenses/> """Interface to uscan""" -import os, re, subprocess +import os +import re +import subprocess + class UscanError(Exception): pass + class Uscan(object): cmd = '/usr/bin/uscan' @@ -84,7 +88,7 @@ class Uscan(object): for n in ('package', 'upstream-version', 'upstream-url'): - m = re.match("<%s>(.*)</%s>" % (n,n), row) + m = re.match("<%s>(.*)</%s>" % (n, n), row) if m: d[n] = m.group(1) d["ext"] = os.path.splitext(d['upstream-url'])[1] @@ -94,10 +98,10 @@ class Uscan(object): # Fall back to the upstream source name otherwise if not os.path.exists(source): - source = "../%s" % d['upstream-url'].rsplit('/',1)[1] + source = "../%s" % d['upstream-url'].rsplit('/', 1)[1] if not os.path.exists(source): raise UscanError("Couldn't find tarball at '%s'" % - source) + source) except KeyError as e: raise UscanError("Couldn't find '%s' in uscan output" % e.args[0]) @@ -157,7 +161,7 @@ class Uscan(object): msg = None for n in ('errors', 'warnings'): - m = re.search("<%s>(.*)</%s>" % (n,n), out, re.DOTALL) + m = re.search("<%s>(.*)</%s>" % (n, n), out, re.DOTALL) if m: msg = "Uscan failed: %s" % m.group(1) break @@ -166,7 +170,6 @@ class Uscan(object): msg = "Uscan failed - debug by running 'uscan --verbose'" raise UscanError(msg) - def scan(self, destdir='..'): """Invoke uscan to fetch a new upstream version""" p = subprocess.Popen(['uscan', '--symlink', '--destdir=%s' % destdir, diff --git a/gbp/git/__init__.py b/gbp/git/__init__.py index 81e1422d..5e5240df 100644 --- a/gbp/git/__init__.py +++ b/gbp/git/__init__.py @@ -19,13 +19,14 @@ import calendar import dateutil.parser -from gbp.git.modifier import GitModifier -from gbp.git.commit import GitCommit -from gbp.git.errors import GitError -from gbp.git.repository import GitRepository, GitRepositoryError -from gbp.git.fastimport import FastImport -from gbp.git.args import GitArgs -from gbp.git.vfs import GitVfs +from gbp.git.modifier import GitModifier # noqa: F401 +from gbp.git.commit import GitCommit # noqa: F401 +from gbp.git.errors import GitError # noqa: F401 +from gbp.git.repository import ( # noqa: F401 + GitRepository, GitRepositoryError) +from gbp.git.fastimport import FastImport # noqa: F401 +from gbp.git.args import GitArgs # noqa: F401 +from gbp.git.vfs import GitVfs # noqa: F401 def rfc822_date_to_git(rfc822_date): diff --git a/gbp/git/args.py b/gbp/git/args.py index 197097f4..95e50116 100644 --- a/gbp/git/args.py +++ b/gbp/git/args.py @@ -21,6 +21,7 @@ Git command argument handling helpers import six import collections + class GitArgs(object): """ Handle arguments to git commands @@ -106,4 +107,3 @@ class GitArgs(object): else: self.add(noopt) return self - diff --git a/gbp/git/commit.py b/gbp/git/commit.py index cfc5d0c7..1a9912f8 100644 --- a/gbp/git/commit.py +++ b/gbp/git/commit.py @@ -18,7 +18,6 @@ import re -from gbp.git.errors import GitError class GitCommit(object): """A git commit""" @@ -44,5 +43,3 @@ class GitCommit(object): @rtype: C{bool} """ return True if GitCommit.sha1_re.match(value) else False - - diff --git a/gbp/git/errors.py b/gbp/git/errors.py index 47122b8e..377e468a 100644 --- a/gbp/git/errors.py +++ b/gbp/git/errors.py @@ -16,7 +16,7 @@ # <http://www.gnu.org/licenses/> """Git base error exception""" + class GitError(Exception): """Exception thrown by Git related classes""" pass - diff --git a/gbp/git/fastimport.py b/gbp/git/fastimport.py index 1195fee6..f5a6b678 100644 --- a/gbp/git/fastimport.py +++ b/gbp/git/fastimport.py @@ -21,12 +21,13 @@ import subprocess import time from gbp.errors import GbpError + class FastImport(object): """Add data to a git repository using I{git fast-import}""" _bufsize = 1024 m_regular = 644 - m_exec = 755 + m_exec = 755 m_symlink = 120000 def __init__(self, repo): @@ -36,7 +37,7 @@ class FastImport(object): """ self._repo = repo try: - self._fi = subprocess.Popen([ 'git', 'fast-import', '--quiet'], + self._fi = subprocess.Popen(['git', 'fast-import', '--quiet'], stdin=subprocess.PIPE, cwd=repo.path) self._out = self._fi.stdin except OSError as err: diff --git a/gbp/git/modifier.py b/gbp/git/modifier.py index 847c4e6d..cb8bec19 100644 --- a/gbp/git/modifier.py +++ b/gbp/git/modifier.py @@ -21,14 +21,17 @@ like committing changes or authoring a patch """ import six -import calendar, datetime +import calendar +import datetime from gbp.git.errors import GitError + class GitModifierError(GitError): """Exception thrown by L{GitModifier}""" pass + class GitTz(datetime.tzinfo): """Simple class to store the utc offset only""" def __init__(self, offset_sec=0, *args, **kwargs): @@ -41,6 +44,7 @@ class GitTz(datetime.tzinfo): def dst(self, dt): return datetime.timedelta(0) + class GitModifier(object): """Stores authorship/committer information""" def __init__(self, name=None, email=None, date=None): @@ -64,16 +68,16 @@ class GitModifier(object): timestamp, offset = date.split() offset_h = int(offset[:-2]) offset_m = int(offset[-2:]) - tz = GitTz(offset_h*3600 + offset_m*60) + tz = GitTz(offset_h * 3600 + offset_m * 60) self._date = datetime.datetime.fromtimestamp(int(timestamp), tz) - elif type(date) in [ type(0), type(0.0) ]: + elif type(date) in [type(0), type(0.0)]: self._date = datetime.datetime.fromtimestamp(date, tz) elif isinstance(date, datetime.datetime): if date.tzinfo: self._date = date else: self._date = date.replace(tzinfo=tz) - elif date != None: + elif date is not None: raise ValueError("Date '%s' not timestamp, " "datetime object or git raw date" % date) @@ -154,7 +158,7 @@ class GitModifier(object): @staticmethod def keys(): - return [ 'name', 'email', 'date' ] + return ['name', 'email', 'date'] def items(self): items = [] diff --git a/gbp/git/vfs.py b/gbp/git/vfs.py index b34e5736..191cf621 100644 --- a/gbp/git/vfs.py +++ b/gbp/git/vfs.py @@ -17,7 +17,8 @@ """Make blobs in a git repository accessible as file like objects""" from six import StringIO -from gbp.git.repository import GitRepositoryError +from gbp.git.repository import GitRepositoryError + class GitVfs(object): @@ -124,24 +124,30 @@ def err(msg): """Logs a message with level ERROR on the GBP logger""" LOGGER.error(msg) + def error(msg): err(msg) + def warn(msg): """Logs a message with level WARNING on the GBP logger""" LOGGER.warning(msg) + def warning(msg): warn(msg) + def info(msg): """Logs a message with level INFO on the GBP logger""" LOGGER.info(msg) + def debug(msg): """Logs a message with level DEBUG on the GBP logger""" LOGGER.debug(msg) + def _parse_color_scheme(color_scheme=""): """Set logging colors""" scheme = {} @@ -159,9 +165,11 @@ def _parse_color_scheme(color_scheme=""): except ValueError: try: scheme[level] = COLORS[color.lower()] - except KeyError: pass + except KeyError: + pass return scheme + def setup(color, verbose, color_scheme=""): """Basic logger setup""" LOGGER.set_color(color) @@ -176,4 +184,3 @@ def setup(color, verbose, color_scheme=""): logging.setLoggerClass(GbpLogger) LOGGER = getLogger("gbp") - diff --git a/gbp/pkg/pristinetar.py b/gbp/pkg/pristinetar.py index 91977897..ac24998f 100644 --- a/gbp/pkg/pristinetar.py +++ b/gbp/pkg/pristinetar.py @@ -20,9 +20,10 @@ import os import gbp.log from gbp.command_wrappers import Command + class PristineTar(Command): """The pristine-tar branch in a git repository""" - cmd='/usr/bin/pristine-tar' + cmd = '/usr/bin/pristine-tar' branch = 'pristine-tar' def __init__(self, repo): @@ -79,4 +80,3 @@ class PristineTar(Command): self.run_error = ("Couldn't commit to '%s' with upstream '%s': {stderr}" % (self.branch, upstream)) self.__call__(['commit', archive, upstream]) - diff --git a/gbp/rpm/git.py b/gbp/rpm/git.py index 77cb3116..5f11a082 100644 --- a/gbp/rpm/git.py +++ b/gbp/rpm/git.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, please see # <http://www.gnu.org/licenses/> -import re from gbp.format import format_str from gbp.errors import GbpError diff --git a/gbp/rpm/lib_rpm.py b/gbp/rpm/lib_rpm.py index 4abc6665..5fc0354e 100644 --- a/gbp/rpm/lib_rpm.py +++ b/gbp/rpm/lib_rpm.py @@ -26,8 +26,8 @@ try: librpm = __import__(RpmPkgPolicy.python_rpmlib_module_name) except ImportError: gbp.log.warn("Failed to import '%s' as rpm python module, using host's " - "default rpm library instead" % - RpmPkgPolicy.python_rpmlib_module_name) + "default rpm library instead" % + RpmPkgPolicy.python_rpmlib_module_name) import rpm as librpm # Module initialization @@ -44,4 +44,3 @@ def get_librpm_log(truncate=True): if truncate: _rpmlogfd.truncate(0) return log - diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 676ee742..5944abf5 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -1,6 +1,6 @@ # vim: set fileencoding=utf-8 : # -# (C) 2006-2011 Guido Guenther <agx@sigxcpu.org> +# (C) 2006-2011, 2016 Guido Guenther <agx@sigxcpu.org> # (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,7 +18,8 @@ # """Common functionality for Debian and RPM buildpackage scripts""" -import os, os.path +import os +import os.path import pipes import tempfile import shutil @@ -112,7 +113,7 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts raise GbpError("Error creating %s: %d" % (output, ret)) -#{ Functions to handle export-dir +# Functions to handle export-dir def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): "dump a tree to output_dir" output_dir = os.path.dirname(export_dir) @@ -147,7 +148,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): ret = pipe.copy('', '') os.chdir(top) if ret: - raise GbpError("Error in dump_tree archive pipe in submodule %s" % subdir) + 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 diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 24a56f10..069a36da 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -35,6 +35,7 @@ try: except ImportError: pass + def orig_needs_repack(upstream_source, options): """ Determine if the upstream sources needs to be repacked diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index e0abc196..fca4ec31 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -176,6 +176,7 @@ def write_patch_file(filename, commit_info, diff): DEFAULT_PATCH_NUM_PREFIX_FORMAT = "%04d-" + def format_patch(outdir, repo, commit_info, series, numbered=True, path_exclude_regex=None, topic='', name=None, renumber=False, patch_num_prefix_format=DEFAULT_PATCH_NUM_PREFIX_FORMAT): @@ -188,10 +189,10 @@ def format_patch(outdir, repo, commit_info, series, numbered=True, try: num_prefix = str(patch_num_prefix_format) % (len(series) + 1) \ - if numbered else '' + if numbered else '' except Exception: - gbp.log.warn("Bad format format string '%s', " \ - "falling back to default '%s'" % \ + gbp.log.warn("Bad format format string '%s', " + "falling back to default '%s'" % (str(patch_num_prefix_format), DEFAULT_PATCH_NUM_PREFIX_FORMAT)) num_prefix = DEFAULT_PATCH_NUM_PREFIX_FORMAT % (len(series) + 1) @@ -200,7 +201,7 @@ def format_patch(outdir, repo, commit_info, series, numbered=True, if renumber: # Remove any existing numeric prefix if the patch # should be renumbered - name = re.sub('^\d+[-_]*', '', name) + name = re.sub('^\d+[-_]*', '', name) else: # Otherwise, clear proposed prefix num_prefix = '' @@ -214,9 +215,8 @@ def format_patch(outdir, repo, commit_info, series, numbered=True, filepath = os.path.join(outdir, filename) # Make sure that we don't overwrite existing patches in the series if filepath in series: - presuffix = '-%d' % \ - len([p for p in series \ - if p.startswith(os.path.splitext(filepath)[0])]) + presuffix = '-%d' % len([p for p in series + if p.startswith(os.path.splitext(filepath)[0])]) filename = num_prefix + base + presuffix + suffix filepath = os.path.join(outdir, filename) diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py index 72bcc886..9872d7fc 100755 --- a/gbp/scripts/config.py +++ b/gbp/scripts/config.py @@ -18,7 +18,7 @@ """Query and display config file values""" import sys -import os, os.path +import os from gbp.config import GbpOptionParser from gbp.errors import GbpError from gbp.scripts.supercommand import import_command diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index ffc32eaa..85a49b54 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -70,6 +70,7 @@ def print_config(remote, branches): remote = %s merge = refs/heads/%s""" % (branch, remote['name'], branch)) + def sort_dict(d): """Return a sorted list of (key, value) tuples""" s = [] @@ -77,6 +78,7 @@ def sort_dict(d): s.append((key, d[key])) return s + def parse_url(remote_url, name, pkg, template_dir=None): """ Sanity check our remote URL @@ -116,7 +118,7 @@ def parse_url(remote_url, name, pkg, template_dir=None): else: raise GbpError("URL must use ssh protocol.") - if not '%(pkg)s' in remote_url and not remote_url.endswith(".git"): + if '%(pkg)s' not in remote_url and not remote_url.endswith(".git"): raise GbpError("URL needs to contain either a repository name or '%(pkg)s'") if ":" in frags.netloc: @@ -162,7 +164,7 @@ def build_remote_script(remote, branch): args['git-init-args'] = '--bare --shared' if args['template-dir']: args['git-init-args'] += (' --template=%s' - % args['template-dir']) + % args['template-dir']) remote_script_pattern = ['', 'set -e', 'umask 002', @@ -214,7 +216,7 @@ def read_yn(): if old_settings: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - if ch in ( 'y', 'Y' ): + if ch in ('y', 'Y'): return True else: return False @@ -293,7 +295,7 @@ def parse_args(argv, sections=[]): # section to parse, this makes e.g. --help work as expected: for arg in argv: if arg.startswith('--remote-config='): - sections = ['remote-config %s' % arg.split('=',1)[1]] + sections = ['remote-config %s' % arg.split('=', 1)[1]] break else: sections = [] @@ -325,12 +327,12 @@ def main(argv): try: branches = [] - for branch in [ options.debian_branch, options.upstream_branch ]: + for branch in [options.debian_branch, options.upstream_branch]: if repo.has_branch(branch): - branches += [ branch ] + branches += [branch] if repo.has_pristine_tar_branch() and options.pristine_tar: - branches += [ repo.pristine_tar_branch ] + branches += [repo.pristine_tar_branch] try: cp = ChangeLog(filename=changelog) diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index 7e049a9e..b592d81d 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -29,6 +29,7 @@ from gbp.scripts import import_dsc from gbp.config import GbpOptionParser import gbp.log + class DscCompareVersions(DpkgCompareVersions): def __init__(self): DpkgCompareVersions.__init__(self) @@ -51,8 +52,8 @@ def fetch_snapshots(pkg, downloaddir): gbp.log.info("Downloading snapshots of '%s' to '%s'..." % (pkg, downloaddir)) - debsnap = gbpc.Command("debsnap", [ '--force', '--destdir=%s' % - (downloaddir), pkg]) + debsnap = gbpc.Command("debsnap", ['--force', '--destdir=%s' % + (downloaddir), pkg]) try: debsnap() except gbpc.CommandExecFailed: @@ -68,6 +69,7 @@ def fetch_snapshots(pkg, downloaddir): return [os.path.join(downloaddir, dsc) for dsc in dscs] + def set_gbp_conf_files(): """ Filter out all gbp.conf files that are local to the git repository and set @@ -78,13 +80,14 @@ def set_gbp_conf_files(): os.environ['GBP_CONF_FILES'] = gbp_conf_files gbp.log.debug("Setting GBP_CONF_FILES to '%s'" % gbp_conf_files) + def print_help(): print("""Usage: gbp import-dscs [options] [gbp-import-dsc options] /path/to/dsc1 [/path/to/dsc2] ... gbp import-dscs --debsnap [options] [gbp-import-dsc options] package Options: - --debsnap: use debsnap command to download packages + --debsnap: use debsnap command to download packages --ignore-repo-config ignore gbp.conf in git repo """) @@ -129,7 +132,7 @@ def main(argv): if use_debsnap: dirs['tmp'] = os.path.abspath(tempfile.mkdtemp()) - dscs = [ DscFile.parse(f) for f in fetch_snapshots(pkg, dirs['tmp']) ] + dscs = [DscFile.parse(f) for f in fetch_snapshots(pkg, dirs['tmp'])] dscs.sort(cmp=dsc_cmp) importer = GitImportDsc(import_args) diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 8c51a5f8..67ad842d 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -49,6 +49,7 @@ class RollbackError(GitRepositoryError): def __str__(self): return "%s %s" % (self.msg, self.errors) + class ImportOrigDebianGitRepository(DebianGitRepository): """ Like a DebianGitRepository but can also perform rollbacks and knows @@ -441,7 +442,6 @@ def build_parser(name): dest="components") cmd_group.add_config_file_option(option_name="postimport", dest="postimport") - parser.add_boolean_config_file_option(option_name="interactive", dest='interactive') parser.add_boolean_config_file_option(option_name="rollback", diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 3cdec8a0..51539dc1 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -32,15 +32,15 @@ from gbp.errors import GbpError import gbp.log from gbp.patch_series import (PatchSeries, Patch) from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base, - parse_gbp_commands, format_patch, - switch_to_pq_branch, apply_single_patch, - apply_and_commit_patch, switch_pq, - drop_pq, get_maintainer_from_control) + parse_gbp_commands, format_patch, + switch_to_pq_branch, apply_single_patch, + apply_and_commit_patch, switch_pq, + drop_pq, get_maintainer_from_control) from gbp.scripts.common import ExitCodes from gbp.dch import extract_bts_cmds PATCH_DIR = "debian/patches/" -SERIES_FILE = os.path.join(PATCH_DIR,"series") +SERIES_FILE = os.path.join(PATCH_DIR, "series") def parse_old_style_topic(commit_info): @@ -158,12 +158,12 @@ def commit_patches(repo, branch, patches, options): vfs = gbp.git.vfs.GitVfs(repo, branch) try: oldseries = vfs.open('debian/patches/series') - oldpatches = [ p.strip() for p in oldseries.readlines() ] + oldpatches = [p.strip() for p in oldseries.readlines()] oldseries.close() except IOError: # No series file yet oldpatches = [] - newpatches = [ p[len(PATCH_DIR):] for p in patches ] + newpatches = [p[len(PATCH_DIR):] for p in patches] # FIXME: handle case were only the contents of the patches changed added, removed = compare_series(oldpatches, newpatches) @@ -338,7 +338,7 @@ def import_quilt_patches(repo, branch, series, tries, force, pq_from, else: # All patches applied successfully break - i-=1 + i -= 1 else: raise GbpError("Couldn't apply patches") @@ -368,20 +368,24 @@ def rebase_pq(repo, branch, pq_from, upstream_tag): GitCommand("rebase", cwd=repo.path)([_from]) +def usage_msg(): + return """%prog [options] action - maintain patches on a patch queue branch +Actions: + export export the patch queue associated to the current branch + into a quilt patch series in debian/patches/ and update the + series file. + import create a patch queue branch from quilt patches in debian/patches. + rebase switch to patch queue branch associated to the current + branch and rebase against current branch. + drop drop (delete) the patch queue associated to the current branch. + apply apply a patch + switch switch to patch-queue branch and vice versa""" + + def build_parser(name): try: parser = GbpOptionParserDebian(command=os.path.basename(name), - usage="%prog [options] action - maintain patches on a patch queue branch\n" - "Actions:\n" - " export export the patch queue associated to the current branch\n" - " into a quilt patch series in debian/patches/ and update the\n" - " series file.\n" - " import create a patch queue branch from quilt patches in debian/patches.\n" - " rebase switch to patch queue branch associated to the current\n" - " branch and rebase against current branch.\n" - " drop drop (delete) the patch queue associated to the current branch.\n" - " apply apply a patch\n" - " switch switch to patch-queue branch and vice versa") + usage=usage_msg()) except GbpError as err: gbp.log.err(err) return None @@ -459,7 +463,7 @@ def main(argv): options.upstream_tag) current = repo.get_branch() gbp.log.info("%d patches listed in '%s' imported on '%s'" % - (num, series, current)) + (num, series, current)) elif action == "drop": drop_pq(repo, current) elif action == "rebase": diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 6e7b4ef4..d2f204d9 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -55,6 +55,7 @@ def is_ancestor(repo, parent, child): merge_base = None return merge_base == parent_sha1 + def generate_patches(repo, start, end, outdir, options): """ Generate patch files from git @@ -100,7 +101,7 @@ def generate_patches(repo, start, end, outdir, options): 'gbp-rpm', ('ignore'), ('if', 'ifarch')) - if not 'ignore' in cmds: + if 'ignore' not in cmds: patch_fn = format_patch(outdir, repo, info, patches, options.patch_numbers) if patch_fn: @@ -223,7 +224,7 @@ def safe_patches(queue): if len(queue) > 0: gbp.log.debug("Safeing patches '%s' in '%s'" % - (os.path.dirname(queue[0].path), tmpdir)) + (os.path.dirname(queue[0].path), tmpdir)) for patch in queue: base, _archive_fmt, comp = parse_archive_filename(patch.path) uncompressors = {'gzip': gzip.open, 'bzip2': bz2.BZ2File} @@ -315,7 +316,7 @@ def import_spec_patches(repo, options): if not queue: return gbp.log.info("Trying to apply patches from branch '%s' onto '%s'" % - (base, upstream_commit)) + (base, upstream_commit)) for patch in queue: gbp.log.debug("Applying %s" % patch.path) apply_and_commit_patch(repo, patch, packager) @@ -463,4 +464,3 @@ def main(argv): if __name__ == '__main__': sys.exit(main(sys.argv)) - diff --git a/gbp/scripts/supercommand.py b/gbp/scripts/supercommand.py index 2d0a9f47..e9e03ab2 100644 --- a/gbp/scripts/supercommand.py +++ b/gbp/scripts/supercommand.py @@ -26,7 +26,8 @@ import sys # Command is this module and common/ is shared code # so we don't allow these to be imported: -invalid_modules = [ 'common', 'supercommand' ] +invalid_modules = ['common', 'supercommand'] + def sanitize(cmd): """ @@ -35,6 +36,7 @@ def sanitize(cmd): """ return cmd.replace('-', '_') + def usage(): print(""" Usage: @@ -50,6 +52,7 @@ The most commonly used commands are: Use '--list-cmds' to list all available commands. """) + def version(prog): try: from gbp.version import gbp_version @@ -64,7 +67,7 @@ def import_command(cmd): """ modulename = sanitize(cmd) if (not re.match(r'[a-z][a-z0-9_]', modulename) or - modulename in invalid_modules): + modulename in invalid_modules): raise ImportError('Illegal module name %s' % modulename) return __import__('gbp.scripts.%s' % modulename, fromlist='main', level=0) @@ -75,7 +78,7 @@ def pymod_to_cmd(mod): >>> pymod_to_cmd('/x/y/z/a_cmd.py') 'a-cmd' """ - return os.path.basename(mod.rsplit('.', 1)[0]).replace('_','-') + return os.path.basename(mod.rsplit('.', 1)[0]).replace('_', '-') def get_available_commands(path): @@ -125,10 +128,10 @@ def supercommand(argv=None): elif cmd == 'help': usage() return 0 - elif cmd in [ '--version', 'version' ]: + elif cmd in ['--version', 'version']: version(argv[0]) return 0 - elif cmd in [ '--list-cmds', 'list-cmds' ]: + elif cmd in ['--list-cmds', 'list-cmds']: list_available_commands() return 0 diff --git a/gbp/tristate.py b/gbp/tristate.py index 46300298..d6ff8109 100644 --- a/gbp/tristate.py +++ b/gbp/tristate.py @@ -19,27 +19,28 @@ A switch with three states: on|off|auto """ + class Tristate(object): """Tri-state value: on, off or auto """ - ON = True # state is on == do it + ON = True # state is on == do it OFF = False # state is off == don't do it AUTO = -1 # autodetect == do if possible # We accept true as alias for on and false as alias for off - _VALID_NAMES = [ 'on', 'off', 'true', 'false', 'auto' ] + _VALID_NAMES = ['on', 'off', 'true', 'false', 'auto'] def __init__(self, val): - if type(val) in [ type(t) for t in (True, 1) ]: + if type(val) in [type(t) for t in (True, 1)]: if val > 0: self._state = self.ON elif val < 0: self._state = self.AUTO else: self._state = self.OFF - elif type(val) in [ type(t) for t in ("", u"") ]: - if val.lower() in [ 'on', 'true' ]: + elif type(val) in [type(t) for t in ("", u"")]: + if val.lower() in ['on', 'true']: self._state = self.ON - elif val.lower() in [ 'auto' ]: + elif val.lower() in ['auto']: self._state = self.AUTO else: self._state = self.OFF |