diff options
Diffstat (limited to 'gbp')
39 files changed, 155 insertions, 156 deletions
diff --git a/gbp/bb/__init__.py b/gbp/bb/__init__.py index d6f205b4..60204b7e 100644 --- a/gbp/bb/__init__.py +++ b/gbp/bb/__init__.py @@ -42,8 +42,8 @@ def import_bb(): try: return __import__('bb') except ImportError: - print "ERROR: Unable to find bitbake/lib, try initializing build " \ - "environment with the 'oe-init-build-env' script\n" + print("ERROR: Unable to find bitbake/lib, try initializing build " \ + "environment with the 'oe-init-build-env' script\n") # Return None instead of raising (ImportError) so that building of # this package succeeds in Debian. Otherwise dpkg-buildpackage fails # because of an import error in epydoc. @@ -257,7 +257,7 @@ class BBFile(object): if match and match.group('name') == var: if not self.was_set: self.was_set = True - print "Setting value %s = %s" % (var, val) + print("Setting value %s = %s" % (var, val)) return ['%s = "%s"\n' % (var, val)] else: return [] diff --git a/gbp/config.py b/gbp/config.py index 267400ce..0f0bdc6f 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -17,7 +17,7 @@ """handles command line and config file option parsing for the gbp commands""" from optparse import OptionParser, OptionGroup, Option, OptionValueError -from ConfigParser import SafeConfigParser, NoSectionError +from configparser import SafeConfigParser, NoSectionError from copy import copy import os.path import tempfile @@ -427,11 +427,11 @@ class GbpOptionParser(OptionParser): if parser.has_section(cmd): # Don't use items() until we got rid of the compat sections # since this pulls in the defaults again - self.config.update(dict(parser._sections[cmd].items())) + self.config.update(dict(list(parser._sections[cmd].items()))) for section in self.sections: if parser.has_section(section): - self.config.update(dict(parser._sections[section].items())) + self.config.update(dict(list(parser._sections[section].items()))) else: raise NoSectionError("Mandatory section [%s] does not exist." % section) diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py index 356f74d7..9b3c03bb 100644 --- a/gbp/deb/changelog.py +++ b/gbp/deb/changelog.py @@ -166,7 +166,7 @@ class ChangeLog(object): @return: C{True} if the version has an epoch, C{False} otherwise @rtype: C{bool} """ - return self._cp.has_key('Epoch') + return 'Epoch' in self._cp @property def author(self): @@ -264,11 +264,11 @@ class ChangeLog(object): new_cl = open("debian/changelog.bak", "w") for line in old_cl: if line == " * [[[insert-git-dch-commit-message-here]]]\n": - print >> new_cl, " * " + msg[0] + print(" * " + msg[0], file=new_cl) for line in msg[1:]: - print >> new_cl, " " + line + print(" " + line, file=new_cl) else: - print >> new_cl, line, + print(line, end=' ', file=new_cl) os.rename("debian/changelog.bak", "debian/changelog") def add_entry(self, msg, author=None, email=None, dch_options=[]): diff --git a/gbp/deb/control.py b/gbp/deb/control.py index a4cef2fa..4ac12ccd 100644 --- a/gbp/deb/control.py +++ b/gbp/deb/control.py @@ -50,7 +50,7 @@ class Control(object): with open(filename) as f: control = email.message_from_file(f) - if not control.items(): + if not list(control.items()): raise ParseControlError("Empty or invalid control file or contents") self._control = control diff --git a/gbp/deb/source.py b/gbp/deb/source.py index c7403613..938e5a1b 100644 --- a/gbp/deb/source.py +++ b/gbp/deb/source.py @@ -51,7 +51,7 @@ class DebianSource(object): """ self._changelog = None - if isinstance(vfs, basestring): + if isinstance(vfs, str): self._vfs = FileVfs(vfs) else: self._vfs = vfs diff --git a/gbp/git/args.py b/gbp/git/args.py index f9fc64d6..5a40553a 100644 --- a/gbp/git/args.py +++ b/gbp/git/args.py @@ -55,7 +55,7 @@ class GitArgs(object): Add arguments to argument list """ for arg in args: - if isinstance(arg, basestring): + if isinstance(arg, str): self._args.append(arg) elif isinstance(arg, collections.Iterable): for i in iter(arg): diff --git a/gbp/git/modifier.py b/gbp/git/modifier.py index 2452e0b5..5f5b5999 100644 --- a/gbp/git/modifier.py +++ b/gbp/git/modifier.py @@ -59,7 +59,7 @@ class GitModifier(object): self._date = None tz = GitTz(0) - if isinstance(date, basestring): + if isinstance(date, str): timestamp, offset = date.split() offset_h = int(offset[:-2]) offset_m = int(offset[-2:]) @@ -153,7 +153,7 @@ class GitModifier(object): def items(self): items = [] - for key in self.keys(): + for key in list(self.keys()): val = self.__getitem__(key) if val: items.append((key, val)) diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 6d971c22..42661678 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -39,7 +39,7 @@ class GitRemote(object): def __init__(self, name, fetch_url, push_urls): self._name = name self._fetch_url = fetch_url - if isinstance(push_urls, basestring): + if isinstance(push_urls, str): self._push_urls = [push_urls] else: self._push_urls = [url for url in push_urls] @@ -1392,7 +1392,7 @@ class GitRepository(object): @param verbose: be verbose @type verbose: C{bool} """ - if isinstance(paths, basestring): + if isinstance(paths, str): paths = [ paths ] args = [] if verbose else ['--quiet'] @@ -1594,10 +1594,10 @@ class GitRepository(object): @type committer: C{dict} with keys 'name' and 'email' """ extra_env = {} - for key, val in author.items(): + for key, val in list(author.items()): if val: extra_env['GIT_AUTHOR_%s' % key.upper()] = val - for key, val in committer.items(): + for key, val in list(committer.items()): if val: extra_env['GIT_COMMITTER_%s' % key.upper()] = val @@ -1644,7 +1644,7 @@ class GitRepository(object): args.add(until) args.add_cond(options, options) args.add("--") - if isinstance(paths, basestring): + if isinstance(paths, str): paths = [ paths ] args.add_cond(paths, paths) diff --git a/gbp/git/vfs.py b/gbp/git/vfs.py index 5d5e1323..6f10442a 100644 --- a/gbp/git/vfs.py +++ b/gbp/git/vfs.py @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Make blobs in a git repository accessible as file like objects""" -import StringIO +import io from gbp.git.repository import GitRepositoryError class GitVfs(object): @@ -29,7 +29,7 @@ class GitVfs(object): """ def __init__(self, content): self._iter = iter - self._data = StringIO.StringIO(content) + self._data = io.StringIO(content) def readline(self): return self._data.readline() @@ -26,8 +26,8 @@ import gbp.tristate # Initialize default logger LOGGER = logging.getLogger(__name__) -COLORS = dict([('none', 0)] + zip(['black', 'red', 'green', 'yellow', 'blue', - 'magenta', 'cyan', 'white'], range(30, 38))) +COLORS = dict([('none', 0)] + list(zip(['black', 'red', 'green', 'yellow', 'blue', + 'magenta', 'cyan', 'white'], list(range(30, 38))))) DEFAULT_COLOR_SCHEME = {DEBUG: COLORS['green'], INFO: COLORS['green'], WARNING: COLORS['red'], diff --git a/gbp/patch_series.py b/gbp/patch_series.py index 6ca24f2c..f608f200 100644 --- a/gbp/patch_series.py +++ b/gbp/patch_series.py @@ -130,7 +130,7 @@ class Patch(object): if self.info == None: self._read_info() - if self.info.has_key(key): + if key in self.info: return self.info[key] else: return get_val() if get_val else None diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py index 8162286b..320973d2 100644 --- a/gbp/pkg/__init__.py +++ b/gbp/pkg/__init__.py @@ -86,7 +86,7 @@ def parse_archive_filename(filename): base_name = ".".join(split[:-1]) (archive_fmt, compression) = (split[-1], None) else: - for (c, o) in compressor_opts.iteritems(): + for (c, o) in compressor_opts.items(): if o[1] == split[-1]: base_name = ".".join(split[:-1]) compression = c @@ -187,14 +187,13 @@ class PkgPolicy(object): version_chars = r'[a-zA-Z\d\.\~\-\:\+]' basename = parse_archive_filename(os.path.basename(filename))[0] - version_filters = map ( lambda x: x % version_chars, - ( # Debian upstream tarball: package_'<version>.orig.tar.gz' + version_filters = [x % version_chars for x in ( # Debian upstream tarball: package_'<version>.orig.tar.gz' r'^(?P<package>[a-z\d\.\+\-]+)_(?P<version>%s+)\.orig', # Debian native: 'package_<version>.tar.gz' r'^(?P<package>[a-z\d\.\+\-]+)_(?P<version>%s+)', # Upstream 'package-<version>.tar.gz' # or directory 'package-<version>': - r'^(?P<package>[a-zA-Z\d\.\+\-]+)(-)(?P<version>[0-9]%s*)')) + r'^(?P<package>[a-zA-Z\d\.\+\-]+)(-)(?P<version>[0-9]%s*)')] if extra_regex: version_filters = extra_regex + version_filters @@ -509,7 +508,7 @@ class UpstreamSource(object): @staticmethod def known_compressions(): - return [ args[1][-1] for args in compressor_opts.items() ] + return [ args[1][-1] for args in list(compressor_opts.items()) ] def guess_version(self, extra_regex=r''): return self._pkg_policy.guess_upstream_src_version(self.path, diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 0fe2b4d8..0a376e18 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -17,7 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """provides some rpm source package related helpers""" -import commands +import subprocess import sys import os import re @@ -243,7 +243,7 @@ class SpecFile(object): def sources(self): """Get all source tags as a dict""" sources = {} - for src in self._sources().values(): + for src in list(self._sources().values()): sources[src['num']] = src['linevalue'] return sources @@ -303,7 +303,7 @@ class SpecFile(object): tagvalue = None # We don't support "multivalue" tags like "Provides:" or "SourceX:" # Rpm python doesn't support many of these, thus the explicit list - if type(tagvalue) is int or type(tagvalue) is long: + if type(tagvalue) is int or type(tagvalue) is int: tagvalue = str(tagvalue) elif type(tagvalue) is list or tagname in self._listtags: tagvalue = None @@ -480,7 +480,7 @@ class SpecFile(object): indent_re = re.compile(r'^([a-z]+([0-9]+)?\s*:\s*)', flags=re.I) match = indent_re.match(str(insertafter)) if not match: - match = indent_re.match(str(insertafter.next)) + match = indent_re.match(str(insertafter.__next__)) indent = 12 if not match else len(match.group(1)) text = '%-*s%s\n' % (indent, '%s:' % tagname, value) if key in self._tags: @@ -574,11 +574,11 @@ class SpecFile(object): "which to update" % name) line = self._special_directives[name][0]['line'] gbp.log.debug("Removing content of %s section" % name) - while line.next: - match = self.directive_re.match(str(line.next)) + while line.__next__: + match = self.directive_re.match(str(line.__next__)) if match and match.group('name') in self.section_identifiers: break - self._content.delete(line.next) + self._content.delete(line.__next__) else: gbp.log.debug("Adding %s section to the end of spec file" % name) line = self._content.append('%%%s\n' % name) @@ -598,8 +598,8 @@ class SpecFile(object): text = '' if 'changelog' in self._special_directives: line = self._special_directives['changelog'][0]['line'] - while line.next: - line = line.next + while line.__next__: + line = line.__next__ match = self.directive_re.match(str(line)) if match and match.group('name') in self.section_identifiers: break @@ -613,7 +613,7 @@ class SpecFile(object): macro_prev = None ignored = self.ignorepatches # Remove 'Patch:̈́' tags - for tag in self._patches().values(): + for tag in list(self._patches().values()): if not tag['num'] in ignored: tag_prev = self._delete_tag('patch', tag['num']) # Remove a preceding comment if it seems to originate from GBP @@ -626,7 +626,7 @@ class SpecFile(object): if not macro['id'] in ignored: macro_prev = self._delete_special_macro('patch', macro['id']) # Remove surrounding if-else - macro_next = macro_prev.next + macro_next = macro_prev.__next__ if (str(macro_prev).startswith('%if') and str(macro_next).startswith('%endif')): self._content.delete(macro_next) @@ -694,7 +694,7 @@ class SpecFile(object): macro_line = self._content.insert_after(macro_line, comment_text) macro_line = self._set_special_macro('patch', patchnum, '-p1', macro_line) - for cmd, args in cmds.iteritems(): + for cmd, args in cmds.items(): if cmd in ('if', 'ifarch'): self._content.insert_before(macro_line, '%%%s %s\n' % (cmd, args)) @@ -779,7 +779,7 @@ class SpecFile(object): """ orig = None sources = self.sources() - for num, filename in sorted(sources.iteritems()): + for num, filename in sorted(sources.items()): src = {'num': num, 'filename': os.path.basename(filename), 'uri': filename} src['filename_base'], src['archive_fmt'], src['compression'] = \ @@ -803,9 +803,9 @@ def parse_srpm(srpmfile): """parse srpm by creating a SrcRpmFile object""" try: srcrpm = SrcRpmFile(srpmfile) - except IOError, err: + except IOError as err: raise GbpError("Error reading src.rpm file: %s" % err) - except librpm.error, err: + except librpm.error as err: raise GbpError("RPM error while reading src.rpm: %s" % err) return srcrpm diff --git a/gbp/rpm/linkedlist.py b/gbp/rpm/linkedlist.py index 74d897bc..0840fef6 100644 --- a/gbp/rpm/linkedlist.py +++ b/gbp/rpm/linkedlist.py @@ -63,8 +63,8 @@ class LinkedListNode(object): def delete(self): """Delete node""" if self.prev: - self.prev.next = self.next - if self.next: + self.prev.next = self.__next__ + if self.__next__: self.next.prev = self.prev self._data = None @@ -75,10 +75,10 @@ class LinkedListIterator(collections.Iterator): def __init__(self, obj): self._next = obj.first - def next(self): + def __next__(self): ret = self._next if ret: - self._next = ret.next + self._next = ret.__next__ else: raise StopIteration return ret @@ -171,8 +171,8 @@ class LinkedList(collections.Iterable): >>> [str(data) for data in list] ['foo', 'baz', 'bar'] """ - new = LinkedListNode(data, prev_node=node, next_node=node.next) - if node.next: + new = LinkedListNode(data, prev_node=node, next_node=node.__next__) + if node.__next__: node.next.prev = new else: self._last = new @@ -205,7 +205,7 @@ class LinkedList(collections.Iterable): """ ret = node.prev if node is self._first: - ret = self._first = self._first.next + ret = self._first = self._first.__next__ if node is self._last: self._last = self._last.prev node.delete() diff --git a/gbp/rpm/policy.py b/gbp/rpm/policy.py index 93625545..82e877da 100644 --- a/gbp/rpm/policy.py +++ b/gbp/rpm/policy.py @@ -264,7 +264,7 @@ class RpmPkgPolicy(PkgPolicy): text.extend([" " + line for line in body if line.strip()]) # Add bts tags and ids in the end - for tag, ids in bts_tags.iteritems(): + for tag, ids in bts_tags.items(): bts_msg = " (%s: %s)" % (tag, ', '.join(ids)) if len(text[-1]) + len(bts_msg) >= cls.max_entry_line_length: text.append(" ") diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 43dc261e..5ed16281 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -17,7 +17,7 @@ # """Build a debian package out of a GIT repository""" -import ConfigParser +import configparser import errno import os, os.path import sys @@ -296,7 +296,7 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): if comp_type != 'auto': comp_type = compressor_aliases.get(comp_type, comp_type) - if not compressor_opts.has_key(comp_type): + if comp_type not in compressor_opts: gbp.log.warn("Unknown compression type - guessing.") comp_type = 'auto' @@ -305,7 +305,7 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): if not tarball_dir: tarball_dir = '..' detected = None - for comp in compressor_opts.keys(): + for comp in list(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.") @@ -384,7 +384,7 @@ def changes_file_suffix(dpkg_args): def build_parser(name, prefix=None): try: parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix) - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/buildpackage_bb.py b/gbp/scripts/buildpackage_bb.py index 340724c8..5dd4eda7 100644 --- a/gbp/scripts/buildpackage_bb.py +++ b/gbp/scripts/buildpackage_bb.py @@ -17,7 +17,7 @@ # """Build an RPM package out of a Git repo with Bitbake meta data""" -import ConfigParser +import configparser import os, os.path import sys import shutil @@ -46,7 +46,7 @@ def guess_export_params(repo, options): """Get commit and tree from where to export packaging and patches""" tree = None branch = None - if options.export in wc_names.keys() + [index_name, 'HEAD']: + if options.export in list(wc_names.keys()) + [index_name, 'HEAD']: branch = get_current_branch(repo) elif options.export in repo.get_local_branches(): branch = options.export @@ -112,8 +112,8 @@ def guess_export_dir(options, tinfoil, repo, treeish): gbp.log.debug("Found matching recipe filename: %s" % name) return os.path.dirname(name) else: - for name, appends in tinfoil.cooker.collection.appendlist.iteritems(): - print name, appends + for name, appends in tinfoil.cooker.collection.appendlist.items(): + print(name, appends) if name.rsplit('_', 1)[0] == pkg_name: gbp.log.debug("Found %s from appends" % name) for append_name in appends: @@ -212,7 +212,7 @@ def build_parser(name, prefix=None, git_treeish=None): try: parser = GbpOptionParserBB(command=os.path.basename(name), prefix=prefix, git_treeish=git_treeish) - except ConfigParser.ParsingError, err: + except configparser.ParsingError as err: gbp.log.err(err) return None @@ -507,7 +507,7 @@ def main(argv): if len(err.__str__()): gbp.log.err(err) retval = 2 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 7708dfce..537f96d7 100755 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -18,7 +18,7 @@ # """run commands to build an RPM package out of a git repository""" -import ConfigParser +import configparser import errno import os, os.path import sys @@ -207,7 +207,7 @@ def guess_export_params(repo, options): """Get commit and tree from where to export packaging and patches""" tree = None branch = None - if options.export in wc_names.keys() + [index_name, 'HEAD']: + if options.export in list(wc_names.keys()) + [index_name, 'HEAD']: branch = get_current_branch(repo) elif options.export in repo.get_local_branches(): branch = options.export @@ -390,7 +390,7 @@ def parse_args(argv, prefix, git_treeish=None): try: parser = GbpOptionParserRpm(command=os.path.basename(argv[0]), prefix=prefix, git_treeish=git_treeish) - except ConfigParser.ParsingError, err: + except configparser.ParsingError as err: gbp.log.err(err) return None, None, None @@ -544,7 +544,7 @@ def main(argv): # Create base temporary directory for this run options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='buildpackage-rpm_') - except GbpError, err: + except GbpError as err: gbp.log.err(err) return 1 @@ -697,7 +697,7 @@ def main(argv): if len(err.__str__()): gbp.log.err(err) retval = 2 - 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 2810a310..cdc7317a 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -19,7 +19,7 @@ # """Clone a GIT repository and set it up for gbp""" -import ConfigParser +import configparser import sys import os, os.path from gbp.config import (GbpOptionParser, GbpOptionGroup) @@ -36,7 +36,7 @@ def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] repository - clone a remote repository') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/clone_bb.py b/gbp/scripts/clone_bb.py index 7cc6b9a2..817baa57 100755 --- a/gbp/scripts/clone_bb.py +++ b/gbp/scripts/clone_bb.py @@ -20,7 +20,7 @@ # """Clone a package Git repository from a bitbake-based distro""" -import ConfigParser +import configparser import re import sys import os, os.path @@ -57,7 +57,7 @@ def build_parser(name): parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] repository - clone a ' 'remote per-package repository') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py index 16244423..30df6101 100644 --- a/gbp/scripts/common/import_orig.py +++ b/gbp/scripts/common/import_orig.py @@ -47,7 +47,7 @@ def ask_package_name(default, name_validator_func, err_msg): @param default: The default package name to suggest to the user. """ while True: - sourcepackage = raw_input("What will be the source package name? [%s] " % default) + sourcepackage = input("What will be the source package name? [%s] " % default) if not sourcepackage: # No input, use the default. sourcepackage = default # Valid package name, return it. @@ -66,7 +66,7 @@ def ask_package_version(default, ver_validator_func, err_msg): @param default: The default package version to suggest to the user. """ while True: - version = raw_input("What is the upstream version? [%s] " % default) + version = input("What is the upstream version? [%s] " % default) if not version: # No input, use the default. version = default # Valid version, return it. diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index a91ec8e9..60157b2f 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -180,7 +180,7 @@ def patch_path_filter(file_status, exclude_regex=None): """ if exclude_regex: include_paths = [] - for file_list in file_status.values(): + for file_list in list(file_status.values()): for fname in file_list: if not re.match(exclude_regex, fname): include_paths.append(fname) @@ -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(unicode(name, 'utf-8'), charset, 77, 'from') - from_header.append(unicode('<%s>' % email)) + from_header = Header(str(name, 'utf-8'), charset, 77, 'from') + from_header.append(str('<%s>' % email)) msg['From'] = from_header date = commit_info['author'].datetime datestr = date.strftime('%a, %-d %b %Y %H:%M:%S %z') - msg['Date'] = Header(unicode(datestr, 'utf-8'), charset, 77, 'date') - msg['Subject'] = Header(unicode(commit_info['subject'], 'utf-8'), + msg['Date'] = Header(str(datestr, 'utf-8'), charset, 77, 'date') + msg['Subject'] = Header(str(commit_info['subject'], 'utf-8'), charset, 77, 'subject') # Write message body if commit_info['body']: diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py index 07c731c0..c914e7da 100755 --- a/gbp/scripts/config.py +++ b/gbp/scripts/config.py @@ -17,7 +17,7 @@ # """Query and display config file values""" -import ConfigParser +import configparser import sys import os, os.path from gbp.config import (GbpOptionParser, GbpOptionGroup) @@ -30,7 +30,7 @@ def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] command[.optionname] - display configuration settings') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index a9832a1d..3b5aa764 100755 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -18,10 +18,10 @@ # Based on the aa-create-git-repo and dom-new-git-repo shell scripts """Create a remote GIT repository based on the current one""" -import ConfigParser +import configparser import sys import os, os.path -import urlparse +import urllib.parse import subprocess import tty, termios import re @@ -51,22 +51,22 @@ def print_config(remote, branches): merge = refs/heads/bar """ - print """[remote "%(name)s"] + print("""[remote "%(name)s"] url = %(url)s - fetch = +refs/heads/*:refs/remotes/%(name)s/*""" % remote + fetch = +refs/heads/*:refs/remotes/%(name)s/*""" % remote) for branch in branches: - print " push = %s" % branch + print(" push = %s" % branch) for branch in branches: - print """[branch "%s"] + print("""[branch "%s"] remote = %s - merge = refs/heads/%s""" % (branch, remote['name'], branch) + merge = refs/heads/%s""" % (branch, remote['name'], branch)) def sort_dict(d): """Return a sorted list of (key, value) tuples""" s = [] - for key in sorted(d.iterkeys()): + for key in sorted(d.keys()): s.append((key, d[key])) return s @@ -103,7 +103,7 @@ def parse_url(remote_url, name, pkg, template_dir=None): ... GbpError: URL contains invalid ~username expansion. """ - frags = urlparse.urlparse(remote_url) + frags = urllib.parse.urlparse(remote_url) if frags.scheme in ['ssh', 'git+ssh', '']: scheme = frags.scheme else: @@ -232,7 +232,7 @@ def build_parser(name, sections=[]): usage='%prog [options] - ' 'create a remote repository', sections=sections) - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None @@ -306,7 +306,7 @@ def main(argv): try: options, args = parse_args(argv) except Exception as e: - print >>sys.stderr, "%s" % e + print("%s" % e, file=sys.stderr) return 1 gbp.log.setup(options.color, options.verbose, options.color_scheme) @@ -350,11 +350,11 @@ def main(argv): remote_script = build_remote_script(remote, branches[0]) if options.verbose: - print remote_script + print(remote_script) cmd = build_cmd(remote) if options.verbose: - print cmd + print(cmd) proc = subprocess.Popen(cmd, stdin=subprocess.PIPE) proc.communicate(remote_script) diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index b8a86a77..90d448c6 100755 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -17,7 +17,7 @@ # """Generate Debian changelog entries from GIT commit messages""" -import ConfigParser +import configparser import os.path import re import sys @@ -137,8 +137,8 @@ def mangle_changelog(changelog, cp, snapshot=''): cw = open(tmpfile, 'w') cr = open(changelog, 'r') - print >>cw, ("%(Source)s (%(MangledVersion)s) " - "%(Distribution)s; urgency=%(urgency)s\n" % cp) + print(("%(Source)s (%(MangledVersion)s) " + "%(Distribution)s; urgency=%(urgency)s\n" % cp), file=cw) cr.readline() # skip version and empty line cr.readline() @@ -148,10 +148,10 @@ def mangle_changelog(changelog, cp, snapshot=''): line = '' if snapshot: - print >>cw, " ** SNAPSHOT build @%s **\n" % snapshot + print(" ** SNAPSHOT build @%s **\n" % snapshot, file=cw) if line: - print >>cw, line.rstrip() + print(line.rstrip(), file=cw) shutil.copyfileobj(cr, cw) cw.close() cr.close() @@ -242,7 +242,7 @@ def has_snapshot_banner(cp): def get_customizations(customization_file): if customization_file: - execfile(customization_file, + exec(compile(open(customization_file, "rb").read(), customization_file, 'exec'), user_customizations, user_customizations) @@ -295,7 +295,7 @@ def build_parser(name): try: parser = GbpOptionParserDebian(command=os.path.basename(name), usage='%prog [options] paths') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/import_bb.py b/gbp/scripts/import_bb.py index 5d249776..07417999 100755 --- a/gbp/scripts/import_bb.py +++ b/gbp/scripts/import_bb.py @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Import an RPM package in Bitbake format""" -import ConfigParser +import configparser import sys import os import shutil @@ -57,7 +57,7 @@ def build_parser(name): prefix='', usage='%prog [options] /path/to/package' '.src.rpm') - except ConfigParser.ParsingError, err: + except configparser.ParsingError as err: gbp.log.err(err) return None @@ -256,7 +256,7 @@ def import_upstream_archive(repo, pkg_data, fetch_data, dirs, options): def import_upstream_git(repo, fetch_data, options): """Import upstream sources from Git""" # Fetch from local cached repo - for branch in fetch_data.branches.values(): + for branch in list(fetch_data.branches.values()): repo.fetch(repo=fetch_data.localpath, refspec=branch) commit = fetch_data.revision diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index 41eae8c7..08addabe 100755 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Import a Debian source package into a GIT repository""" -import ConfigParser +import configparser import sys import re import os @@ -209,7 +209,7 @@ def build_parser(name): try: parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', usage='%prog [options] /path/to/package.dsc') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None @@ -416,7 +416,7 @@ def main(argv): os.chdir(dirs['top']) for d in [ 'tmp', 'download' ]: - if dirs.has_key(d): + if d in dirs: gbpc.RemoveTree(dirs[d])() if not ret and not skipped: diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index 5409ca11..c37cea80 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -79,13 +79,13 @@ def set_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] ... + 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: --ignore-repo-config: ignore gbp.conf in git repo -""" +""") def main(argv): @@ -159,7 +159,7 @@ def main(argv): gbp.log.err(err) ret = 1 finally: - if dirs.has_key('tmp'): + if 'tmp' in dirs: gbpc.RemoveTree(dirs['tmp'])() os.chdir(dirs['top']) diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 56b1d9dc..532b3e4a 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -17,7 +17,7 @@ # """Import a new upstream version into a GIT repository""" -import ConfigParser +import configparser import os import sys import gbp.tmpfile as tempfile @@ -146,7 +146,7 @@ def build_parser(name): try: parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/import_orig_rpm.py b/gbp/scripts/import_orig_rpm.py index 4b318a2c..ced92fc7 100755 --- a/gbp/scripts/import_orig_rpm.py +++ b/gbp/scripts/import_orig_rpm.py @@ -18,7 +18,7 @@ # """Import a new upstream version into a git repository""" -import ConfigParser +import configparser import os import sys import gbp.tmpfile as tempfile @@ -152,7 +152,7 @@ def parse_args(argv): parser = GbpOptionParserRpm(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] /path/to/upstream-version.tar.gz') - except ConfigParser.ParsingError, err: + except configparser.ParsingError as err: gbp.log.err(err) return None, None @@ -331,7 +331,7 @@ def main(argv): repo.force_head(current_branch, hard=True) except (GitRepositoryError, gbpc.CommandExecFailed): raise GbpError("Import of %s failed" % source.path) - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index b573f2bc..0712288e 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -17,7 +17,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Import an RPM source package into a GIT repository""" -import ConfigParser +import configparser import sys import re import os @@ -25,7 +25,7 @@ import glob import time import shutil import errno -import urllib2 +import urllib.request, urllib.error, urllib.parse import gbp.tmpfile as tempfile import gbp.command_wrappers as gbpc @@ -68,13 +68,13 @@ def download_file(target_dir, url): """Download a remote file""" gbp.log.info("Downloading '%s'..." % url) try: - urlobj = urllib2.urlopen(url) + urlobj = urllib.request.urlopen(url) local_fn = os.path.join(target_dir, os.path.basename(url)) with open(local_fn, "wb") as local_file: local_file.write(urlobj.read()) - except urllib2.HTTPError as err: + except urllib.error.HTTPError as err: raise GbpError("Download failed: %s" % err) - except urllib2.URLError as err: + except urllib.error.URLError as err: raise GbpError("Download failed: %s" % err.reason) return local_fn @@ -176,7 +176,7 @@ def parse_args(argv): prefix='', usage='%prog [options] /path/to/package' '.src.rpm') - except ConfigParser.ParsingError, err: + except configparser.ParsingError as err: gbp.log.err(err) return None, None @@ -337,7 +337,7 @@ def main(argv): # Need to copy files to the packaging directory given by caller files = [os.path.basename(patch.path) \ for patch in spec.patchseries(unapplied=True, ignored=True)] - for filename in spec.sources().values(): + for filename in list(spec.sources().values()): files.append(os.path.basename(filename)) files.append(os.path.join(spec.specdir, spec.specfile)) # Don't copy orig source archive, though diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index f15753ce..029e7182 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -17,7 +17,7 @@ # """Manage Debian patches on a patch queue branch""" -import ConfigParser +import configparser import errno import os import shutil @@ -119,7 +119,7 @@ def format_series_diff(added, removed, options): bugs, dummy = extract_bts_cmds(patch.long_desc.split('\n'), options) if bugs: msg += '\n' - for k, v in bugs.items(): + for k, v in list(bugs.items()): msg += '\n%s: %s' % (k, ', '.join(v)) else: msg = "Rediff patches\n\n" @@ -326,7 +326,7 @@ def build_parser(name): " 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") - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/pq_bb.py b/gbp/scripts/pq_bb.py index 23e9e896..e1dbae13 100755 --- a/gbp/scripts/pq_bb.py +++ b/gbp/scripts/pq_bb.py @@ -18,7 +18,7 @@ # """manage patches in a patch queue""" -import ConfigParser +import configparser import errno import os import shutil @@ -289,7 +289,7 @@ def build_parser(name): try: parser = GbpOptionParserBB(command=os.path.basename(name), prefix='', usage=USAGE_STRING) - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None @@ -411,7 +411,7 @@ def main(argv): except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 - except GbpError, err: + except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 32ffadee..011c4165 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -18,7 +18,7 @@ # """manage patches in a patch queue""" -import ConfigParser +import configparser import errno import os import shutil @@ -147,7 +147,7 @@ def generate_patches(repo, start, squash, end, outdir, options): "into one monolithic diff" % (start_sha1, merge_sha1)) patches.append(patch_fn) start = merge_sha1 - print start + print(start) # Generate patches for commit in reversed(repo.get_commits(start, end_commit)): @@ -348,14 +348,14 @@ def import_extra_files(repo, commitish, files, patch_ignore=True): if found: gbp.log.info("Importing additional file(s) from branch '%s' into '%s'" % (commitish, repo.get_branch())) - for fname, content in found.iteritems(): + for fname, content in found.items(): dirname = os.path.dirname(fname) if dirname and not os.path.exists(dirname): os.makedirs(dirname) with open(fname, 'w') as fobj: fobj.write(content) - files = found.keys() + files = list(found.keys()) gbp.log.debug('Adding/commiting %s' % files) repo.add_files(files, force=True) commit_msg = ("Auto-import file(s) from branch '%s':\n %s\n" % @@ -363,7 +363,7 @@ def import_extra_files(repo, commitish, files, patch_ignore=True): if patch_ignore: commit_msg += "\nGbp: Ignore\nGbp-Rpm: Ignore" repo.commit_files(files, msg=commit_msg) - return found.keys() + return list(found.keys()) def import_spec_patches(repo, options): """ @@ -618,7 +618,7 @@ def main(argv): try: parser = GbpOptionParserRpm(command=os.path.basename(argv[0]), prefix='', usage=USAGE_STRING) - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err('Invalid config file: %s' % err) return 1 @@ -727,7 +727,7 @@ def main(argv): except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) 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 166955a9..4725a8eb 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -19,7 +19,7 @@ # """Pull remote changes and fast forward debian, upstream and pristine-tar branch""" -import ConfigParser +import configparser import sys import os, os.path from gbp.command_wrappers import (Command, CommandExecFailed) @@ -100,7 +100,7 @@ def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] - safely update a repository from remote') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 33058372..e5fddb4e 100755 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -18,7 +18,7 @@ # """Generate RPM changelog entries from git commit messages""" -import ConfigParser +import configparser from datetime import datetime import os.path import pwd @@ -92,7 +92,7 @@ def load_customizations(customization_file): return customizations = {} try: - execfile(customization_file, customizations, customizations) + exec(compile(open(customization_file, "rb").read(), customization_file, 'exec'), customizations, customizations) except Exception as err: raise GbpError("Failed to load customization file: %s" % err) @@ -134,7 +134,7 @@ def check_repo_state(repo, options): if options.commit: unstaged = [] status = repo.status() - for group, files in status.iteritems(): + for group, files in status.items(): if group != '??' and group[1] != ' ': unstaged.extend(files) if unstaged: @@ -340,7 +340,7 @@ def update_changelog(changelog, entries, repo, spec, options): revision = options.changelog_revision % rev_str_fields except KeyError as err: raise GbpError("Unable to construct revision field: unknown key " - "%s, only %s are accepted" % (err, rev_str_fields.keys())) + "%s, only %s are accepted" % (err, list(rev_str_fields.keys()))) # Add a new changelog section if new release or an empty changelog if options.release or not changelog.sections: @@ -366,7 +366,7 @@ def create_commit_message(spec, options): return options.commit_msg % fields except KeyError as err: raise GbpError("Unknown key %s in commit-msg string, " - "only %s are accepted" % (err, fields.keys())) + "only %s are accepted" % (err, list(fields.keys()))) def commit_changelog(repo, changelog, message, author, committer, edit): """Commit changelog and create a packaging/release tag""" @@ -380,7 +380,7 @@ def parse_args(argv): try: parser = GbpOptionParserRpm(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] paths') - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.error('invalid config file: %s' % err) return None, None diff --git a/gbp/scripts/submit_bb.py b/gbp/scripts/submit_bb.py index b3a9b852..95d29a02 100755 --- a/gbp/scripts/submit_bb.py +++ b/gbp/scripts/submit_bb.py @@ -17,7 +17,7 @@ # """Create and push submit tag""" -import ConfigParser +import configparser import os import sys from datetime import datetime @@ -38,11 +38,11 @@ def guess_remote(repo, options): raise GbpError("Local repo has no remotes configured. Please add one " "or use --remote to define the remote where to push.") elif len(remotes) == 1: - return remotes.keys()[0] + return list(remotes.keys())[0] else: raise GbpError("Local repo has multiple remotes (%s). Don't know which " "one to choose. Use --remote to define where to push." % - ', '.join(remotes.keys())) + ', '.join(list(remotes.keys()))) def build_parser(name): @@ -51,7 +51,7 @@ def build_parser(name): try: parser = GbpOptionParserBB(command=os.path.basename(name), prefix='', usage=usage_str) - except ConfigParser.ParsingError as err: + except configparser.ParsingError as err: gbp.log.err(err) return None diff --git a/gbp/scripts/supercommand.py b/gbp/scripts/supercommand.py index 493554f2..a47c4db8 100644 --- a/gbp/scripts/supercommand.py +++ b/gbp/scripts/supercommand.py @@ -34,7 +34,7 @@ def sanitize(cmd): return cmd.replace('-', '_') def usage(): - print """ + print(""" Usage: gbp <command> [<args>] @@ -46,14 +46,14 @@ The most commonly used commands are: import-dscs - import multiple Debian source packages Use '--list-cmds' to list all available commands. -""" +""") def version(prog): try: 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): @@ -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('') @@ -127,10 +127,10 @@ def supercommand(argv=None): try: module = import_command(cmd) except ImportError as e: - print >>sys.stderr, "'%s' is not a valid command." % cmd + print("'%s' is not a valid command." % cmd, file=sys.stderr) usage() if '--verbose' in args: - print >>sys.stderr, e + print(e, file=sys.stderr) return 2 return module.main(args) diff --git a/gbp/tristate.py b/gbp/tristate.py index 0a800ecd..81cb75c3 100644 --- a/gbp/tristate.py +++ b/gbp/tristate.py @@ -36,7 +36,7 @@ class Tristate(object): self._state = self.AUTO else: self._state = self.OFF - elif type(val) in [ type(t) for t in ("", u"") ]: + elif type(val) in [ type(t) for t in ("", "") ]: if val.lower() in [ 'on', 'true' ]: self._state = self.ON elif val.lower() in [ 'auto' ]: @@ -66,7 +66,7 @@ class Tristate(object): else: return 'off' - def __nonzero__(self): + def __bool__(self): """ >>> Tristate('on').__nonzero__() True |