diff options
Diffstat (limited to 'gbp/scripts')
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 5 | ||||
-rw-r--r-- | gbp/scripts/common/import_orig.py | 6 | ||||
-rw-r--r-- | gbp/scripts/common/pq.py | 26 | ||||
-rw-r--r-- | gbp/scripts/import_dscs.py | 42 | ||||
-rwxr-xr-x | gbp/scripts/import_srpm.py | 2 | ||||
-rwxr-xr-x | gbp/scripts/pq.py | 6 | ||||
-rwxr-xr-x | gbp/scripts/pq_rpm.py | 10 | ||||
-rwxr-xr-x | gbp/scripts/rpm_ch.py | 3 | ||||
-rw-r--r-- | gbp/scripts/supercommand.py | 8 |
9 files changed, 68 insertions, 40 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index a2122866..12eede9e 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -150,8 +150,9 @@ def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): if recursive: paths = '' else: - paths = [nam for _mod, typ, _sha, nam in repo.list_tree(treeish) if - typ == 'blob'] + paths = ["'%s'" % nam.decode() for _mod, typ, _sha, nam in + repo.list_tree(treeish) if typ == 'blob'] + try: data = repo.archive('tar', '', None, treeish, paths) untar_data(export_dir, data) diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 30df6101..55516689 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -26,7 +26,7 @@ import gbp.log # Try to import readline, since that will cause raw_input to get fancy # line editing and history capabilities. However, if readline is not -# available, raw_input will still work. +# available, input() will still work. try: import readline except ImportError: @@ -48,7 +48,7 @@ def ask_package_name(default, name_validator_func, err_msg): """ while True: sourcepackage = input("What will be the source package name? [%s] " % default) - if not sourcepackage: # No input, use the default. + if not sourcepackage: # No input, use the default. sourcepackage = default # Valid package name, return it. if name_validator_func(sourcepackage): @@ -67,7 +67,7 @@ def ask_package_version(default, ver_validator_func, err_msg): """ while True: version = input("What is the upstream version? [%s] " % default) - if not version: # No input, use the default. + if not version: # No input, use the default. version = default # Valid version, return it. if ver_validator_func(version): diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 60157b2f..0ea9f9e8 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -151,7 +151,7 @@ def pq_branch_base(pq_branch, options): def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds): """Parse gbp commands from commit message""" cmd_re = re.compile(r'^%s:\s*(?P<cmd>[a-z-]+)(\s+(?P<args>\S.*))?' % - cmd_tag, flags=re.I) + cmd_tag, flags=re.I) commands = {} other_lines = [] for line in info['body'].splitlines(): @@ -168,7 +168,7 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds): commands[cmd] = match.group('args') else: gbp.log.warn("Ignoring unknown gbp-command '%s' in commit %s" - % (line, info['id'])) + % (line, info['id'])) else: other_lines.append(line) return commands, other_lines @@ -196,7 +196,7 @@ def write_patch_file(filename, commit_info, diff): gbp.log.debug("I won't generate empty diff %s" % filename) return None try: - with open(filename, 'w') as patch: + with open(filename, 'wb') as patch: msg = Message() charset = Charset('utf-8') charset.body_encoding = None @@ -208,13 +208,13 @@ def write_patch_file(filename, commit_info, diff): # Git compat: put name in quotes if special characters found if re.search("[,.@()\[\]\\\:;]", name): name = '"%s"' % name - from_header = Header(str(name, 'utf-8'), charset, 77, 'from') - from_header.append(str('<%s>' % email)) + from_header = Header(name.encode('utf-8'), charset, 77, 'from') + from_header.append(email.encode('utf-8')) msg['From'] = from_header date = commit_info['author'].datetime datestr = date.strftime('%a, %-d %b %Y %H:%M:%S %z') - msg['Date'] = Header(str(datestr, 'utf-8'), charset, 77, 'date') - msg['Subject'] = Header(str(commit_info['subject'], 'utf-8'), + msg['Date'] = Header(datestr.encode('utf-8'), charset, 77, 'date') + msg['Subject'] = Header(commit_info['subject'].encode('utf-8'), charset, 77, 'subject') # Write message body if commit_info['body']: @@ -224,11 +224,11 @@ def write_patch_file(filename, commit_info, diff): msg.set_payload(body.encode('ascii')) except UnicodeDecodeError: msg.set_payload(body, charset) - patch.write(msg.as_string(unixfrom=False)) + patch.write(msg.as_string(unixfrom=False).encode('utf-8')) # Write diff - patch.write('---\n') - patch.write(diff) + patch.write(b'---\n') + patch.write(diff.encode()) except IOError as err: raise GbpError('Unable to create patch file: %s' % err) return filename @@ -278,7 +278,7 @@ def format_diff(outdir, filename, repo, start, end, path_exclude_regex=None): info['subject'] = "Raw diff %s..%s" % (start, end) info['body'] = ("Raw diff between %s '%s' and\n%s '%s'\n" % (repo.get_obj_type(start), start, - repo.get_obj_type(end), end)) + repo.get_obj_type(end), end)) if not filename: filename = '%s-to-%s.diff' % (start, end) filename = os.path.join(outdir, filename) @@ -323,7 +323,7 @@ def get_maintainer_from_control(repo): stdout=subprocess.PIPE).stdout.readlines() if len(cmdout) > 0: - maintainer = cmdout[0].strip() + maintainer = cmdout[0].decode().strip() m = re.match('(?P<name>.*[^ ]) *<(?P<email>.*)>', maintainer) if m: return GitModifier(m.group('name'), m.group('email')) @@ -361,7 +361,7 @@ def apply_and_commit_patch(repo, patch, fallback_author, topic=None): """apply a single patch 'patch', add topic 'topic' and commit it""" author = {'name': patch.author, 'email': patch.email, - 'date': patch.date } + 'date': patch.date} patch_fn = os.path.basename(patch.path) if not (author['name'] and author['email']): diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index c37cea80..7ed5e70f 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -1,6 +1,6 @@ # vim: set fileencoding=utf-8 : # -# (C) 2008, 2009, 2010 Guido Guenther <agx@sigxcpu.org> +# (C) 2008, 2009, 2010, 2017 Guido Günther <agx@sigxcpu.org> # 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 # the Free Software Foundation; either version 2 of the License, or @@ -12,9 +12,9 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -"""Import multiple dsc files into GIT in one go""" +# along with this program; if not, please see +# <http://www.gnu.org/licenses/> +"""Import multiple dsc files into Git in one go""" import glob import os @@ -37,6 +37,32 @@ class DscCompareVersions(DpkgCompareVersions): return DpkgCompareVersions.__call__(self, dsc1.version, dsc2.version) +def cmp_to_key(mycmp): + 'Convert a cmp= function into a key= function' + class K(object): + def __init__(self, obj, *args): + self.obj = obj + + def __lt__(self, other): + return mycmp(self.obj, other.obj) < 0 + + def __gt__(self, other): + return mycmp(self.obj, other.obj) > 0 + + def __eq__(self, other): + return mycmp(self.obj, other.obj) == 0 + + def __le__(self, other): + return mycmp(self.obj, other.obj) <= 0 + + def __ge__(self, other): + return mycmp(self.obj, other.obj) >= 0 + + def __ne__(self, other): + return mycmp(self.obj, other.obj) != 0 + return K + + class GitImportDsc(object): def __init__(self, args): self.args = args @@ -46,7 +72,7 @@ class GitImportDsc(object): def fetch_snapshots(pkg, downloaddir): - "Fetch snapshots using debsnap von snapshots.debian.org" + "Fetch snapshots using debsnap from snapshots.debian.org" dscs = None gbp.log.info("Downloading snapshots of '%s' to '%s'..." % @@ -93,7 +119,7 @@ def main(argv): dscs = [] ret = 0 verbose = False - dsc_cmp = DscCompareVersions() + dsc_key = cmp_to_key(DscCompareVersions()) use_debsnap = False try: @@ -128,9 +154,9 @@ 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) + dscs.sort(key=dsc_key) importer = GitImportDsc(import_args) try: diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index 0712288e..88ca4819 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -81,7 +81,7 @@ def download_file(target_dir, url): def download_source(pkg, dirs): """Download package from a remote location""" if re.match(r'[a-z]{1,5}://', pkg): - mode = 'python urllib2' + mode = 'python urllib' else: mode = 'yumdownloader' diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 029e7182..4430d5fa 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -167,9 +167,9 @@ def export_patches(repo, branch, options): pq_branch = pq_branch_name(branch, options) try: shutil.rmtree(PATCH_DIR) - except OSError as msg: - if msg.errno != errno.ENOENT: - raise GbpError("Failed to remove patch dir: %s" % msg) + except OSError as e: + if e.errno != errno.ENOENT: + raise GbpError("Failed to remove patch dir: %s" % e.strerror) else: gbp.log.debug("%s does not exist." % PATCH_DIR) diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 011c4165..92954eec 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -292,8 +292,8 @@ def safe_patches(queue, tmpdir_base): safequeue = PatchSeries() if len(queue) > 0: - gbp.log.debug("Safeing patches '%s' in '%s'" % - (os.path.dirname(queue[0].path), tmpdir)) + gbp.log.debug("Saving patches '%s' in '%s'" % + (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} @@ -308,11 +308,11 @@ def safe_patches(queue, tmpdir_base): raise GbpError("Unsupported patch compression '%s', giving up" % comp) else: - src = open(patch.path, 'r') + src = open(patch.path, 'rb') dst_name = os.path.join(tmpdir, os.path.basename(patch.path)) - dst = open(dst_name, 'w') - dst.writelines(src) + dst = open(dst_name, 'wb') + dst.write(src.read()) src.close() dst.close() if _archive_fmt: diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index e5fddb4e..b2a836aa 100755 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -92,7 +92,8 @@ def load_customizations(customization_file): return customizations = {} try: - exec(compile(open(customization_file, "rb").read(), customization_file, 'exec'), customizations, customizations) + with open(customization_file) as f: + exec(f.read(), customizations, customizations) except Exception as err: raise GbpError("Failed to load customization file: %s" % err) diff --git a/gbp/scripts/supercommand.py b/gbp/scripts/supercommand.py index 7a91625b..7e35877a 100644 --- a/gbp/scripts/supercommand.py +++ b/gbp/scripts/supercommand.py @@ -53,7 +53,7 @@ def version(prog): from gbp.version import gbp_version except ImportError: gbp_version = '[Unknown version]' - print(("%s %s" % (os.path.basename(prog), gbp_version))) + print("%s %s" % (os.path.basename(prog), gbp_version)) def import_command(cmd): @@ -62,7 +62,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) @@ -90,7 +90,7 @@ def list_available_commands(): path = os.path.dirname(mod.__file__) maxlen = 0 - print(("Available commands in %s\n" % path)) + print("Available commands in %s\n" % path) cmds = sorted(get_available_commands(path)) for cmd in cmds: if len(cmd[0]) > maxlen: @@ -98,7 +98,7 @@ def list_available_commands(): for cmd in cmds: mod = import_command(cmd[0]) doc = mod.__doc__ - print((" %s - %s" % (cmd[0].rjust(maxlen), doc))) + print(" %s - %s" % (cmd[0].rjust(maxlen), doc)) print('') |