style: Format Python code with black

```
PYTHON_SCRIPTS=$(grep -l -r '^#! */usr/bin/python3$' .)
black -C -l 99 . $PYTHON_SCRIPTS
```

Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
This commit is contained in:
Benjamin Drung 2023-01-30 19:45:36 +01:00
parent 79d24c9df1
commit 3354b526b5
64 changed files with 3920 additions and 3012 deletions

View File

@ -34,18 +34,20 @@ except ImportError:
from httplib2 import Http, HttpLib2Error from httplib2 import Http, HttpLib2Error
from distro_info import DebianDistroInfo, UbuntuDistroInfo from distro_info import DebianDistroInfo, UbuntuDistroInfo
from ubuntutools.archive import (DebianSourcePackage, from ubuntutools.archive import DebianSourcePackage, UbuntuSourcePackage, DownloadError
UbuntuSourcePackage, DownloadError)
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.builder import get_builder from ubuntutools.builder import get_builder
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, from ubuntutools.lp.lpapicache import (
SeriesNotFoundException, Launchpad,
PackageNotFoundException) Distribution,
from ubuntutools.misc import (system_distribution, vendor_to_distroinfo, SeriesNotFoundException,
codename_to_distribution) PackageNotFoundException,
)
from ubuntutools.misc import system_distribution, vendor_to_distroinfo, codename_to_distribution
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -55,130 +57,152 @@ def error(msg):
def check_call(cmd, *args, **kwargs): def check_call(cmd, *args, **kwargs):
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
ret = subprocess.call(cmd, *args, **kwargs) ret = subprocess.call(cmd, *args, **kwargs)
if ret != 0: if ret != 0:
error('%s returned %d.' % (cmd[0], ret)) error("%s returned %d." % (cmd[0], ret))
def parse(args): def parse(args):
usage = 'Usage: %prog [options] <source package name or .dsc URL/file>' usage = "Usage: %prog [options] <source package name or .dsc URL/file>"
parser = optparse.OptionParser(usage) parser = optparse.OptionParser(usage)
parser.add_option('-d', '--destination', parser.add_option(
metavar='DEST', "-d",
dest='dest_releases', "--destination",
default=[], metavar="DEST",
action='append', dest="dest_releases",
help='Backport to DEST release ' default=[],
'(default: current release)') action="append",
parser.add_option('-s', '--source', help="Backport to DEST release (default: current release)",
metavar='SOURCE', )
dest='source_release', parser.add_option(
help='Backport from SOURCE release ' "-s",
'(default: devel release)') "--source",
parser.add_option('-S', '--suffix', metavar="SOURCE",
metavar='SUFFIX', dest="source_release",
help='Suffix to append to version number ' help="Backport from SOURCE release (default: devel release)",
'(default: ~ppa1 when uploading to a PPA)') )
parser.add_option('-e', '--message', parser.add_option(
metavar='MESSAGE', "-S",
default="No-change", "--suffix",
help='Changelog message to use instead of "No-change" ' metavar="SUFFIX",
'(default: No-change backport to DEST.)') help="Suffix to append to version number (default: ~ppa1 when uploading to a PPA)",
parser.add_option('-b', '--build', )
default=False, parser.add_option(
action='store_true', "-e",
help='Build the package before uploading ' "--message",
'(default: %default)') metavar="MESSAGE",
parser.add_option('-B', '--builder', default="No-change",
metavar='BUILDER', help='Changelog message to use instead of "No-change" '
help='Specify the package builder (default: pbuilder)') "(default: No-change backport to DEST.)",
parser.add_option('-U', '--update', )
default=False, parser.add_option(
action='store_true', "-b",
help='Update the build environment before ' "--build",
'attempting to build') default=False,
parser.add_option('-u', '--upload', action="store_true",
metavar='UPLOAD', help="Build the package before uploading (default: %default)",
help='Specify an upload destination') )
parser.add_option("-k", "--key", parser.add_option(
dest='keyid', "-B",
help="Specify the key ID to be used for signing.") "--builder",
parser.add_option('--dont-sign', metavar="BUILDER",
dest='keyid', action='store_false', help="Specify the package builder (default: pbuilder)",
help='Do not sign the upload.') )
parser.add_option('-y', '--yes', parser.add_option(
dest='prompt', "-U",
default=True, "--update",
action='store_false', default=False,
help='Do not prompt before uploading to a PPA') action="store_true",
parser.add_option('-v', '--version', help="Update the build environment before attempting to build",
metavar='VERSION', )
help='Package version to backport (or verify)') parser.add_option("-u", "--upload", metavar="UPLOAD", help="Specify an upload destination")
parser.add_option('-w', '--workdir', parser.add_option(
metavar='WORKDIR', "-k", "--key", dest="keyid", help="Specify the key ID to be used for signing."
help='Specify a working directory ' )
'(default: temporary dir)') parser.add_option(
parser.add_option('-r', '--release-pocket', "--dont-sign", dest="keyid", action="store_false", help="Do not sign the upload."
default=False, )
action='store_true', parser.add_option(
help='Target the release pocket in the .changes file. ' "-y",
'Necessary (and default) for uploads to PPAs') "--yes",
parser.add_option('-c', '--close', dest="prompt",
metavar='BUG', default=True,
help='Bug to close in the changelog entry.') action="store_false",
parser.add_option('-m', '--mirror', help="Do not prompt before uploading to a PPA",
metavar='URL', )
help='Preferred mirror (default: Launchpad)') parser.add_option(
parser.add_option('-l', '--lpinstance', "-v", "--version", metavar="VERSION", help="Package version to backport (or verify)"
metavar='INSTANCE', )
help='Launchpad instance to connect to ' parser.add_option(
'(default: production)') "-w",
parser.add_option('--no-conf', "--workdir",
default=False, metavar="WORKDIR",
action='store_true', help="Specify a working directory (default: temporary dir)",
help="Don't read config files or environment variables") )
parser.add_option(
"-r",
"--release-pocket",
default=False,
action="store_true",
help="Target the release pocket in the .changes file. "
"Necessary (and default) for uploads to PPAs",
)
parser.add_option("-c", "--close", metavar="BUG", help="Bug to close in the changelog entry.")
parser.add_option(
"-m", "--mirror", metavar="URL", help="Preferred mirror (default: Launchpad)"
)
parser.add_option(
"-l",
"--lpinstance",
metavar="INSTANCE",
help="Launchpad instance to connect to (default: production)",
)
parser.add_option(
"--no-conf",
default=False,
action="store_true",
help="Don't read config files or environment variables",
)
opts, args = parser.parse_args(args) opts, args = parser.parse_args(args)
if len(args) != 1: if len(args) != 1:
parser.error('You must specify a single source package or a .dsc ' parser.error("You must specify a single source package or a .dsc URL/path.")
'URL/path.')
config = UDTConfig(opts.no_conf) config = UDTConfig(opts.no_conf)
if opts.builder is None: if opts.builder is None:
opts.builder = config.get_value('BUILDER') opts.builder = config.get_value("BUILDER")
if not opts.update: if not opts.update:
opts.update = config.get_value('UPDATE_BUILDER', boolean=True) opts.update = config.get_value("UPDATE_BUILDER", boolean=True)
if opts.workdir is None: if opts.workdir is None:
opts.workdir = config.get_value('WORKDIR') opts.workdir = config.get_value("WORKDIR")
if opts.lpinstance is None: if opts.lpinstance is None:
opts.lpinstance = config.get_value('LPINSTANCE') opts.lpinstance = config.get_value("LPINSTANCE")
if opts.upload is None: if opts.upload is None:
opts.upload = config.get_value('UPLOAD') opts.upload = config.get_value("UPLOAD")
if opts.keyid is None: if opts.keyid is None:
opts.keyid = config.get_value('KEYID') opts.keyid = config.get_value("KEYID")
if not opts.upload and not opts.workdir: if not opts.upload and not opts.workdir:
parser.error('Please specify either a working dir or an upload target!') parser.error("Please specify either a working dir or an upload target!")
if opts.upload and opts.upload.startswith('ppa:'): if opts.upload and opts.upload.startswith("ppa:"):
opts.release_pocket = True opts.release_pocket = True
return opts, args, config return opts, args, config
def find_release_package(mirror, workdir, package, version, source_release, def find_release_package(mirror, workdir, package, version, source_release, config):
config):
srcpkg = None srcpkg = None
if source_release: if source_release:
distribution = codename_to_distribution(source_release) distribution = codename_to_distribution(source_release)
if not distribution: if not distribution:
error('Unknown release codename %s' % source_release) error("Unknown release codename %s" % source_release)
info = vendor_to_distroinfo(distribution)() info = vendor_to_distroinfo(distribution)()
source_release = info.codename(source_release, default=source_release) source_release = info.codename(source_release, default=source_release)
else: else:
distribution = system_distribution() distribution = system_distribution()
mirrors = [mirror] if mirror else [] mirrors = [mirror] if mirror else []
mirrors.append(config.get_value('%s_MIRROR' % distribution.upper())) mirrors.append(config.get_value("%s_MIRROR" % distribution.upper()))
if not version: if not version:
archive = Distribution(distribution.lower()).getArchive() archive = Distribution(distribution.lower()).getArchive()
@ -188,39 +212,35 @@ def find_release_package(mirror, workdir, package, version, source_release,
error(str(e)) error(str(e))
version = spph.getVersion() version = spph.getVersion()
if distribution == 'Debian': if distribution == "Debian":
srcpkg = DebianSourcePackage(package, srcpkg = DebianSourcePackage(package, version, workdir=workdir, mirrors=mirrors)
version, elif distribution == "Ubuntu":
workdir=workdir, srcpkg = UbuntuSourcePackage(package, version, workdir=workdir, mirrors=mirrors)
mirrors=mirrors)
elif distribution == 'Ubuntu':
srcpkg = UbuntuSourcePackage(package,
version,
workdir=workdir,
mirrors=mirrors)
return srcpkg return srcpkg
def find_package(mirror, workdir, package, version, source_release, config): def find_package(mirror, workdir, package, version, source_release, config):
"Returns the SourcePackage" "Returns the SourcePackage"
if package.endswith('.dsc'): if package.endswith(".dsc"):
# Here we are using UbuntuSourcePackage just because we don't have any # Here we are using UbuntuSourcePackage just because we don't have any
# "general" class that is safely instantiable (as SourcePackage is an # "general" class that is safely instantiable (as SourcePackage is an
# abstract class). None of the distribution-specific details within # abstract class). None of the distribution-specific details within
# UbuntuSourcePackage is relevant for this use case. # UbuntuSourcePackage is relevant for this use case.
return UbuntuSourcePackage(version=version, dscfile=package, return UbuntuSourcePackage(
workdir=workdir, mirrors=(mirror,)) version=version, dscfile=package, workdir=workdir, mirrors=(mirror,)
)
if not source_release and not version: if not source_release and not version:
info = vendor_to_distroinfo(system_distribution()) info = vendor_to_distroinfo(system_distribution())
source_release = info().devel() source_release = info().devel()
srcpkg = find_release_package(mirror, workdir, package, version, srcpkg = find_release_package(mirror, workdir, package, version, source_release, config)
source_release, config)
if version and srcpkg.version != version: if version and srcpkg.version != version:
error('Requested backport of version %s but version of %s in %s is %s' error(
% (version, package, source_release, srcpkg.version)) "Requested backport of version %s but version of %s in %s is %s"
% (version, package, source_release, srcpkg.version)
)
return srcpkg return srcpkg
@ -228,30 +248,27 @@ def find_package(mirror, workdir, package, version, source_release, config):
def get_backport_version(version, suffix, upload, release): def get_backport_version(version, suffix, upload, release):
distribution = codename_to_distribution(release) distribution = codename_to_distribution(release)
if not distribution: if not distribution:
error('Unknown release codename %s' % release) error("Unknown release codename %s" % release)
if distribution == 'Debian': if distribution == "Debian":
debian_distro_info = DebianDistroInfo() debian_distro_info = DebianDistroInfo()
debian_codenames = debian_distro_info.supported() debian_codenames = debian_distro_info.supported()
if release in debian_codenames: if release in debian_codenames:
release_version = debian_distro_info.version(release) release_version = debian_distro_info.version(release)
if not release_version: if not release_version:
error(f"Can't find the release version for {release}") error(f"Can't find the release version for {release}")
backport_version = "{}~bpo{}+1".format( backport_version = "{}~bpo{}+1".format(version, release_version)
version, release_version
)
else: else:
error(f"{release} is not a supported release ({debian_codenames})") error(f"{release} is not a supported release ({debian_codenames})")
elif distribution == 'Ubuntu': elif distribution == "Ubuntu":
series = Distribution(distribution.lower()).\ series = Distribution(distribution.lower()).getSeries(name_or_version=release)
getSeries(name_or_version=release)
backport_version = version + ('~bpo%s.1' % (series.version)) backport_version = version + ("~bpo%s.1" % (series.version))
else: else:
error('Unknown distribution «%s» for release «%s»' % (distribution, release)) error("Unknown distribution «%s» for release «%s»" % (distribution, release))
if suffix is not None: if suffix is not None:
backport_version += suffix backport_version += suffix
elif upload and upload.startswith('ppa:'): elif upload and upload.startswith("ppa:"):
backport_version += '~ppa1' backport_version += "~ppa1"
return backport_version return backport_version
@ -259,10 +276,9 @@ def get_old_version(source, release):
try: try:
distribution = codename_to_distribution(release) distribution = codename_to_distribution(release)
archive = Distribution(distribution.lower()).getArchive() archive = Distribution(distribution.lower()).getArchive()
pkg = archive.getSourcePackage(source, pkg = archive.getSourcePackage(
release, source, release, ("Release", "Security", "Updates", "Proposed", "Backports")
('Release', 'Security', 'Updates', )
'Proposed', 'Backports'))
return pkg.getVersion() return pkg.getVersion()
except (SeriesNotFoundException, PackageNotFoundException): except (SeriesNotFoundException, PackageNotFoundException):
pass pass
@ -272,7 +288,7 @@ def get_backport_dist(release, release_pocket):
if release_pocket: if release_pocket:
return release return release
else: else:
return '%s-backports' % release return "%s-backports" % release
def do_build(workdir, dsc, release, builder, update): def do_build(workdir, dsc, release, builder, update):
@ -286,41 +302,43 @@ def do_build(workdir, dsc, release, builder, update):
# builder.build is going to chdir to buildresult: # builder.build is going to chdir to buildresult:
workdir = os.path.realpath(workdir) workdir = os.path.realpath(workdir)
return builder.build(os.path.join(workdir, dsc), return builder.build(os.path.join(workdir, dsc), release, os.path.join(workdir, "buildresult"))
release,
os.path.join(workdir, "buildresult"))
def do_upload(workdir, package, bp_version, changes, upload, prompt): def do_upload(workdir, package, bp_version, changes, upload, prompt):
print('Please check %s %s in file://%s carefully!' % (package, bp_version, workdir)) print("Please check %s %s in file://%s carefully!" % (package, bp_version, workdir))
if prompt or upload == 'ubuntu': if prompt or upload == "ubuntu":
question = 'Do you want to upload the package to %s' % upload question = "Do you want to upload the package to %s" % upload
answer = YesNoQuestion().ask(question, "yes") answer = YesNoQuestion().ask(question, "yes")
if answer == "no": if answer == "no":
return return
check_call(['dput', upload, changes], cwd=workdir) check_call(["dput", upload, changes], cwd=workdir)
def orig_needed(upload, workdir, pkg): def orig_needed(upload, workdir, pkg):
'''Avoid a -sa if possible''' """Avoid a -sa if possible"""
if not upload or not upload.startswith('ppa:'): if not upload or not upload.startswith("ppa:"):
return True return True
ppa = upload.split(':', 1)[1] ppa = upload.split(":", 1)[1]
user, ppa = ppa.split('/', 1) user, ppa = ppa.split("/", 1)
version = pkg.version.upstream_version version = pkg.version.upstream_version
h = Http() h = Http()
for filename in glob.glob(os.path.join(workdir, '%s_%s.orig*' % (pkg.source, version))): for filename in glob.glob(os.path.join(workdir, "%s_%s.orig*" % (pkg.source, version))):
url = ('https://launchpad.net/~%s/+archive/%s/+sourcefiles/%s/%s/%s' url = "https://launchpad.net/~%s/+archive/%s/+sourcefiles/%s/%s/%s" % (
% (quote(user), quote(ppa), quote(pkg.source), quote(user),
quote(pkg.version.full_version), quote(ppa),
quote(os.path.basename(filename)))) quote(pkg.source),
quote(pkg.version.full_version),
quote(os.path.basename(filename)),
)
try: try:
headers, body = h.request(url, 'HEAD') headers, body = h.request(url, "HEAD")
if (headers.status != 200 or if headers.status != 200 or not headers["content-location"].startswith(
not headers['content-location'].startswith('https://launchpadlibrarian.net')): "https://launchpadlibrarian.net"
):
return True return True
except HttpLib2Error as e: except HttpLib2Error as e:
Logger.debug(e) Logger.debug(e)
@ -328,61 +346,79 @@ def orig_needed(upload, workdir, pkg):
return False return False
def do_backport(workdir, pkg, suffix, message, close, release, release_pocket, def do_backport(
build, builder, update, upload, keyid, prompt): workdir,
dirname = '%s-%s' % (pkg.source, release) pkg,
suffix,
message,
close,
release,
release_pocket,
build,
builder,
update,
upload,
keyid,
prompt,
):
dirname = "%s-%s" % (pkg.source, release)
srcdir = os.path.join(workdir, dirname) srcdir = os.path.join(workdir, dirname)
if os.path.exists(srcdir): if os.path.exists(srcdir):
question = 'Working directory %s already exists. Delete it?' % srcdir question = "Working directory %s already exists. Delete it?" % srcdir
if YesNoQuestion().ask(question, 'no') == 'no': if YesNoQuestion().ask(question, "no") == "no":
sys.exit(1) sys.exit(1)
shutil.rmtree(srcdir) shutil.rmtree(srcdir)
pkg.unpack(dirname) pkg.unpack(dirname)
bp_version = get_backport_version(pkg.version.full_version, suffix, bp_version = get_backport_version(pkg.version.full_version, suffix, upload, release)
upload, release)
old_version = get_old_version(pkg.source, release) old_version = get_old_version(pkg.source, release)
bp_dist = get_backport_dist(release, release_pocket) bp_dist = get_backport_dist(release, release_pocket)
changelog = '%s backport to %s.' % (message, release,) changelog = "%s backport to %s." % (message, release)
if close: if close:
changelog += ' (LP: #%s)' % (close,) changelog += " (LP: #%s)" % (close,)
check_call(['dch', check_call(
'--force-bad-version', [
'--force-distribution', "dch",
'--preserve', "--force-bad-version",
'--newversion', bp_version, "--force-distribution",
'--distribution', bp_dist, "--preserve",
changelog], "--newversion",
cwd=srcdir) bp_version,
"--distribution",
bp_dist,
changelog,
],
cwd=srcdir,
)
cmd = ['debuild', '--no-lintian', '-S', '-nc', '-uc', '-us'] cmd = ["debuild", "--no-lintian", "-S", "-nc", "-uc", "-us"]
if orig_needed(upload, workdir, pkg): if orig_needed(upload, workdir, pkg):
cmd.append('-sa') cmd.append("-sa")
else: else:
cmd.append('-sd') cmd.append("-sd")
if old_version: if old_version:
cmd.append('-v%s' % old_version) cmd.append("-v%s" % old_version)
env = os.environ.copy() env = os.environ.copy()
# An ubuntu.com e-mail address would make dpkg-buildpackage fail if there # An ubuntu.com e-mail address would make dpkg-buildpackage fail if there
# wasn't an Ubuntu maintainer for an ubuntu-versioned package. LP: #1007042 # wasn't an Ubuntu maintainer for an ubuntu-versioned package. LP: #1007042
env.pop('DEBEMAIL', None) env.pop("DEBEMAIL", None)
check_call(cmd, cwd=srcdir, env=env) check_call(cmd, cwd=srcdir, env=env)
fn_base = pkg.source + '_' + bp_version.split(':', 1)[-1] fn_base = pkg.source + "_" + bp_version.split(":", 1)[-1]
changes = fn_base + '_source.changes' changes = fn_base + "_source.changes"
if build: if build:
if 0 != do_build(workdir, fn_base + '.dsc', release, builder, update): if 0 != do_build(workdir, fn_base + ".dsc", release, builder, update):
sys.exit(1) sys.exit(1)
# None: sign with the default signature. False: don't sign # None: sign with the default signature. False: don't sign
if keyid is not False: if keyid is not False:
cmd = ['debsign'] cmd = ["debsign"]
if keyid: if keyid:
cmd.append('-k' + keyid) cmd.append("-k" + keyid)
cmd.append(changes) cmd.append(changes)
check_call(cmd, cwd=workdir) check_call(cmd, cwd=workdir)
if upload: if upload:
@ -402,13 +438,13 @@ def main(args):
if lsb_release: if lsb_release:
distinfo = lsb_release.get_distro_information() distinfo = lsb_release.get_distro_information()
try: try:
current_distro = distinfo['ID'] current_distro = distinfo["ID"]
except KeyError: except KeyError:
error('No destination release specified and unable to guess yours.') error("No destination release specified and unable to guess yours.")
else: else:
err, current_distro = subprocess.getstatusoutput('lsb_release --id --short') err, current_distro = subprocess.getstatusoutput("lsb_release --id --short")
if err: if err:
error('Could not run lsb_release to retrieve distribution') error("Could not run lsb_release to retrieve distribution")
if current_distro == "Ubuntu": if current_distro == "Ubuntu":
opts.dest_releases = [UbuntuDistroInfo().lts()] opts.dest_releases = [UbuntuDistroInfo().lts()]
@ -420,34 +456,33 @@ def main(args):
if opts.workdir: if opts.workdir:
workdir = os.path.expanduser(opts.workdir) workdir = os.path.expanduser(opts.workdir)
else: else:
workdir = tempfile.mkdtemp(prefix='backportpackage-') workdir = tempfile.mkdtemp(prefix="backportpackage-")
if not os.path.exists(workdir): if not os.path.exists(workdir):
os.makedirs(workdir) os.makedirs(workdir)
try: try:
pkg = find_package(opts.mirror, pkg = find_package(
workdir, opts.mirror, workdir, package_or_dsc, opts.version, opts.source_release, config
package_or_dsc, )
opts.version,
opts.source_release,
config)
pkg.pull() pkg.pull()
for release in opts.dest_releases: for release in opts.dest_releases:
do_backport(workdir, do_backport(
pkg, workdir,
opts.suffix, pkg,
opts.message, opts.suffix,
opts.close, opts.message,
release, opts.close,
opts.release_pocket, release,
opts.build, opts.release_pocket,
opts.builder, opts.build,
opts.update, opts.builder,
opts.upload, opts.update,
opts.keyid, opts.upload,
opts.prompt) opts.keyid,
opts.prompt,
)
except DownloadError as e: except DownloadError as e:
error(str(e)) error(str(e))
finally: finally:
@ -455,5 +490,5 @@ def main(args):
shutil.rmtree(workdir) shutil.rmtree(workdir)
if __name__ == '__main__': if __name__ == "__main__":
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

View File

@ -30,6 +30,7 @@ from launchpadlib.errors import HTTPError
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -46,21 +47,28 @@ def save_entry(entry):
def tag_bug(bug): def tag_bug(bug):
bug.tags = bug.tags + ['bitesize'] # LP: #254901 workaround bug.tags = bug.tags + ["bitesize"] # LP: #254901 workaround
save_entry(bug) save_entry(bug)
def main(): def main():
usage = "Usage: %prog <bug number>" usage = "Usage: %prog <bug number>"
opt_parser = OptionParser(usage) opt_parser = OptionParser(usage)
opt_parser.add_option("-l", "--lpinstance", metavar="INSTANCE", opt_parser.add_option(
help="Launchpad instance to connect to " "-l",
"(default: production)", "--lpinstance",
dest="lpinstance", default=None) metavar="INSTANCE",
opt_parser.add_option("--no-conf", help="Launchpad instance to connect to (default: production)",
help="Don't read config files or " dest="lpinstance",
"environment variables.", default=None,
dest="no_conf", default=False, action="store_true") )
opt_parser.add_option(
"--no-conf",
help="Don't read config files or environment variables.",
dest="no_conf",
default=False,
action="store_true",
)
(options, args) = opt_parser.parse_args() (options, args) = opt_parser.parse_args()
config = UDTConfig(options.no_conf) config = UDTConfig(options.no_conf)
if options.lpinstance is None: if options.lpinstance is None:
@ -77,19 +85,22 @@ def main():
bug = launchpad.bugs[args[0]] bug = launchpad.bugs[args[0]]
except HTTPError as error: except HTTPError as error:
if error.response.status == 401: if error.response.status == 401:
error_out("Don't have enough permissions to access bug %s. %s" % error_out(
(args[0], error.content)) "Don't have enough permissions to access bug %s. %s" % (args[0], error.content)
)
else: else:
raise raise
if 'bitesize' in bug.tags: if "bitesize" in bug.tags:
error_out("Bug is already marked as 'bitesize'.") error_out("Bug is already marked as 'bitesize'.")
bug.newMessage(content="I'm marking this bug as 'bitesize' as it looks " bug.newMessage(
"like an issue that is easy to fix and suitable " content="I'm marking this bug as 'bitesize' as it looks "
"for newcomers in Ubuntu development. If you need " "like an issue that is easy to fix and suitable "
"any help with fixing it, talk to me about it.") "for newcomers in Ubuntu development. If you need "
"any help with fixing it, talk to me about it."
)
bug.subscribe(person=launchpad.me) bug.subscribe(person=launchpad.me)
tag_bug(launchpad.bugs[bug.id]) # fresh bug object, LP: #336866 workaround tag_bug(launchpad.bugs[bug.id]) # fresh bug object, LP: #336866 workaround
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -29,57 +29,58 @@ import apt
def check_support(apt_cache, pkgname, alt=False): def check_support(apt_cache, pkgname, alt=False):
'''Check if pkgname is in main or restricted. """Check if pkgname is in main or restricted.
This prints messages if a package is not in main/restricted, or only This prints messages if a package is not in main/restricted, or only
partially (i. e. source in main, but binary in universe). partially (i. e. source in main, but binary in universe).
''' """
if alt: if alt:
prefix = ' ... alternative ' + pkgname prefix = " ... alternative " + pkgname
else: else:
prefix = ' * ' + pkgname prefix = " * " + pkgname
try: try:
pkg = apt_cache[pkgname] pkg = apt_cache[pkgname]
except KeyError: except KeyError:
print(prefix, 'does not exist (pure virtual?)', file=sys.stderr) print(prefix, "does not exist (pure virtual?)", file=sys.stderr)
return False return False
section = pkg.candidate.section section = pkg.candidate.section
if section.startswith('universe') or section.startswith('multiverse'): if section.startswith("universe") or section.startswith("multiverse"):
# check if the source package is in main and thus will only need binary # check if the source package is in main and thus will only need binary
# promotion # promotion
source_records = apt.apt_pkg.SourceRecords() source_records = apt.apt_pkg.SourceRecords()
if not source_records.lookup(pkg.candidate.source_name): if not source_records.lookup(pkg.candidate.source_name):
print('ERROR: Cannot lookup source package for', pkg.name, print("ERROR: Cannot lookup source package for", pkg.name, file=sys.stderr)
file=sys.stderr) print(prefix, "package is in", section.split("/")[0])
print(prefix, 'package is in', section.split('/')[0])
return False return False
src = apt.apt_pkg.TagSection(source_records.record) src = apt.apt_pkg.TagSection(source_records.record)
if (src['Section'].startswith('universe') or if src["Section"].startswith("universe") or src["Section"].startswith("multiverse"):
src['Section'].startswith('multiverse')): print(prefix, "binary and source package is in", section.split("/")[0])
print(prefix, 'binary and source package is in',
section.split('/')[0])
return False return False
else: else:
print(prefix, 'is in', section.split('/')[0] + ', but its source', print(
pkg.candidate.source_name, prefix,
'is already in main; file an ubuntu-archive bug for ' "is in",
'promoting the current preferred alternative') section.split("/")[0] + ", but its source",
pkg.candidate.source_name,
"is already in main; file an ubuntu-archive bug for "
"promoting the current preferred alternative",
)
return True return True
if alt: if alt:
print(prefix, 'is already in main; consider preferring it') print(prefix, "is already in main; consider preferring it")
return True return True
def check_build_dependencies(apt_cache, control): def check_build_dependencies(apt_cache, control):
print('Checking support status of build dependencies...') print("Checking support status of build dependencies...")
any_unsupported = False any_unsupported = False
for field in ('Build-Depends', 'Build-Depends-Indep'): for field in ("Build-Depends", "Build-Depends-Indep"):
if field not in control.section: if field not in control.section:
continue continue
for or_group in apt.apt_pkg.parse_src_depends(control.section[field]): for or_group in apt.apt_pkg.parse_src_depends(control.section[field]):
@ -98,20 +99,19 @@ def check_build_dependencies(apt_cache, control):
def check_binary_dependencies(apt_cache, control): def check_binary_dependencies(apt_cache, control):
any_unsupported = False any_unsupported = False
print('\nChecking support status of binary dependencies...') print("\nChecking support status of binary dependencies...")
while True: while True:
try: try:
next(control) next(control)
except StopIteration: except StopIteration:
break break
for field in ('Depends', 'Pre-Depends', 'Recommends'): for field in ("Depends", "Pre-Depends", "Recommends"):
if field not in control.section: if field not in control.section:
continue continue
for or_group in apt.apt_pkg.parse_src_depends( for or_group in apt.apt_pkg.parse_src_depends(control.section[field]):
control.section[field]):
pkgname = or_group[0][0] pkgname = or_group[0][0]
if pkgname.startswith('$'): if pkgname.startswith("$"):
continue continue
if not check_support(apt_cache, pkgname): if not check_support(apt_cache, pkgname):
# check non-preferred alternatives # check non-preferred alternatives
@ -125,32 +125,38 @@ def check_binary_dependencies(apt_cache, control):
def main(): def main():
description = "Check if any of a package's build or binary " + \ description = (
"dependencies are in universe or multiverse. " + \ "Check if any of a package's build or binary "
"Run this inside an unpacked source package" + "dependencies are in universe or multiverse. "
+ "Run this inside an unpacked source package"
)
parser = optparse.OptionParser(description=description) parser = optparse.OptionParser(description=description)
parser.parse_args() parser.parse_args()
apt_cache = apt.Cache() apt_cache = apt.Cache()
if not os.path.exists('debian/control'): if not os.path.exists("debian/control"):
print('debian/control not found. You need to run this tool in a ' print(
'source package directory', file=sys.stderr) "debian/control not found. You need to run this tool in a source package directory",
file=sys.stderr,
)
sys.exit(1) sys.exit(1)
# get build dependencies from debian/control # get build dependencies from debian/control
control = apt.apt_pkg.TagFile(open('debian/control')) control = apt.apt_pkg.TagFile(open("debian/control"))
next(control) next(control)
unsupported_build_deps = check_build_dependencies(apt_cache, control) unsupported_build_deps = check_build_dependencies(apt_cache, control)
unsupported_binary_deps = check_binary_dependencies(apt_cache, control) unsupported_binary_deps = check_binary_dependencies(apt_cache, control)
if unsupported_build_deps or unsupported_binary_deps: if unsupported_build_deps or unsupported_binary_deps:
print('\nPlease check https://wiki.ubuntu.com/MainInclusionProcess if ' print(
'this source package needs to get into in main/restricted, or ' "\nPlease check https://wiki.ubuntu.com/MainInclusionProcess if "
'reconsider if the package really needs above dependencies.') "this source package needs to get into in main/restricted, or "
"reconsider if the package really needs above dependencies."
)
else: else:
print('All dependencies are supported in main or restricted.') print("All dependencies are supported in main or restricted.")
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -30,33 +30,33 @@ from ubuntutools.question import EditFile
def main(): def main():
parser = optparse.OptionParser('%prog [options] filename') parser = optparse.OptionParser("%prog [options] filename")
options, args = parser.parse_args() options, args = parser.parse_args()
if len(args) != 1: if len(args) != 1:
parser.error('A filename must be specified') parser.error("A filename must be specified")
body = args[0] body = args[0]
if not os.path.isfile(body): if not os.path.isfile(body):
parser.error('File %s does not exist' % body) parser.error("File %s does not exist" % body)
if 'UDT_EDIT_WRAPPER_EDITOR' in os.environ: if "UDT_EDIT_WRAPPER_EDITOR" in os.environ:
os.environ['EDITOR'] = os.environ['UDT_EDIT_WRAPPER_EDITOR'] os.environ["EDITOR"] = os.environ["UDT_EDIT_WRAPPER_EDITOR"]
else: else:
del os.environ['EDITOR'] del os.environ["EDITOR"]
if 'UDT_EDIT_WRAPPER_VISUAL' in os.environ: if "UDT_EDIT_WRAPPER_VISUAL" in os.environ:
os.environ['VISUAL'] = os.environ['UDT_EDIT_WRAPPER_VISUAL'] os.environ["VISUAL"] = os.environ["UDT_EDIT_WRAPPER_VISUAL"]
else: else:
del os.environ['VISUAL'] del os.environ["VISUAL"]
placeholders = [] placeholders = []
if 'UDT_EDIT_WRAPPER_TEMPLATE_RE' in os.environ: if "UDT_EDIT_WRAPPER_TEMPLATE_RE" in os.environ:
placeholders.append(re.compile( placeholders.append(re.compile(os.environ["UDT_EDIT_WRAPPER_TEMPLATE_RE"]))
os.environ['UDT_EDIT_WRAPPER_TEMPLATE_RE']))
description = os.environ.get('UDT_EDIT_WRAPPER_FILE_DESCRIPTION', 'file') description = os.environ.get("UDT_EDIT_WRAPPER_FILE_DESCRIPTION", "file")
EditFile(body, description, placeholders).edit() EditFile(body, description, placeholders).edit()
if __name__ == '__main__':
if __name__ == "__main__":
main() main()

View File

@ -28,17 +28,19 @@ from httplib2 import Http, HttpLib2Error
import ubuntutools.misc import ubuntutools.misc
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def main(): def main():
parser = optparse.OptionParser( parser = optparse.OptionParser(
usage='%prog [options] [string]', usage="%prog [options] [string]",
description='List pending merges from Debian matching string') description="List pending merges from Debian matching string",
)
args = parser.parse_args()[1] args = parser.parse_args()[1]
if len(args) > 1: if len(args) > 1:
parser.error('Too many arguments') parser.error("Too many arguments")
elif len(args) == 1: elif len(args) == 1:
match = args[0] match = args[0]
else: else:
@ -46,36 +48,46 @@ def main():
ubuntutools.misc.require_utf8() ubuntutools.misc.require_utf8()
for component in ('main', 'main-manual', for component in (
'restricted', 'restricted-manual', "main",
'universe', 'universe-manual', "main-manual",
'multiverse', 'multiverse-manual'): "restricted",
"restricted-manual",
"universe",
"universe-manual",
"multiverse",
"multiverse-manual",
):
url = 'https://merges.ubuntu.com/%s.json' % component url = "https://merges.ubuntu.com/%s.json" % component
try: try:
headers, page = Http().request(url) headers, page = Http().request(url)
except HttpLib2Error as e: except HttpLib2Error as e:
Logger.exception(e) Logger.exception(e)
sys.exit(1) sys.exit(1)
if headers.status != 200: if headers.status != 200:
Logger.error("%s: %s %s" % (url, headers.status, Logger.error("%s: %s %s" % (url, headers.status, headers.reason))
headers.reason))
sys.exit(1) sys.exit(1)
for merge in json.loads(page): for merge in json.loads(page):
package = merge['source_package'] package = merge["source_package"]
author, uploader = '', '' author, uploader = "", ""
if merge.get('user'): if merge.get("user"):
author = merge['user'] author = merge["user"]
if merge.get('uploader'): if merge.get("uploader"):
uploader = '(%s)' % merge['uploader'] uploader = "(%s)" % merge["uploader"]
teams = merge.get('teams', []) teams = merge.get("teams", [])
pretty_uploader = '{} {}'.format(author, uploader) pretty_uploader = "{} {}".format(author, uploader)
if (match is None or match in package or match in author if (
or match in uploader or match in teams): match is None
Logger.info('%s\t%s' % (package, pretty_uploader)) or match in package
or match in author
or match in uploader
or match in teams
):
Logger.info("%s\t%s" % (package, pretty_uploader))
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -33,6 +33,7 @@ from launchpadlib.launchpad import Launchpad
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -40,19 +41,33 @@ def main():
bug_re = re.compile(r"bug=(\d+)") bug_re = re.compile(r"bug=(\d+)")
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-b", "--browserless", action="store_true", parser.add_argument(
help="Don't open the bug in the browser at the end") "-b",
parser.add_argument("-l", "--lpinstance", metavar="INSTANCE", "--browserless",
help="LP instance to connect to (default: production)") action="store_true",
parser.add_argument("-v", "--verbose", action="store_true", help="Don't open the bug in the browser at the end",
help="Print info about the bug being imported") )
parser.add_argument("-n", "--dry-run", action="store_true", parser.add_argument(
help="Don't actually open a bug (also sets verbose)") "-l",
parser.add_argument("-p", "--package", "--lpinstance",
help="Launchpad package to file bug against " metavar="INSTANCE",
"(default: Same as Debian)") help="LP instance to connect to (default: production)",
parser.add_argument("--no-conf", action="store_true", )
help="Don't read config files or environment variables.") parser.add_argument(
"-v", "--verbose", action="store_true", help="Print info about the bug being imported"
)
parser.add_argument(
"-n",
"--dry-run",
action="store_true",
help="Don't actually open a bug (also sets verbose)",
)
parser.add_argument(
"-p", "--package", help="Launchpad package to file bug against (default: Same as Debian)"
)
parser.add_argument(
"--no-conf", action="store_true", help="Don't read config files or environment variables."
)
parser.add_argument("bugs", nargs="+", help="Bug number(s) or URL(s)") parser.add_argument("bugs", nargs="+", help="Bug number(s) or URL(s)")
options = parser.parse_args() options = parser.parse_args()
@ -69,9 +84,9 @@ def main():
if options.verbose: if options.verbose:
Logger.setLevel(logging.DEBUG) Logger.setLevel(logging.DEBUG)
debian = launchpad.distributions['debian'] debian = launchpad.distributions["debian"]
ubuntu = launchpad.distributions['ubuntu'] ubuntu = launchpad.distributions["ubuntu"]
lp_debbugs = launchpad.bug_trackers.getByName(name='debbugs') lp_debbugs = launchpad.bug_trackers.getByName(name="debbugs")
bug_nums = [] bug_nums = []
@ -101,31 +116,34 @@ def main():
bug_num = bug.bug_num bug_num = bug.bug_num
subject = bug.subject subject = bug.subject
log = debianbts.get_bug_log(bug_num) log = debianbts.get_bug_log(bug_num)
summary = log[0]['message'].get_payload() summary = log[0]["message"].get_payload()
target = ubuntu.getSourcePackage(name=ubupackage) target = ubuntu.getSourcePackage(name=ubupackage)
if target is None: if target is None:
Logger.error("Source package '%s' is not in Ubuntu. Please specify " Logger.error(
"the destination source package with --package", "Source package '%s' is not in Ubuntu. Please specify "
ubupackage) "the destination source package with --package",
ubupackage,
)
err = True err = True
continue continue
description = ('Imported from Debian bug http://bugs.debian.org/%d:\n\n%s' % description = "Imported from Debian bug http://bugs.debian.org/%d:\n\n%s" % (
(bug_num, summary)) bug_num,
summary,
)
# LP limits descriptions to 50K chars # LP limits descriptions to 50K chars
description = (description[:49994] + ' [...]') if len(description) > 50000 else description description = (description[:49994] + " [...]") if len(description) > 50000 else description
Logger.debug('Target: %s' % target) Logger.debug("Target: %s" % target)
Logger.debug('Subject: %s' % subject) Logger.debug("Subject: %s" % subject)
Logger.debug('Description: ') Logger.debug("Description: ")
Logger.debug(description) Logger.debug(description)
if options.dry_run: if options.dry_run:
Logger.info('Dry-Run: not creating Ubuntu bug.') Logger.info("Dry-Run: not creating Ubuntu bug.")
continue continue
u_bug = launchpad.bugs.createBug(target=target, title=subject, u_bug = launchpad.bugs.createBug(target=target, title=subject, description=description)
description=description)
d_sp = debian.getSourcePackage(name=package) d_sp = debian.getSourcePackage(name=package)
if d_sp is None and options.package: if d_sp is None and options.package:
d_sp = debian.getSourcePackage(name=options.package) d_sp = debian.getSourcePackage(name=options.package)
@ -141,5 +159,5 @@ def main():
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -23,19 +23,23 @@ import sys
from debian.changelog import Changelog from debian.changelog import Changelog
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def usage(exit_code=1): def usage(exit_code=1):
Logger.info('''Usage: merge-changelog <left changelog> <right changelog> Logger.info(
"""Usage: merge-changelog <left changelog> <right changelog>
merge-changelog takes two changelogs that once shared a common source, merge-changelog takes two changelogs that once shared a common source,
merges them back together, and prints the merged result to stdout. This merges them back together, and prints the merged result to stdout. This
is useful if you need to manually merge a ubuntu package with a new is useful if you need to manually merge a ubuntu package with a new
Debian release of the package. Debian release of the package.
''') """
)
sys.exit(exit_code) sys.exit(exit_code)
######################################################################## ########################################################################
# Changelog Management # Changelog Management
######################################################################## ########################################################################
@ -67,11 +71,11 @@ def merge_changelog(left_changelog, right_changelog):
assert block.version == version assert block.version == version
Logger.info(str(block).strip() + ('\n' if ci else '')) Logger.info(str(block).strip() + ("\n" if ci else ""))
def main(): def main():
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'): if len(sys.argv) > 1 and sys.argv[1] in ("-h", "--help"):
usage(0) usage(0)
if len(sys.argv) != 3: if len(sys.argv) != 3:
usage(1) usage(1)
@ -83,5 +87,5 @@ def main():
sys.exit(0) sys.exit(0)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -45,6 +45,7 @@ from ubuntutools.config import UDTConfig
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -87,32 +88,32 @@ class PbuilderDist(object):
self.chroot_string = None self.chroot_string = None
# Authentication method # Authentication method
self.auth = 'sudo' self.auth = "sudo"
# Builder # Builder
self.builder = builder self.builder = builder
self._debian_distros = DebianDistroInfo().all + \ self._debian_distros = DebianDistroInfo().all + ["stable", "testing", "unstable"]
['stable', 'testing', 'unstable']
# Ensure that the used builder is installed # Ensure that the used builder is installed
paths = set(os.environ['PATH'].split(':')) paths = set(os.environ["PATH"].split(":"))
paths |= set(('/sbin', '/usr/sbin', '/usr/local/sbin')) paths |= set(("/sbin", "/usr/sbin", "/usr/local/sbin"))
if not any(os.path.exists(os.path.join(p, builder)) for p in paths): if not any(os.path.exists(os.path.join(p, builder)) for p in paths):
Logger.error('Could not find "%s".', builder) Logger.error('Could not find "%s".', builder)
sys.exit(1) sys.exit(1)
############################################################## ##############################################################
self.base = os.path.expanduser(os.environ.get('PBUILDFOLDER', self.base = os.path.expanduser(os.environ.get("PBUILDFOLDER", "~/pbuilder/"))
'~/pbuilder/'))
if 'SUDO_USER' in os.environ: if "SUDO_USER" in os.environ:
Logger.warning('Running under sudo. ' Logger.warning(
'This is probably not what you want. ' "Running under sudo. "
'pbuilder-dist will use sudo itself, ' "This is probably not what you want. "
'when necessary.') "pbuilder-dist will use sudo itself, "
if os.stat(os.environ['HOME']).st_uid != os.getuid(): "when necessary."
)
if os.stat(os.environ["HOME"]).st_uid != os.getuid():
Logger.error("You don't own $HOME") Logger.error("You don't own $HOME")
sys.exit(1) sys.exit(1)
@ -123,8 +124,8 @@ class PbuilderDist(object):
Logger.error('Cannot create base directory "%s"', self.base) Logger.error('Cannot create base directory "%s"', self.base)
sys.exit(1) sys.exit(1)
if 'PBUILDAUTH' in os.environ: if "PBUILDAUTH" in os.environ:
self.auth = os.environ['PBUILDAUTH'] self.auth = os.environ["PBUILDAUTH"]
self.system_architecture = ubuntutools.misc.host_architecture() self.system_architecture = ubuntutools.misc.host_architecture()
self.system_distro = ubuntutools.misc.system_distribution() self.system_distro = ubuntutools.misc.system_distribution()
@ -134,7 +135,7 @@ class PbuilderDist(object):
self.target_distro = self.system_distro self.target_distro = self.system_distro
def set_target_distro(self, distro): def set_target_distro(self, distro):
""" PbuilderDist.set_target_distro(distro) -> None """PbuilderDist.set_target_distro(distro) -> None
Check if the given target distribution name is correct, if it Check if the given target distribution name is correct, if it
isn't know to the system ask the user for confirmation before isn't know to the system ask the user for confirmation before
@ -145,16 +146,16 @@ class PbuilderDist(object):
Logger.error('"%s" is an invalid distribution codename.', distro) Logger.error('"%s" is an invalid distribution codename.', distro)
sys.exit(1) sys.exit(1)
if not os.path.isfile(os.path.join('/usr/share/debootstrap/scripts/', if not os.path.isfile(os.path.join("/usr/share/debootstrap/scripts/", distro)):
distro)): if os.path.isdir("/usr/share/debootstrap/scripts/"):
if os.path.isdir('/usr/share/debootstrap/scripts/'):
# Debian experimental doesn't have a debootstrap file but # Debian experimental doesn't have a debootstrap file but
# should work nevertheless. # should work nevertheless.
if distro not in self._debian_distros: if distro not in self._debian_distros:
question = ('Warning: Unknown distribution "%s". ' question = (
'Do you want to continue' % distro) 'Warning: Unknown distribution "%s". ' "Do you want to continue" % distro
answer = YesNoQuestion().ask(question, 'no') )
if answer == 'no': answer = YesNoQuestion().ask(question, "no")
if answer == "no":
sys.exit(0) sys.exit(0)
else: else:
Logger.error('Please install package "debootstrap".') Logger.error('Please install package "debootstrap".')
@ -163,33 +164,35 @@ class PbuilderDist(object):
self.target_distro = distro self.target_distro = distro
def set_operation(self, operation): def set_operation(self, operation):
""" PbuilderDist.set_operation -> None """PbuilderDist.set_operation -> None
Check if the given string is a valid pbuilder operation and Check if the given string is a valid pbuilder operation and
depending on this either save it into the appropiate variable depending on this either save it into the appropiate variable
or finalize pbuilder-dist's execution. or finalize pbuilder-dist's execution.
""" """
arguments = ('create', 'update', 'build', 'clean', 'login', 'execute') arguments = ("create", "update", "build", "clean", "login", "execute")
if operation not in arguments: if operation not in arguments:
if operation.endswith('.dsc'): if operation.endswith(".dsc"):
if os.path.isfile(operation): if os.path.isfile(operation):
self.operation = 'build' self.operation = "build"
return [operation] return [operation]
else: else:
Logger.error('Could not find file "%s".', operation) Logger.error('Could not find file "%s".', operation)
sys.exit(1) sys.exit(1)
else: else:
Logger.error('"%s" is not a recognized argument.\n' Logger.error(
'Please use one of these: %s.', '"%s" is not a recognized argument.\nPlease use one of these: %s.',
operation, ', '.join(arguments)) operation,
", ".join(arguments),
)
sys.exit(1) sys.exit(1)
else: else:
self.operation = operation self.operation = operation
return [] return []
def get_command(self, remaining_arguments=None): def get_command(self, remaining_arguments=None):
""" PbuilderDist.get_command -> string """PbuilderDist.get_command -> string
Generate the pbuilder command which matches the given configuration Generate the pbuilder command which matches the given configuration
and return it as a string. and return it as a string.
@ -200,30 +203,34 @@ class PbuilderDist(object):
if self.build_architecture == self.system_architecture: if self.build_architecture == self.system_architecture:
self.chroot_string = self.target_distro self.chroot_string = self.target_distro
else: else:
self.chroot_string = (self.target_distro + '-' self.chroot_string = self.target_distro + "-" + self.build_architecture
+ self.build_architecture)
prefix = os.path.join(self.base, self.chroot_string) prefix = os.path.join(self.base, self.chroot_string)
if '--buildresult' not in remaining_arguments: if "--buildresult" not in remaining_arguments:
result = os.path.normpath('%s_result/' % prefix) result = os.path.normpath("%s_result/" % prefix)
else: else:
location_of_arg = remaining_arguments.index('--buildresult') location_of_arg = remaining_arguments.index("--buildresult")
result = os.path.normpath(remaining_arguments[location_of_arg+1]) result = os.path.normpath(remaining_arguments[location_of_arg + 1])
remaining_arguments.pop(location_of_arg+1) remaining_arguments.pop(location_of_arg + 1)
remaining_arguments.pop(location_of_arg) remaining_arguments.pop(location_of_arg)
if not self.logfile and self.operation != 'login': if not self.logfile and self.operation != "login":
if self.operation == 'build': if self.operation == "build":
dsc_files = [a for a in remaining_arguments dsc_files = [a for a in remaining_arguments if a.strip().endswith(".dsc")]
if a.strip().endswith('.dsc')]
assert len(dsc_files) == 1 assert len(dsc_files) == 1
dsc = debian.deb822.Dsc(open(dsc_files[0])) dsc = debian.deb822.Dsc(open(dsc_files[0]))
version = ubuntutools.version.Version(dsc['Version']) version = ubuntutools.version.Version(dsc["Version"])
name = (dsc['Source'] + '_' + version.strip_epoch() + '_' + name = (
self.build_architecture + '.build') dsc["Source"]
+ "_"
+ version.strip_epoch()
+ "_"
+ self.build_architecture
+ ".build"
)
self.logfile = os.path.join(result, name) self.logfile = os.path.join(result, name)
else: else:
self.logfile = os.path.join(result, 'last_operation.log') self.logfile = os.path.join(result, "last_operation.log")
if not os.path.isdir(result): if not os.path.isdir(result):
try: try:
@ -233,87 +240,89 @@ class PbuilderDist(object):
sys.exit(1) sys.exit(1)
arguments = [ arguments = [
'--%s' % self.operation, "--%s" % self.operation,
'--distribution', self.target_distro, "--distribution",
'--buildresult', result, self.target_distro,
"--buildresult",
result,
] ]
if self.operation == 'update': if self.operation == "update":
arguments += ['--override-config'] arguments += ["--override-config"]
if self.builder == 'pbuilder': if self.builder == "pbuilder":
arguments += ['--basetgz', prefix + '-base.tgz'] arguments += ["--basetgz", prefix + "-base.tgz"]
elif self.builder == 'cowbuilder': elif self.builder == "cowbuilder":
arguments += ['--basepath', prefix + '-base.cow'] arguments += ["--basepath", prefix + "-base.cow"]
else: else:
Logger.error('Unrecognized builder "%s".', self.builder) Logger.error('Unrecognized builder "%s".', self.builder)
sys.exit(1) sys.exit(1)
if self.logfile: if self.logfile:
arguments += ['--logfile', self.logfile] arguments += ["--logfile", self.logfile]
if os.path.exists('/var/cache/archive/'): if os.path.exists("/var/cache/archive/"):
arguments += ['--bindmounts', '/var/cache/archive/'] arguments += ["--bindmounts", "/var/cache/archive/"]
config = UDTConfig() config = UDTConfig()
if self.target_distro in self._debian_distros: if self.target_distro in self._debian_distros:
mirror = os.environ.get('MIRRORSITE', mirror = os.environ.get("MIRRORSITE", config.get_value("DEBIAN_MIRROR"))
config.get_value('DEBIAN_MIRROR')) components = "main"
components = 'main'
if self.extra_components: if self.extra_components:
components += ' contrib non-free' components += " contrib non-free"
else: else:
mirror = os.environ.get('MIRRORSITE', mirror = os.environ.get("MIRRORSITE", config.get_value("UBUNTU_MIRROR"))
config.get_value('UBUNTU_MIRROR')) if self.build_architecture not in ("amd64", "i386"):
if self.build_architecture not in ('amd64', 'i386'): mirror = os.environ.get("MIRRORSITE", config.get_value("UBUNTU_PORTS_MIRROR"))
mirror = os.environ.get( components = "main restricted"
'MIRRORSITE', config.get_value('UBUNTU_PORTS_MIRROR'))
components = 'main restricted'
if self.extra_components: if self.extra_components:
components += ' universe multiverse' components += " universe multiverse"
arguments += ['--mirror', mirror] arguments += ["--mirror", mirror]
othermirrors = [] othermirrors = []
localrepo = '/var/cache/archive/' + self.target_distro localrepo = "/var/cache/archive/" + self.target_distro
if os.path.exists(localrepo): if os.path.exists(localrepo):
repo = 'deb file:///var/cache/archive/ %s/' % self.target_distro repo = "deb file:///var/cache/archive/ %s/" % self.target_distro
othermirrors.append(repo) othermirrors.append(repo)
if self.target_distro in self._debian_distros: if self.target_distro in self._debian_distros:
debian_info = DebianDistroInfo() debian_info = DebianDistroInfo()
try: try:
codename = debian_info.codename(self.target_distro, codename = debian_info.codename(self.target_distro, default=self.target_distro)
default=self.target_distro)
except DistroDataOutdated as error: except DistroDataOutdated as error:
Logger.warning(error) Logger.warning(error)
if codename in (debian_info.devel(), 'experimental'): if codename in (debian_info.devel(), "experimental"):
self.enable_security = False self.enable_security = False
self.enable_updates = False self.enable_updates = False
self.enable_proposed = False self.enable_proposed = False
elif codename in (debian_info.testing(), 'testing'): elif codename in (debian_info.testing(), "testing"):
self.enable_updates = False self.enable_updates = False
if self.enable_security: if self.enable_security:
pocket = '-security' pocket = "-security"
with suppress(ValueError): with suppress(ValueError):
# before bullseye (version 11) security suite is /updates # before bullseye (version 11) security suite is /updates
if float(debian_info.version(codename)) < 11.0: if float(debian_info.version(codename)) < 11.0:
pocket = '/updates' pocket = "/updates"
othermirrors.append('deb %s %s%s %s' othermirrors.append(
% (config.get_value('DEBSEC_MIRROR'), "deb %s %s%s %s"
self.target_distro, pocket, components)) % (config.get_value("DEBSEC_MIRROR"), self.target_distro, pocket, components)
)
if self.enable_updates: if self.enable_updates:
othermirrors.append('deb %s %s-updates %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-updates %s" % (mirror, self.target_distro, components)
)
if self.enable_proposed: if self.enable_proposed:
othermirrors.append('deb %s %s-proposed-updates %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-proposed-updates %s" % (mirror, self.target_distro, components)
)
if self.enable_backports: if self.enable_backports:
othermirrors.append('deb %s %s-backports %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-backports %s" % (mirror, self.target_distro, components)
)
aptcache = os.path.join(self.base, 'aptcache', 'debian') aptcache = os.path.join(self.base, "aptcache", "debian")
else: else:
try: try:
dev_release = self.target_distro == UbuntuDistroInfo().devel() dev_release = self.target_distro == UbuntuDistroInfo().devel()
@ -326,46 +335,51 @@ class PbuilderDist(object):
self.enable_updates = False self.enable_updates = False
if self.enable_security: if self.enable_security:
othermirrors.append('deb %s %s-security %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-security %s" % (mirror, self.target_distro, components)
)
if self.enable_updates: if self.enable_updates:
othermirrors.append('deb %s %s-updates %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-updates %s" % (mirror, self.target_distro, components)
)
if self.enable_proposed: if self.enable_proposed:
othermirrors.append('deb %s %s-proposed %s' othermirrors.append(
% (mirror, self.target_distro, components)) "deb %s %s-proposed %s" % (mirror, self.target_distro, components)
)
aptcache = os.path.join(self.base, 'aptcache', 'ubuntu') aptcache = os.path.join(self.base, "aptcache", "ubuntu")
if 'OTHERMIRROR' in os.environ: if "OTHERMIRROR" in os.environ:
othermirrors += os.environ['OTHERMIRROR'].split('|') othermirrors += os.environ["OTHERMIRROR"].split("|")
if othermirrors: if othermirrors:
arguments += ['--othermirror', '|'.join(othermirrors)] arguments += ["--othermirror", "|".join(othermirrors)]
# Work around LP:#599695 # Work around LP:#599695
if (ubuntutools.misc.system_distribution() == 'Debian' if (
and self.target_distro not in self._debian_distros): ubuntutools.misc.system_distribution() == "Debian"
if not os.path.exists( and self.target_distro not in self._debian_distros
'/usr/share/keyrings/ubuntu-archive-keyring.gpg'): ):
Logger.error('ubuntu-keyring not installed') if not os.path.exists("/usr/share/keyrings/ubuntu-archive-keyring.gpg"):
Logger.error("ubuntu-keyring not installed")
sys.exit(1) sys.exit(1)
arguments += [ arguments += [
'--debootstrapopts', "--debootstrapopts",
'--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg', "--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg",
] ]
elif (ubuntutools.misc.system_distribution() == 'Ubuntu' elif (
and self.target_distro in self._debian_distros): ubuntutools.misc.system_distribution() == "Ubuntu"
if not os.path.exists( and self.target_distro in self._debian_distros
'/usr/share/keyrings/debian-archive-keyring.gpg'): ):
Logger.error('debian-archive-keyring not installed') if not os.path.exists("/usr/share/keyrings/debian-archive-keyring.gpg"):
Logger.error("debian-archive-keyring not installed")
sys.exit(1) sys.exit(1)
arguments += [ arguments += [
'--debootstrapopts', "--debootstrapopts",
'--keyring=/usr/share/keyrings/debian-archive-keyring.gpg', "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg",
] ]
arguments += ['--aptcache', aptcache, '--components', components] arguments += ["--aptcache", aptcache, "--components", components]
if not os.path.isdir(aptcache): if not os.path.isdir(aptcache):
try: try:
@ -375,13 +389,11 @@ class PbuilderDist(object):
sys.exit(1) sys.exit(1)
if self.build_architecture != self.system_architecture: if self.build_architecture != self.system_architecture:
arguments += ['--debootstrapopts', arguments += ["--debootstrapopts", "--arch=" + self.build_architecture]
'--arch=' + self.build_architecture]
apt_conf_dir = os.path.join(self.base, apt_conf_dir = os.path.join(self.base, "etc/%s/apt.conf" % self.target_distro)
'etc/%s/apt.conf' % self.target_distro)
if os.path.exists(apt_conf_dir): if os.path.exists(apt_conf_dir):
arguments += ['--aptconfdir', apt_conf_dir] arguments += ["--aptconfdir", apt_conf_dir]
# Append remaining arguments # Append remaining arguments
if remaining_arguments: if remaining_arguments:
@ -392,28 +404,28 @@ class PbuilderDist(object):
# With both common variable name schemes (BTS: #659060). # With both common variable name schemes (BTS: #659060).
return [ return [
self.auth, self.auth,
'HOME=' + os.path.expanduser('~'), "HOME=" + os.path.expanduser("~"),
'ARCHITECTURE=' + self.build_architecture, "ARCHITECTURE=" + self.build_architecture,
'DISTRIBUTION=' + self.target_distro, "DISTRIBUTION=" + self.target_distro,
'ARCH=' + self.build_architecture, "ARCH=" + self.build_architecture,
'DIST=' + self.target_distro, "DIST=" + self.target_distro,
'DEB_BUILD_OPTIONS=' + os.environ.get('DEB_BUILD_OPTIONS', ''), "DEB_BUILD_OPTIONS=" + os.environ.get("DEB_BUILD_OPTIONS", ""),
self.builder, self.builder,
] + arguments ] + arguments
def show_help(exit_code=0): def show_help(exit_code=0):
""" help() -> None """help() -> None
Print a help message for pbuilder-dist, and exit with the given code. Print a help message for pbuilder-dist, and exit with the given code.
""" """
Logger.info('See man pbuilder-dist for more information.') Logger.info("See man pbuilder-dist for more information.")
sys.exit(exit_code) sys.exit(exit_code)
def main(): def main():
""" main() -> None """main() -> None
This is pbuilder-dist's main function. It creates a PbuilderDist This is pbuilder-dist's main function. It creates a PbuilderDist
object, modifies all necessary settings taking data from the object, modifies all necessary settings taking data from the
@ -421,27 +433,25 @@ def main():
the script and runs pbuilder itself or exists with an error message. the script and runs pbuilder itself or exists with an error message.
""" """
script_name = os.path.basename(sys.argv[0]) script_name = os.path.basename(sys.argv[0])
parts = script_name.split('-') parts = script_name.split("-")
# Copy arguments into another list for save manipulation # Copy arguments into another list for save manipulation
args = sys.argv[1:] args = sys.argv[1:]
if ('-' in script_name and parts[0] not in ('pbuilder', 'cowbuilder') if "-" in script_name and parts[0] not in ("pbuilder", "cowbuilder") or len(parts) > 3:
or len(parts) > 3): Logger.error('"%s" is not a valid name for a "pbuilder-dist" executable.', script_name)
Logger.error('"%s" is not a valid name for a "pbuilder-dist" '
'executable.', script_name)
sys.exit(1) sys.exit(1)
if len(args) < 1: if len(args) < 1:
Logger.error('Insufficient number of arguments.') Logger.error("Insufficient number of arguments.")
show_help(1) show_help(1)
if args[0] in ('-h', '--help', 'help'): if args[0] in ("-h", "--help", "help"):
show_help(0) show_help(0)
app = PbuilderDist(parts[0]) app = PbuilderDist(parts[0])
if len(parts) > 1 and parts[1] != 'dist' and '.' not in parts[1]: if len(parts) > 1 and parts[1] != "dist" and "." not in parts[1]:
app.set_target_distro(parts[1]) app.set_target_distro(parts[1])
else: else:
app.set_target_distro(args.pop(0)) app.set_target_distro(args.pop(0))
@ -449,24 +459,28 @@ def main():
if len(parts) > 2: if len(parts) > 2:
requested_arch = parts[2] requested_arch = parts[2]
elif len(args) > 0: elif len(args) > 0:
if shutil.which('arch-test') is not None: if shutil.which("arch-test") is not None:
if subprocess.run( if subprocess.run(["arch-test", args[0]], stdout=subprocess.DEVNULL).returncode == 0:
['arch-test', args[0]],
stdout=subprocess.DEVNULL).returncode == 0:
requested_arch = args.pop(0) requested_arch = args.pop(0)
elif (os.path.isdir('/usr/lib/arch-test') elif os.path.isdir("/usr/lib/arch-test") and args[0] in os.listdir(
and args[0] in os.listdir('/usr/lib/arch-test/')): "/usr/lib/arch-test/"
Logger.error('Architecture "%s" is not supported on your ' ):
'currently running kernel. Consider installing ' Logger.error(
'the qemu-user-static package to enable the use of ' 'Architecture "%s" is not supported on your '
'foreign architectures.', args[0]) "currently running kernel. Consider installing "
"the qemu-user-static package to enable the use of "
"foreign architectures.",
args[0],
)
sys.exit(1) sys.exit(1)
else: else:
requested_arch = None requested_arch = None
else: else:
Logger.error('Cannot determine if "%s" is a valid architecture. ' Logger.error(
'Please install the arch-test package and retry.', 'Cannot determine if "%s" is a valid architecture. '
args[0]) "Please install the arch-test package and retry.",
args[0],
)
sys.exit(1) sys.exit(1)
else: else:
requested_arch = None requested_arch = None
@ -474,62 +488,74 @@ def main():
if requested_arch: if requested_arch:
app.build_architecture = requested_arch app.build_architecture = requested_arch
# For some foreign architectures we need to use qemu # For some foreign architectures we need to use qemu
if (requested_arch != app.system_architecture if requested_arch != app.system_architecture and (
and (app.system_architecture, requested_arch) not in [ app.system_architecture,
('amd64', 'i386'), ('amd64', 'lpia'), ('arm', 'armel'), requested_arch,
('armel', 'arm'), ('armel', 'armhf'), ('armhf', 'armel'), ) not in [
('arm64', 'arm'), ('arm64', 'armhf'), ('arm64', 'armel'), ("amd64", "i386"),
('i386', 'lpia'), ('lpia', 'i386'), ('powerpc', 'ppc64'), ("amd64", "lpia"),
('ppc64', 'powerpc'), ('sparc', 'sparc64'), ("arm", "armel"),
('sparc64', 'sparc')]): ("armel", "arm"),
args += ['--debootstrap', 'qemu-debootstrap'] ("armel", "armhf"),
("armhf", "armel"),
("arm64", "arm"),
("arm64", "armhf"),
("arm64", "armel"),
("i386", "lpia"),
("lpia", "i386"),
("powerpc", "ppc64"),
("ppc64", "powerpc"),
("sparc", "sparc64"),
("sparc64", "sparc"),
]:
args += ["--debootstrap", "qemu-debootstrap"]
if 'mainonly' in sys.argv or '--main-only' in sys.argv: if "mainonly" in sys.argv or "--main-only" in sys.argv:
app.extra_components = False app.extra_components = False
if 'mainonly' in sys.argv: if "mainonly" in sys.argv:
args.remove('mainonly') args.remove("mainonly")
else: else:
args.remove('--main-only') args.remove("--main-only")
if '--release-only' in sys.argv: if "--release-only" in sys.argv:
args.remove('--release-only') args.remove("--release-only")
app.enable_security = False app.enable_security = False
app.enable_updates = False app.enable_updates = False
app.enable_proposed = False app.enable_proposed = False
elif '--security-only' in sys.argv: elif "--security-only" in sys.argv:
args.remove('--security-only') args.remove("--security-only")
app.enable_updates = False app.enable_updates = False
app.enable_proposed = False app.enable_proposed = False
elif '--updates-only' in sys.argv: elif "--updates-only" in sys.argv:
args.remove('--updates-only') args.remove("--updates-only")
app.enable_proposed = False app.enable_proposed = False
elif '--backports' in sys.argv: elif "--backports" in sys.argv:
args.remove('--backports') args.remove("--backports")
app.enable_backports = True app.enable_backports = True
if len(args) < 1: if len(args) < 1:
Logger.error('Insufficient number of arguments.') Logger.error("Insufficient number of arguments.")
show_help(1) show_help(1)
# Parse the operation # Parse the operation
args = app.set_operation(args.pop(0)) + args args = app.set_operation(args.pop(0)) + args
if app.operation == 'build': if app.operation == "build":
if len([a for a in args if a.strip().endswith('.dsc')]) != 1: if len([a for a in args if a.strip().endswith(".dsc")]) != 1:
msg = 'You have to specify one .dsc file if you want to build.' msg = "You have to specify one .dsc file if you want to build."
Logger.error(msg) Logger.error(msg)
sys.exit(1) sys.exit(1)
# Execute the pbuilder command # Execute the pbuilder command
if '--debug-echo' not in args: if "--debug-echo" not in args:
sys.exit(subprocess.call(app.get_command(args))) sys.exit(subprocess.call(app.get_command(args)))
else: else:
Logger.info(app.get_command([arg for arg in args if arg != '--debug-echo'])) Logger.info(app.get_command([arg for arg in args if arg != "--debug-echo"]))
if __name__ == '__main__': if __name__ == "__main__":
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
Logger.error('Manually aborted.') Logger.error("Manually aborted.")
sys.exit(1) sys.exit(1)

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='debian', pull='ddebs') PullPkg.main(distro="debian", pull="ddebs")

View File

@ -27,19 +27,20 @@ from ubuntutools.config import UDTConfig
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def previous_version(package, version, distance): def previous_version(package, version, distance):
"Given an (extracted) package, determine the version distance versions ago" "Given an (extracted) package, determine the version distance versions ago"
upver = Version(version).upstream_version upver = Version(version).upstream_version
filename = '%s-%s/debian/changelog' % (package, upver) filename = "%s-%s/debian/changelog" % (package, upver)
changelog_file = open(filename, 'r') changelog_file = open(filename, "r")
changelog = debian.changelog.Changelog(changelog_file.read()) changelog = debian.changelog.Changelog(changelog_file.read())
changelog_file.close() changelog_file.close()
seen = 0 seen = 0
for entry in changelog: for entry in changelog:
if entry.distributions == 'UNRELEASED': if entry.distributions == "UNRELEASED":
continue continue
if seen == distance: if seen == distance:
return entry.version.full_version return entry.version.full_version
@ -48,46 +49,60 @@ def previous_version(package, version, distance):
def main(): def main():
parser = optparse.OptionParser('%prog [options] <package> <version> ' parser = optparse.OptionParser("%prog [options] <package> <version> [distance]")
'[distance]') parser.add_option(
parser.add_option('-f', '--fetch', "-f",
dest='fetch_only', default=False, action='store_true', "--fetch",
help="Only fetch the source packages, don't diff.") dest="fetch_only",
parser.add_option('-d', '--debian-mirror', metavar='DEBIAN_MIRROR', default=False,
dest='debian_mirror', action="store_true",
help='Preferred Debian mirror ' help="Only fetch the source packages, don't diff.",
'(default: http://deb.debian.org/debian)') )
parser.add_option('-s', '--debsec-mirror', metavar='DEBSEC_MIRROR', parser.add_option(
dest='debsec_mirror', "-d",
help='Preferred Debian Security mirror ' "--debian-mirror",
'(default: http://security.debian.org)') metavar="DEBIAN_MIRROR",
parser.add_option('--no-conf', dest="debian_mirror",
dest='no_conf', default=False, action='store_true', help="Preferred Debian mirror (default: http://deb.debian.org/debian)",
help="Don't read config files or environment variables") )
parser.add_option(
"-s",
"--debsec-mirror",
metavar="DEBSEC_MIRROR",
dest="debsec_mirror",
help="Preferred Debian Security mirror (default: http://security.debian.org)",
)
parser.add_option(
"--no-conf",
dest="no_conf",
default=False,
action="store_true",
help="Don't read config files or environment variables",
)
opts, args = parser.parse_args() opts, args = parser.parse_args()
if len(args) < 2: if len(args) < 2:
parser.error('Must specify package and version') parser.error("Must specify package and version")
elif len(args) > 3: elif len(args) > 3:
parser.error('Too many arguments') parser.error("Too many arguments")
package = args[0] package = args[0]
version = args[1] version = args[1]
distance = int(args[2]) if len(args) > 2 else 1 distance = int(args[2]) if len(args) > 2 else 1
config = UDTConfig(opts.no_conf) config = UDTConfig(opts.no_conf)
if opts.debian_mirror is None: if opts.debian_mirror is None:
opts.debian_mirror = config.get_value('DEBIAN_MIRROR') opts.debian_mirror = config.get_value("DEBIAN_MIRROR")
if opts.debsec_mirror is None: if opts.debsec_mirror is None:
opts.debsec_mirror = config.get_value('DEBSEC_MIRROR') opts.debsec_mirror = config.get_value("DEBSEC_MIRROR")
mirrors = [opts.debsec_mirror, opts.debian_mirror] mirrors = [opts.debsec_mirror, opts.debian_mirror]
Logger.info('Downloading %s %s', package, version) Logger.info("Downloading %s %s", package, version)
newpkg = DebianSourcePackage(package, version, mirrors=mirrors) newpkg = DebianSourcePackage(package, version, mirrors=mirrors)
try: try:
newpkg.pull() newpkg.pull()
except DownloadError as e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error("Failed to download: %s", str(e))
sys.exit(1) sys.exit(1)
newpkg.unpack() newpkg.unpack()
@ -96,21 +111,21 @@ def main():
oldversion = previous_version(package, version, distance) oldversion = previous_version(package, version, distance)
if not oldversion: if not oldversion:
Logger.error('No previous version could be found') Logger.error("No previous version could be found")
sys.exit(1) sys.exit(1)
Logger.info('Downloading %s %s', package, oldversion) Logger.info("Downloading %s %s", package, oldversion)
oldpkg = DebianSourcePackage(package, oldversion, mirrors=mirrors) oldpkg = DebianSourcePackage(package, oldversion, mirrors=mirrors)
try: try:
oldpkg.pull() oldpkg.pull()
except DownloadError as e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error("Failed to download: %s", str(e))
sys.exit(1) sys.exit(1)
Logger.info('file://' + oldpkg.debdiff(newpkg, diffstat=True)) Logger.info("file://" + oldpkg.debdiff(newpkg, diffstat=True))
if __name__ == '__main__': if __name__ == "__main__":
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
Logger.info('User abort.') Logger.info("User abort.")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='debian', pull='debs') PullPkg.main(distro="debian", pull="debs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='debian', pull='source') PullPkg.main(distro="debian", pull="source")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='debian', pull='udebs') PullPkg.main(distro="debian", pull="udebs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ubuntu', pull='ddebs') PullPkg.main(distro="ubuntu", pull="ddebs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ubuntu', pull='debs') PullPkg.main(distro="ubuntu", pull="debs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ubuntu', pull='source') PullPkg.main(distro="ubuntu", pull="source")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ubuntu', pull='udebs') PullPkg.main(distro="ubuntu", pull="udebs")

View File

@ -25,5 +25,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main() PullPkg.main()

View File

@ -8,5 +8,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ppa', pull='ddebs') PullPkg.main(distro="ppa", pull="ddebs")

View File

@ -8,5 +8,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ppa', pull='debs') PullPkg.main(distro="ppa", pull="debs")

View File

@ -8,5 +8,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ppa', pull='source') PullPkg.main(distro="ppa", pull="source")

View File

@ -8,5 +8,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='ppa', pull='udebs') PullPkg.main(distro="ppa", pull="udebs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='uca', pull='ddebs') PullPkg.main(distro="uca", pull="ddebs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='uca', pull='debs') PullPkg.main(distro="uca", pull="debs")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='uca', pull='source') PullPkg.main(distro="uca", pull="source")

View File

@ -7,5 +7,5 @@
from ubuntutools.pullpkg import PullPkg from ubuntutools.pullpkg import PullPkg
if __name__ == '__main__': if __name__ == "__main__":
PullPkg.main(distro='uca', pull='udebs') PullPkg.main(distro="uca", pull="udebs")

View File

@ -24,11 +24,11 @@ from distro_info import UbuntuDistroInfo
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools.lp.lpapicache import Launchpad, Distribution from ubuntutools.lp.lpapicache import Launchpad, Distribution
from ubuntutools.lp.udtexceptions import PackageNotFoundException from ubuntutools.lp.udtexceptions import PackageNotFoundException
from ubuntutools.question import (YesNoQuestion, EditBugReport, from ubuntutools.question import YesNoQuestion, EditBugReport, confirmation_prompt
confirmation_prompt)
from ubuntutools.rdepends import query_rdepends, RDependsException from ubuntutools.rdepends import query_rdepends, RDependsException
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -44,11 +44,9 @@ def determine_destinations(source, destination):
if source not in ubuntu_info.all: if source not in ubuntu_info.all:
raise DestinationException("Source release %s does not exist" % source) raise DestinationException("Source release %s does not exist" % source)
if destination not in ubuntu_info.all: if destination not in ubuntu_info.all:
raise DestinationException("Destination release %s does not exist" raise DestinationException("Destination release %s does not exist" % destination)
% destination)
if destination not in ubuntu_info.supported(): if destination not in ubuntu_info.supported():
raise DestinationException("Destination release %s is not supported" raise DestinationException("Destination release %s is not supported" % destination)
% destination)
found = False found = False
destinations = [] destinations = []
@ -76,30 +74,34 @@ def determine_destinations(source, destination):
def disclaimer(): def disclaimer():
print("Ubuntu's backports are not for fixing bugs in stable releases, " print(
"but for bringing new features to older, stable releases.\n" "Ubuntu's backports are not for fixing bugs in stable releases, "
"See https://wiki.ubuntu.com/UbuntuBackports for the Ubuntu " "but for bringing new features to older, stable releases.\n"
"Backports policy and processes.\n" "See https://wiki.ubuntu.com/UbuntuBackports for the Ubuntu "
"See https://wiki.ubuntu.com/StableReleaseUpdates for the process " "Backports policy and processes.\n"
"for fixing bugs in stable releases.") "See https://wiki.ubuntu.com/StableReleaseUpdates for the process "
"for fixing bugs in stable releases."
)
confirmation_prompt() confirmation_prompt()
def check_existing(package): def check_existing(package):
"""Search for possible existing bug reports""" """Search for possible existing bug reports"""
distro = Distribution('ubuntu') distro = Distribution("ubuntu")
srcpkg = distro.getSourcePackage(name=package.getPackageName()) srcpkg = distro.getSourcePackage(name=package.getPackageName())
bugs = srcpkg.searchTasks(omit_duplicates=True, bugs = srcpkg.searchTasks(
search_text="[BPO]", omit_duplicates=True,
status=["Incomplete", "New", "Confirmed", search_text="[BPO]",
"Triaged", "In Progress", status=["Incomplete", "New", "Confirmed", "Triaged", "In Progress", "Fix Committed"],
"Fix Committed"]) )
if not bugs: if not bugs:
return return
Logger.info("There are existing bug reports that look similar to your " Logger.info(
"request. Please check before continuing:") "There are existing bug reports that look similar to your "
"request. Please check before continuing:"
)
for bug in sorted([bug_task.bug for bug_task in bugs], key=lambda bug: bug.id): for bug in sorted([bug_task.bug for bug_task in bugs], key=lambda bug: bug.id):
Logger.info(" * LP: #%-7i: %s %s", bug.id, bug.title, bug.web_link) Logger.info(" * LP: #%-7i: %s %s", bug.id, bug.title, bug.web_link)
@ -114,7 +116,7 @@ def find_rdepends(releases, published_binaries):
for binpkg in published_binaries: for binpkg in published_binaries:
intermediate[binpkg] intermediate[binpkg]
for arch in ('any', 'source'): for arch in ("any", "source"):
for release in releases: for release in releases:
for binpkg in published_binaries: for binpkg in published_binaries:
try: try:
@ -125,20 +127,20 @@ def find_rdepends(releases, published_binaries):
for relationship, rdeps in raw_rdeps.items(): for relationship, rdeps in raw_rdeps.items():
for rdep in rdeps: for rdep in rdeps:
# Ignore circular deps: # Ignore circular deps:
if rdep['Package'] in published_binaries: if rdep["Package"] in published_binaries:
continue continue
# arch==any queries return Reverse-Build-Deps: # arch==any queries return Reverse-Build-Deps:
if arch == 'any' and rdep.get('Architectures', []) == ['source']: if arch == "any" and rdep.get("Architectures", []) == ["source"]:
continue continue
intermediate[binpkg][rdep['Package']].append((release, relationship)) intermediate[binpkg][rdep["Package"]].append((release, relationship))
output = [] output = []
for binpkg, rdeps in intermediate.items(): for binpkg, rdeps in intermediate.items():
output += ['', binpkg, '-' * len(binpkg)] output += ["", binpkg, "-" * len(binpkg)]
for pkg, appearences in rdeps.items(): for pkg, appearences in rdeps.items():
output += ['* %s' % pkg] output += ["* %s" % pkg]
for release, relationship in appearences: for release, relationship in appearences:
output += [' [ ] %s (%s)' % (release, relationship)] output += [" [ ] %s (%s)" % (release, relationship)]
found_any = sum(len(rdeps) for rdeps in intermediate.values()) found_any = sum(len(rdeps) for rdeps in intermediate.values())
if found_any: if found_any:
@ -153,8 +155,8 @@ def find_rdepends(releases, published_binaries):
"package currently in the release still works with the new " "package currently in the release still works with the new "
"%(package)s installed. " "%(package)s installed. "
"Reverse- Recommends, Suggests, and Enhances don't need to be " "Reverse- Recommends, Suggests, and Enhances don't need to be "
"tested, and are listed for completeness-sake." "tested, and are listed for completeness-sake.",
] + output ] + output
else: else:
output = ["No reverse dependencies"] output = ["No reverse dependencies"]
@ -162,8 +164,8 @@ def find_rdepends(releases, published_binaries):
def locate_package(package, distribution): def locate_package(package, distribution):
archive = Distribution('ubuntu').getArchive() archive = Distribution("ubuntu").getArchive()
for pass_ in ('source', 'binary'): for pass_ in ("source", "binary"):
try: try:
package_spph = archive.getSourcePackage(package, distribution) package_spph = archive.getSourcePackage(package, distribution)
return package_spph return package_spph
@ -174,8 +176,9 @@ def locate_package(package, distribution):
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
package = apt_pkg.candidate.source_name package = apt_pkg.candidate.source_name
Logger.info("Binary package specified, considering its source " Logger.info(
"package instead: %s", package) "Binary package specified, considering its source package instead: %s", package
)
def request_backport(package_spph, source, destinations): def request_backport(package_spph, source, destinations):
@ -184,67 +187,77 @@ def request_backport(package_spph, source, destinations):
published_binaries.add(bpph.getPackageName()) published_binaries.add(bpph.getPackageName())
if not published_binaries: if not published_binaries:
Logger.error("%s (%s) has no published binaries in %s. ", Logger.error(
package_spph.getPackageName(), package_spph.getVersion(), "%s (%s) has no published binaries in %s. ",
source) package_spph.getPackageName(),
Logger.info("Is it stuck in bin-NEW? It can't be backported until " package_spph.getVersion(),
"the binaries have been accepted.") source,
)
Logger.info(
"Is it stuck in bin-NEW? It can't be backported until "
"the binaries have been accepted."
)
sys.exit(1) sys.exit(1)
testing = ["[Testing]", ""] testing = ["[Testing]", ""]
for dest in destinations: for dest in destinations:
testing += [" * %s:" % dest.capitalize()] testing += [" * %s:" % dest.capitalize()]
testing += [" [ ] Package builds without modification"] testing += [" [ ] Package builds without modification"]
testing += [" [ ] %s installs cleanly and runs" % binary testing += [
for binary in published_binaries] " [ ] %s installs cleanly and runs" % binary for binary in published_binaries
]
subst = { subst = {
'package': package_spph.getPackageName(), "package": package_spph.getPackageName(),
'version': package_spph.getVersion(), "version": package_spph.getVersion(),
'component': package_spph.getComponent(), "component": package_spph.getComponent(),
'source': package_spph.getSeriesAndPocket(), "source": package_spph.getSeriesAndPocket(),
'destinations': ', '.join(destinations), "destinations": ", ".join(destinations),
} }
subject = "[BPO] %(package)s %(version)s to %(destinations)s" % subst subject = "[BPO] %(package)s %(version)s to %(destinations)s" % subst
body = ('\n'.join( body = (
"\n".join(
[ [
"[Impact]", "[Impact]",
"", "",
" * Justification for backporting the new version to the stable release.", " * Justification for backporting the new version to the stable release.",
"", "",
"[Scope]", "[Scope]",
"", "",
" * List the Ubuntu release you will backport from," " * List the Ubuntu release you will backport from,"
" and the specific package version.", " and the specific package version.",
"", "",
" * List the Ubuntu release(s) you will backport to.", " * List the Ubuntu release(s) you will backport to.",
"", "",
"[Other Info]", "[Other Info]",
"", "",
" * Anything else you think is useful to include", " * Anything else you think is useful to include",
"" "",
] ]
+ testing + testing
+ [""] + [""]
+ find_rdepends(destinations, published_binaries) + find_rdepends(destinations, published_binaries)
+ [""]) % subst) + [""]
)
% subst
)
editor = EditBugReport(subject, body) editor = EditBugReport(subject, body)
editor.edit() editor.edit()
subject, body = editor.get_report() subject, body = editor.get_report()
Logger.info('The final report is:\nSummary: %s\nDescription:\n%s\n', Logger.info("The final report is:\nSummary: %s\nDescription:\n%s\n", subject, body)
subject, body)
if YesNoQuestion().ask("Request this backport", "yes") == "no": if YesNoQuestion().ask("Request this backport", "yes") == "no":
sys.exit(1) sys.exit(1)
distro = Distribution('ubuntu') distro = Distribution("ubuntu")
pkgname = package_spph.getPackageName() pkgname = package_spph.getPackageName()
bug = Launchpad.bugs.createBug(title=subject, description=body, bug = Launchpad.bugs.createBug(
target=distro.getSourcePackage(name=pkgname)) title=subject, description=body, target=distro.getSourcePackage(name=pkgname)
)
bug.subscribe(person=Launchpad.people['ubuntu-backporters']) bug.subscribe(person=Launchpad.people["ubuntu-backporters"])
for dest in destinations: for dest in destinations:
series = distro.getSeries(dest) series = distro.getSeries(dest)
@ -257,20 +270,35 @@ def request_backport(package_spph, source, destinations):
def main(): def main():
parser = optparse.OptionParser('%prog [options] package') parser = optparse.OptionParser("%prog [options] package")
parser.add_option('-d', '--destination', metavar='DEST', parser.add_option(
help='Backport to DEST release and necessary ' "-d",
'intermediate releases ' "--destination",
'(default: current LTS release)') metavar="DEST",
parser.add_option('-s', '--source', metavar='SOURCE', help="Backport to DEST release and necessary "
help='Backport from SOURCE release ' "intermediate releases "
'(default: current devel release)') "(default: current LTS release)",
parser.add_option('-l', '--lpinstance', metavar='INSTANCE', default=None, )
help='Launchpad instance to connect to ' parser.add_option(
'(default: production).') "-s",
parser.add_option('--no-conf', action='store_true', "--source",
dest='no_conf', default=False, metavar="SOURCE",
help="Don't read config files or environment variables") help="Backport from SOURCE release (default: current devel release)",
)
parser.add_option(
"-l",
"--lpinstance",
metavar="INSTANCE",
default=None,
help="Launchpad instance to connect to (default: production).",
)
parser.add_option(
"--no-conf",
action="store_true",
dest="no_conf",
default=False,
help="Don't read config files or environment variables",
)
options, args = parser.parse_args() options, args = parser.parse_args()
if len(args) != 1: if len(args) != 1:
@ -280,15 +308,14 @@ def main():
config = UDTConfig(options.no_conf) config = UDTConfig(options.no_conf)
if options.lpinstance is None: if options.lpinstance is None:
options.lpinstance = config.get_value('LPINSTANCE') options.lpinstance = config.get_value("LPINSTANCE")
Launchpad.login(options.lpinstance) Launchpad.login(options.lpinstance)
if options.source is None: if options.source is None:
options.source = Distribution('ubuntu').getDevelopmentSeries().name options.source = Distribution("ubuntu").getDevelopmentSeries().name
try: try:
destinations = determine_destinations(options.source, destinations = determine_destinations(options.source, options.destination)
options.destination)
except DestinationException as e: except DestinationException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
@ -301,5 +328,5 @@ def main():
request_backport(package_spph, options.source, destinations) request_backport(package_spph, options.source, destinations)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -39,6 +39,7 @@ from ubuntutools.question import confirmation_prompt, EditBugReport
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
# #
@ -48,46 +49,78 @@ Logger = getLogger()
def main(): def main():
# Our usage options. # Our usage options.
usage = ('Usage: %prog [options] ' usage = "Usage: %prog [options] <source package> [<target release> [base version]]"
'<source package> [<target release> [base version]]')
parser = optparse.OptionParser(usage) parser = optparse.OptionParser(usage)
parser.add_option('-d', type='string', parser.add_option(
dest='dist', default='unstable', "-d",
help='Debian distribution to sync from.') type="string",
parser.add_option('-k', type='string', dest="dist",
dest='keyid', default=None, default="unstable",
help='GnuPG key ID to use for signing report ' help="Debian distribution to sync from.",
'(only used when emailing the sync request).') )
parser.add_option('-n', action='store_true', parser.add_option(
dest='newpkg', default=False, "-k",
help='Whether package to sync is a new package in ' type="string",
'Ubuntu.') dest="keyid",
parser.add_option('--email', action='store_true', default=False, default=None,
help='Use a PGP-signed email for filing the sync ' help="GnuPG key ID to use for signing report "
'request, rather than the LP API.') "(only used when emailing the sync request).",
parser.add_option('--lp', dest='deprecated_lp_flag', )
action='store_true', default=False, parser.add_option(
help=optparse.SUPPRESS_HELP) "-n",
parser.add_option('-l', '--lpinstance', metavar='INSTANCE', action="store_true",
dest='lpinstance', default=None, dest="newpkg",
help='Launchpad instance to connect to ' default=False,
'(default: production).') help="Whether package to sync is a new package in Ubuntu.",
parser.add_option('-s', action='store_true', )
dest='sponsorship', default=False, parser.add_option(
help='Force sponsorship') "--email",
parser.add_option('-C', action='store_true', action="store_true",
dest='missing_changelog_ok', default=False, default=False,
help='Allow changelog to be manually filled in ' help="Use a PGP-signed email for filing the sync request, rather than the LP API.",
'when missing') )
parser.add_option('-e', action='store_true', parser.add_option(
dest='ffe', default=False, "--lp",
help='Use this after FeatureFreeze for non-bug fix ' dest="deprecated_lp_flag",
'syncs, changes default subscription to the ' action="store_true",
'appropriate release team.') default=False,
parser.add_option('--no-conf', action='store_true', help=optparse.SUPPRESS_HELP,
dest='no_conf', default=False, )
help="Don't read config files or environment variables") parser.add_option(
"-l",
"--lpinstance",
metavar="INSTANCE",
dest="lpinstance",
default=None,
help="Launchpad instance to connect to (default: production).",
)
parser.add_option(
"-s", action="store_true", dest="sponsorship", default=False, help="Force sponsorship"
)
parser.add_option(
"-C",
action="store_true",
dest="missing_changelog_ok",
default=False,
help="Allow changelog to be manually filled in when missing",
)
parser.add_option(
"-e",
action="store_true",
dest="ffe",
default=False,
help="Use this after FeatureFreeze for non-bug fix "
"syncs, changes default subscription to the "
"appropriate release team.",
)
parser.add_option(
"--no-conf",
action="store_true",
dest="no_conf",
default=False,
help="Don't read config files or environment variables",
)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -104,74 +137,78 @@ def main():
if options.email: if options.email:
options.lpapi = False options.lpapi = False
else: else:
options.lpapi = config.get_value('USE_LPAPI', default=True, options.lpapi = config.get_value("USE_LPAPI", default=True, boolean=True)
boolean=True)
if options.lpinstance is None: if options.lpinstance is None:
options.lpinstance = config.get_value('LPINSTANCE') options.lpinstance = config.get_value("LPINSTANCE")
if options.keyid is None: if options.keyid is None:
options.keyid = config.get_value('KEYID') options.keyid = config.get_value("KEYID")
if not options.lpapi: if not options.lpapi:
if options.lpinstance == 'production': if options.lpinstance == "production":
bug_mail_domain = 'bugs.launchpad.net' bug_mail_domain = "bugs.launchpad.net"
elif options.lpinstance == 'staging': elif options.lpinstance == "staging":
bug_mail_domain = 'bugs.staging.launchpad.net' bug_mail_domain = "bugs.staging.launchpad.net"
else: else:
Logger.error('Error: Unknown launchpad instance: %s' Logger.error("Error: Unknown launchpad instance: %s" % options.lpinstance)
% options.lpinstance)
sys.exit(1) sys.exit(1)
mailserver_host = config.get_value('SMTP_SERVER', mailserver_host = config.get_value(
default=None, "SMTP_SERVER", default=None, compat_keys=["UBUSMTP", "DEBSMTP"]
compat_keys=['UBUSMTP', 'DEBSMTP']) )
if not options.lpapi and not mailserver_host: if not options.lpapi and not mailserver_host:
try: try:
import DNS import DNS
DNS.DiscoverNameServers() DNS.DiscoverNameServers()
mxlist = DNS.mxlookup(bug_mail_domain) mxlist = DNS.mxlookup(bug_mail_domain)
firstmx = mxlist[0] firstmx = mxlist[0]
mailserver_host = firstmx[1] mailserver_host = firstmx[1]
except ImportError: except ImportError:
Logger.error('Please install python-dns to support ' Logger.error("Please install python-dns to support Launchpad mail server lookup.")
'Launchpad mail server lookup.')
sys.exit(1) sys.exit(1)
mailserver_port = config.get_value('SMTP_PORT', default=25, mailserver_port = config.get_value(
compat_keys=['UBUSMTP_PORT', "SMTP_PORT", default=25, compat_keys=["UBUSMTP_PORT", "DEBSMTP_PORT"]
'DEBSMTP_PORT']) )
mailserver_user = config.get_value('SMTP_USER', mailserver_user = config.get_value("SMTP_USER", compat_keys=["UBUSMTP_USER", "DEBSMTP_USER"])
compat_keys=['UBUSMTP_USER', mailserver_pass = config.get_value("SMTP_PASS", compat_keys=["UBUSMTP_PASS", "DEBSMTP_PASS"])
'DEBSMTP_USER'])
mailserver_pass = config.get_value('SMTP_PASS',
compat_keys=['UBUSMTP_PASS',
'DEBSMTP_PASS'])
# import the needed requestsync module # import the needed requestsync module
if options.lpapi: if options.lpapi:
from ubuntutools.requestsync.lp import (check_existing_reports, from ubuntutools.requestsync.lp import (
get_debian_srcpkg, check_existing_reports,
get_ubuntu_srcpkg, get_debian_srcpkg,
get_ubuntu_delta_changelog, get_ubuntu_srcpkg,
need_sponsorship, post_bug) get_ubuntu_delta_changelog,
need_sponsorship,
post_bug,
)
from ubuntutools.lp.lpapicache import Distribution, Launchpad from ubuntutools.lp.lpapicache import Distribution, Launchpad
# See if we have LP credentials and exit if we don't - # See if we have LP credentials and exit if we don't -
# cannot continue in this case # cannot continue in this case
try: try:
# devel for changelogUrl() # devel for changelogUrl()
Launchpad.login(service=options.lpinstance, api_version='devel') Launchpad.login(service=options.lpinstance, api_version="devel")
except IOError: except IOError:
sys.exit(1) sys.exit(1)
else: else:
from ubuntutools.requestsync.mail import (check_existing_reports, from ubuntutools.requestsync.mail import (
get_debian_srcpkg, check_existing_reports,
get_ubuntu_srcpkg, get_debian_srcpkg,
get_ubuntu_delta_changelog, get_ubuntu_srcpkg,
mail_bug, need_sponsorship) get_ubuntu_delta_changelog,
if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')): mail_bug,
Logger.error('The environment variable UBUMAIL, DEBEMAIL or EMAIL needs ' need_sponsorship,
'to be set to let this script mail the sync request.') )
if not any(x in os.environ for x in ("UBUMAIL", "DEBEMAIL", "EMAIL")):
Logger.error(
"The environment variable UBUMAIL, DEBEMAIL or EMAIL needs "
"to be set to let this script mail the sync request."
)
sys.exit(1) sys.exit(1)
newsource = options.newpkg newsource = options.newpkg
@ -185,30 +222,30 @@ def main():
if len(args) == 1: if len(args) == 1:
if lpapi: if lpapi:
release = Distribution('ubuntu').getDevelopmentSeries().name release = Distribution("ubuntu").getDevelopmentSeries().name
else: else:
ubu_info = UbuntuDistroInfo() ubu_info = UbuntuDistroInfo()
release = ubu_info.devel() release = ubu_info.devel()
Logger.warning('Target release missing - assuming %s' % release) Logger.warning("Target release missing - assuming %s" % release)
elif len(args) == 2: elif len(args) == 2:
release = args[1] release = args[1]
elif len(args) == 3: elif len(args) == 3:
release = args[1] release = args[1]
force_base_version = Version(args[2]) force_base_version = Version(args[2])
else: else:
Logger.error('Too many arguments.') Logger.error("Too many arguments.")
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
# Get the current Ubuntu source package # Get the current Ubuntu source package
try: try:
ubuntu_srcpkg = get_ubuntu_srcpkg(srcpkg, release, 'Proposed') ubuntu_srcpkg = get_ubuntu_srcpkg(srcpkg, release, "Proposed")
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_version = Version(ubuntu_srcpkg.getVersion())
ubuntu_component = ubuntu_srcpkg.getComponent() ubuntu_component = ubuntu_srcpkg.getComponent()
newsource = False # override the -n flag newsource = False # override the -n flag
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_srcpkg = None ubuntu_srcpkg = None
ubuntu_version = Version('~') ubuntu_version = Version("~")
ubuntu_component = None # Set after getting the Debian info ubuntu_component = None # Set after getting the Debian info
if not newsource: if not newsource:
Logger.info("'%s' doesn't exist in 'Ubuntu %s'." % (srcpkg, release)) Logger.info("'%s' doesn't exist in 'Ubuntu %s'." % (srcpkg, release))
@ -232,15 +269,16 @@ def main():
sys.exit(1) sys.exit(1)
if ubuntu_component is None: if ubuntu_component is None:
if debian_component == 'main': if debian_component == "main":
ubuntu_component = 'universe' ubuntu_component = "universe"
else: else:
ubuntu_component = 'multiverse' ubuntu_component = "multiverse"
# Stop if Ubuntu has already the version from Debian or a newer version # Stop if Ubuntu has already the version from Debian or a newer version
if (ubuntu_version >= debian_version) and options.lpapi: if (ubuntu_version >= debian_version) and options.lpapi:
# try rmadison # try rmadison
import ubuntutools.requestsync.mail import ubuntutools.requestsync.mail
try: try:
debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(srcpkg, distro) debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(srcpkg, distro)
debian_version = Version(debian_srcpkg.getVersion()) debian_version = Version(debian_srcpkg.getVersion())
@ -250,13 +288,16 @@ def main():
sys.exit(1) sys.exit(1)
if ubuntu_version == debian_version: if ubuntu_version == debian_version:
Logger.error('The versions in Debian and Ubuntu are the ' Logger.error(
'same already (%s). Aborting.' % ubuntu_version) "The versions in Debian and Ubuntu are the "
"same already (%s). Aborting." % ubuntu_version
)
sys.exit(1) sys.exit(1)
if ubuntu_version > debian_version: if ubuntu_version > debian_version:
Logger.error('The version in Ubuntu (%s) is newer than ' Logger.error(
'the version in Debian (%s). Aborting.' "The version in Ubuntu (%s) is newer than "
% (ubuntu_version, debian_version)) "the version in Debian (%s). Aborting." % (ubuntu_version, debian_version)
)
sys.exit(1) sys.exit(1)
# -s flag not specified - check if we do need sponsorship # -s flag not specified - check if we do need sponsorship
@ -264,40 +305,47 @@ def main():
sponsorship = need_sponsorship(srcpkg, ubuntu_component, release) sponsorship = need_sponsorship(srcpkg, ubuntu_component, release)
if not sponsorship and not ffe: if not sponsorship and not ffe:
Logger.error('Consider using syncpackage(1) for syncs that ' Logger.error(
'do not require feature freeze exceptions.') "Consider using syncpackage(1) for syncs that "
"do not require feature freeze exceptions."
)
# Check for existing package reports # Check for existing package reports
if not newsource: if not newsource:
check_existing_reports(srcpkg) check_existing_reports(srcpkg)
# Generate bug report # Generate bug report
pkg_to_sync = ('%s %s (%s) from Debian %s (%s)' pkg_to_sync = "%s %s (%s) from Debian %s (%s)" % (
% (srcpkg, debian_version, ubuntu_component, srcpkg,
distro, debian_component)) debian_version,
ubuntu_component,
distro,
debian_component,
)
title = "Sync %s" % pkg_to_sync title = "Sync %s" % pkg_to_sync
if ffe: if ffe:
title = "FFe: " + title title = "FFe: " + title
report = "Please sync %s\n\n" % pkg_to_sync report = "Please sync %s\n\n" % pkg_to_sync
if 'ubuntu' in str(ubuntu_version): if "ubuntu" in str(ubuntu_version):
need_interaction = True need_interaction = True
Logger.info('Changes have been made to the package in Ubuntu.') Logger.info("Changes have been made to the package in Ubuntu.")
Logger.info('Please edit the report and give an explanation.') Logger.info("Please edit the report and give an explanation.")
Logger.info('Not saving the report file will abort the request.') Logger.info("Not saving the report file will abort the request.")
report += ('Explanation of the Ubuntu delta and why it can be ' report += (
'dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n' "Explanation of the Ubuntu delta and why it can be "
% get_ubuntu_delta_changelog(ubuntu_srcpkg)) "dropped:\n%s\n>>> ENTER_EXPLANATION_HERE <<<\n\n"
% get_ubuntu_delta_changelog(ubuntu_srcpkg)
)
if ffe: if ffe:
need_interaction = True need_interaction = True
Logger.info('To approve FeatureFreeze exception, you need to state') Logger.info("To approve FeatureFreeze exception, you need to state")
Logger.info('the reason why you feel it is necessary.') Logger.info("the reason why you feel it is necessary.")
Logger.info('Not saving the report file will abort the request.') Logger.info("Not saving the report file will abort the request.")
report += ('Explanation of FeatureFreeze exception:\n' report += "Explanation of FeatureFreeze exception:\n>>> ENTER_EXPLANATION_HERE <<<\n\n"
'>>> ENTER_EXPLANATION_HERE <<<\n\n')
if need_interaction: if need_interaction:
confirmation_prompt() confirmation_prompt()
@ -305,17 +353,18 @@ def main():
base_version = force_base_version or ubuntu_version base_version = force_base_version or ubuntu_version
if newsource: if newsource:
report += 'All changelog entries:\n\n' report += "All changelog entries:\n\n"
else: else:
report += ('Changelog entries since current %s version %s:\n\n' report += "Changelog entries since current %s version %s:\n\n" % (release, ubuntu_version)
% (release, ubuntu_version))
changelog = debian_srcpkg.getChangelog(since_version=base_version) changelog = debian_srcpkg.getChangelog(since_version=base_version)
if not changelog: if not changelog:
if not options.missing_changelog_ok: if not options.missing_changelog_ok:
Logger.error("Did not retrieve any changelog entries. " Logger.error(
"Do you need to specify '-C'? " "Did not retrieve any changelog entries. "
"Was the package recently uploaded? (check " "Do you need to specify '-C'? "
"http://packages.debian.org/changelogs/)") "Was the package recently uploaded? (check "
"http://packages.debian.org/changelogs/)"
)
sys.exit(1) sys.exit(1)
else: else:
need_interaction = True need_interaction = True
@ -326,36 +375,49 @@ def main():
editor.edit(optional=not need_interaction) editor.edit(optional=not need_interaction)
title, report = editor.get_report() title, report = editor.get_report()
if 'XXX FIXME' in report: if "XXX FIXME" in report:
Logger.error("changelog boilerplate found in report, " Logger.error(
"please manually add changelog when using '-C'") "changelog boilerplate found in report, "
"please manually add changelog when using '-C'"
)
sys.exit(1) sys.exit(1)
# bug status and bug subscriber # bug status and bug subscriber
status = 'confirmed' status = "confirmed"
subscribe = 'ubuntu-archive' subscribe = "ubuntu-archive"
if sponsorship: if sponsorship:
status = 'new' status = "new"
subscribe = 'ubuntu-sponsors' subscribe = "ubuntu-sponsors"
if ffe: if ffe:
status = 'new' status = "new"
subscribe = 'ubuntu-release' subscribe = "ubuntu-release"
srcpkg = not newsource and srcpkg or None srcpkg = not newsource and srcpkg or None
if lpapi: if lpapi:
# Map status to the values expected by LP API # Map status to the values expected by LP API
mapping = {'new': 'New', 'confirmed': 'Confirmed'} mapping = {"new": "New", "confirmed": "Confirmed"}
# Post sync request using LP API # Post sync request using LP API
post_bug(srcpkg, subscribe, mapping[status], title, report) post_bug(srcpkg, subscribe, mapping[status], title, report)
else: else:
email_from = ubu_email(export=False)[1] email_from = ubu_email(export=False)[1]
# Mail sync request # Mail sync request
mail_bug(srcpkg, subscribe, status, title, report, bug_mail_domain, mail_bug(
options.keyid, email_from, mailserver_host, mailserver_port, srcpkg,
mailserver_user, mailserver_pass) subscribe,
status,
title,
report,
bug_mail_domain,
options.keyid,
email_from,
mailserver_host,
mailserver_port,
mailserver_user,
mailserver_pass,
)
if __name__ == '__main__': if __name__ == "__main__":
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -19,11 +19,11 @@ import sys
from distro_info import DistroDataOutdated from distro_info import DistroDataOutdated
from ubuntutools.misc import (system_distribution, vendor_to_distroinfo, from ubuntutools.misc import system_distribution, vendor_to_distroinfo, codename_to_distribution
codename_to_distribution)
from ubuntutools.rdepends import query_rdepends, RDependsException from ubuntutools.rdepends import query_rdepends, RDependsException
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
DEFAULT_MAX_DEPTH = 10 # We want avoid any infinite loop... DEFAULT_MAX_DEPTH = 10 # We want avoid any infinite loop...
@ -35,77 +35,107 @@ def main():
default_release = system_distro_info.devel() default_release = system_distro_info.devel()
except DistroDataOutdated as e: except DistroDataOutdated as e:
Logger.warning(e) Logger.warning(e)
default_release = 'unstable' default_release = "unstable"
description = ("List reverse-dependencies of package. " description = (
"If the package name is prefixed with src: then the " "List reverse-dependencies of package. "
"reverse-dependencies of all the binary packages that " "If the package name is prefixed with src: then the "
"the specified source package builds will be listed.") "reverse-dependencies of all the binary packages that "
"the specified source package builds will be listed."
)
parser = argparse.ArgumentParser(description=description) parser = argparse.ArgumentParser(description=description)
parser.add_argument('-r', '--release', default=default_release, parser.add_argument(
help='Query dependencies in RELEASE. ' "-r",
'Default: %s' % default_release) "--release",
parser.add_argument('-R', '--without-recommends', action='store_false', default=default_release,
dest='recommends', help="Query dependencies in RELEASE. Default: %s" % default_release,
help='Only consider Depends relationships, ' )
'not Recommends') parser.add_argument(
parser.add_argument('-s', '--with-suggests', action='store_true', "-R",
help='Also consider Suggests relationships') "--without-recommends",
parser.add_argument('-b', '--build-depends', action='store_true', action="store_false",
help='Query build dependencies (synonym for --arch=source)') dest="recommends",
parser.add_argument('-a', '--arch', default='any', help="Only consider Depends relationships, not Recommends",
help='Query dependencies in ARCH. Default: any') )
parser.add_argument('-c', '--component', action='append', parser.add_argument(
help='Only consider reverse-dependencies in COMPONENT. ' "-s", "--with-suggests", action="store_true", help="Also consider Suggests relationships"
'Can be specified multiple times. Default: all') )
parser.add_argument('-l', '--list', action='store_true', parser.add_argument(
help='Display a simple, machine-readable list') "-b",
parser.add_argument('-u', '--service-url', metavar='URL', "--build-depends",
dest='server', default=None, action="store_true",
help='Reverse Dependencies webservice URL. ' help="Query build dependencies (synonym for --arch=source)",
'Default: UbuntuWire') )
parser.add_argument('-x', '--recursive', action='store_true', parser.add_argument(
help='Consider to find reverse dependencies recursively.') "-a", "--arch", default="any", help="Query dependencies in ARCH. Default: any"
parser.add_argument('-d', '--recursive-depth', type=int, )
default=DEFAULT_MAX_DEPTH, parser.add_argument(
help='If recusive, you can specify the depth.') "-c",
parser.add_argument('package') "--component",
action="append",
help="Only consider reverse-dependencies in COMPONENT. "
"Can be specified multiple times. Default: all",
)
parser.add_argument(
"-l", "--list", action="store_true", help="Display a simple, machine-readable list"
)
parser.add_argument(
"-u",
"--service-url",
metavar="URL",
dest="server",
default=None,
help="Reverse Dependencies webservice URL. Default: UbuntuWire",
)
parser.add_argument(
"-x",
"--recursive",
action="store_true",
help="Consider to find reverse dependencies recursively.",
)
parser.add_argument(
"-d",
"--recursive-depth",
type=int,
default=DEFAULT_MAX_DEPTH,
help="If recusive, you can specify the depth.",
)
parser.add_argument("package")
options = parser.parse_args() options = parser.parse_args()
opts = {} opts = {}
if options.server is not None: if options.server is not None:
opts['server'] = options.server opts["server"] = options.server
# Convert unstable/testing aliases to codenames: # Convert unstable/testing aliases to codenames:
distribution = codename_to_distribution(options.release) distribution = codename_to_distribution(options.release)
if not distribution: if not distribution:
parser.error('Unknown release codename %s' % options.release) parser.error("Unknown release codename %s" % options.release)
distro_info = vendor_to_distroinfo(distribution)() distro_info = vendor_to_distroinfo(distribution)()
try: try:
options.release = distro_info.codename(options.release, options.release = distro_info.codename(options.release, default=options.release)
default=options.release)
except DistroDataOutdated: except DistroDataOutdated:
# We already logged a warning # We already logged a warning
pass pass
if options.build_depends: if options.build_depends:
options.arch = 'source' options.arch = "source"
if options.arch == 'source': if options.arch == "source":
fields = [ fields = [
'Reverse-Build-Depends', "Reverse-Build-Depends",
'Reverse-Build-Depends-Indep', "Reverse-Build-Depends-Indep",
'Reverse-Build-Depends-Arch', "Reverse-Build-Depends-Arch",
'Reverse-Testsuite-Triggers', "Reverse-Testsuite-Triggers",
] ]
else: else:
fields = ['Reverse-Depends'] fields = ["Reverse-Depends"]
if options.recommends: if options.recommends:
fields.append('Reverse-Recommends') fields.append("Reverse-Recommends")
if options.with_suggests: if options.with_suggests:
fields.append('Reverse-Suggests') fields.append("Reverse-Suggests")
def build_results(package, result, fields, component, recursive): def build_results(package, result, fields, component, recursive):
try: try:
@ -119,9 +149,9 @@ def main():
if fields: if fields:
data = {k: v for k, v in data.items() if k in fields} data = {k: v for k, v in data.items() if k in fields}
if component: if component:
data = {k: [rdep for rdep in v data = {
if rdep['Component'] in component] k: [rdep for rdep in v if rdep["Component"] in component] for k, v in data.items()
for k, v in data.items()} }
data = {k: v for k, v in data.items() if v} data = {k: v for k, v in data.items() if v}
result[package] = data result[package] = data
@ -129,13 +159,16 @@ def main():
if recursive > 0: if recursive > 0:
for rdeps in result[package].values(): for rdeps in result[package].values():
for rdep in rdeps: for rdep in rdeps:
build_results( build_results(rdep["Package"], result, fields, component, recursive - 1)
rdep['Package'], result, fields, component, recursive - 1)
result = {} result = {}
build_results( build_results(
options.package, result, fields, options.component, options.package,
options.recursive and options.recursive_depth or 0) result,
fields,
options.component,
options.recursive and options.recursive_depth or 0,
)
if options.list: if options.list:
display_consise(result) display_consise(result)
@ -150,50 +183,55 @@ def display_verbose(package, values):
def log_field(field): def log_field(field):
Logger.info(field) Logger.info(field)
Logger.info('=' * len(field)) Logger.info("=" * len(field))
def log_package(values, package, arch, dependency, offset=0): def log_package(values, package, arch, dependency, offset=0):
line = ' ' * offset + '* %s' % package line = " " * offset + "* %s" % package
if all_archs and set(arch) != all_archs: if all_archs and set(arch) != all_archs:
line += ' [%s]' % ' '.join(sorted(arch)) line += " [%s]" % " ".join(sorted(arch))
if dependency: if dependency:
if len(line) < 30: if len(line) < 30:
line += ' ' * (30 - len(line)) line += " " * (30 - len(line))
line += ' (for %s)' % dependency line += " (for %s)" % dependency
Logger.info(line) Logger.info(line)
data = values.get(package) data = values.get(package)
if data: if data:
offset = offset + 1 offset = offset + 1
for rdeps in data.values(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
log_package(values, log_package(
rdep['Package'], values,
rdep.get('Architectures', all_archs), rdep["Package"],
rdep.get('Dependency'), rdep.get("Architectures", all_archs),
offset) rdep.get("Dependency"),
offset,
)
all_archs = set() all_archs = set()
# This isn't accurate, but we make up for it by displaying what we found # This isn't accurate, but we make up for it by displaying what we found
for data in values.values(): for data in values.values():
for rdeps in data.values(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
if 'Architectures' in rdep: if "Architectures" in rdep:
all_archs.update(rdep['Architectures']) all_archs.update(rdep["Architectures"])
for field, rdeps in values[package].items(): for field, rdeps in values[package].items():
Logger.info(field) Logger.info(field)
rdeps.sort(key=lambda x: x['Package']) rdeps.sort(key=lambda x: x["Package"])
for rdep in rdeps: for rdep in rdeps:
log_package(values, log_package(
rdep['Package'], values,
rdep.get('Architectures', all_archs), rdep["Package"],
rdep.get('Dependency')) rdep.get("Architectures", all_archs),
rdep.get("Dependency"),
)
Logger.info("") Logger.info("")
if all_archs: if all_archs:
Logger.info("Packages without architectures listed are " Logger.info(
"reverse-dependencies in: %s" "Packages without architectures listed are "
% ', '.join(sorted(list(all_archs)))) "reverse-dependencies in: %s" % ", ".join(sorted(list(all_archs)))
)
def display_consise(values): def display_consise(values):
@ -201,10 +239,10 @@ def display_consise(values):
for data in values.values(): for data in values.values():
for rdeps in data.values(): for rdeps in data.values():
for rdep in rdeps: for rdep in rdeps:
result.add(rdep['Package']) result.add(rdep["Package"])
Logger.info('\n'.join(sorted(list(result)))) Logger.info("\n".join(sorted(list(result))))
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -7,4 +7,4 @@ set -eu
PYTHON_SCRIPTS=$(grep -l -r '^#! */usr/bin/python3$' .) PYTHON_SCRIPTS=$(grep -l -r '^#! */usr/bin/python3$' .)
echo "Running flake8..." echo "Running flake8..."
flake8 --max-line-length=99 . $PYTHON_SCRIPTS flake8 --max-line-length=99 --ignore=E203,W503 . $PYTHON_SCRIPTS

View File

@ -22,43 +22,42 @@ import os
import time import time
import urllib.request import urllib.request
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, from ubuntutools.lp.lpapicache import Distribution, Launchpad, PackageNotFoundException
PackageNotFoundException)
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
DATA_URL = 'http://qa.ubuntuwire.org/ubuntu-seeded-packages/seeded.json.gz' DATA_URL = "http://qa.ubuntuwire.org/ubuntu-seeded-packages/seeded.json.gz"
def load_index(url): def load_index(url):
'''Download a new copy of the image contents index, if necessary, """Download a new copy of the image contents index, if necessary,
and read it. and read it.
''' """
cachedir = os.path.expanduser('~/.cache/ubuntu-dev-tools') cachedir = os.path.expanduser("~/.cache/ubuntu-dev-tools")
fn = os.path.join(cachedir, 'seeded.json.gz') fn = os.path.join(cachedir, "seeded.json.gz")
if (not os.path.isfile(fn) if not os.path.isfile(fn) or time.time() - os.path.getmtime(fn) > 60 * 60 * 2:
or time.time() - os.path.getmtime(fn) > 60 * 60 * 2):
if not os.path.isdir(cachedir): if not os.path.isdir(cachedir):
os.makedirs(cachedir) os.makedirs(cachedir)
urllib.request.urlretrieve(url, fn) urllib.request.urlretrieve(url, fn)
try: try:
with gzip.open(fn, 'r') as f: with gzip.open(fn, "r") as f:
return json.load(f) return json.load(f)
except Exception as e: except Exception as e:
Logger.error("Unable to parse seed data: %s. " Logger.error(
"Deleting cached data, please try again.", "Unable to parse seed data: %s. Deleting cached data, please try again.", str(e)
str(e)) )
os.unlink(fn) os.unlink(fn)
def resolve_binaries(sources): def resolve_binaries(sources):
'''Return a dict of source:binaries for all binary packages built by """Return a dict of source:binaries for all binary packages built by
sources sources
''' """
archive = Distribution('ubuntu').getArchive() archive = Distribution("ubuntu").getArchive()
binaries = {} binaries = {}
for source in sources: for source in sources:
try: try:
@ -66,28 +65,26 @@ def resolve_binaries(sources):
except PackageNotFoundException as e: except PackageNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
continue continue
binaries[source] = sorted(set(bpph.getPackageName() binaries[source] = sorted(set(bpph.getPackageName() for bpph in spph.getBinaries()))
for bpph in spph.getBinaries()))
return binaries return binaries
def present_on(appearences): def present_on(appearences):
'''Format a list of (flavor, type) tuples into a human-readable string''' """Format a list of (flavor, type) tuples into a human-readable string"""
present = collections.defaultdict(set) present = collections.defaultdict(set)
for flavor, type_ in appearences: for flavor, type_ in appearences:
present[flavor].add(type_) present[flavor].add(type_)
for flavor, types in present.items(): for flavor, types in present.items():
if len(types) > 1: if len(types) > 1:
types.discard('supported') types.discard("supported")
output = [' %s: %s' % (flavor, ', '.join(sorted(types))) output = [" %s: %s" % (flavor, ", ".join(sorted(types))) for flavor, types in present.items()]
for flavor, types in present.items()]
output.sort() output.sort()
return '\n'.join(output) return "\n".join(output)
def output_binaries(index, binaries): def output_binaries(index, binaries):
'''Print binaries found in index''' """Print binaries found in index"""
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
Logger.info("%s is seeded in:" % binary) Logger.info("%s is seeded in:" % binary)
@ -97,13 +94,14 @@ def output_binaries(index, binaries):
def output_by_source(index, by_source): def output_by_source(index, by_source):
'''Logger.Info(binaries found in index. Grouped by source''' """Logger.Info(binaries found in index. Grouped by source"""
for source, binaries in by_source.items(): for source, binaries in by_source.items():
seen = False seen = False
if not binaries: if not binaries:
Logger.info("Status unknown: No binary packages built by the latest " Logger.info(
"%s.\nTry again using -b and the expected binary packages." "Status unknown: No binary packages built by the latest "
% source) "%s.\nTry again using -b and the expected binary packages." % source
)
continue continue
for binary in binaries: for binary in binaries:
if binary in index: if binary in index:
@ -115,16 +113,22 @@ def output_by_source(index, by_source):
def main(): def main():
'''Query which images the specified packages are on''' """Query which images the specified packages are on"""
parser = optparse.OptionParser('%prog [options] package...') parser = optparse.OptionParser("%prog [options] package...")
parser.add_option('-b', '--binary', parser.add_option(
default=False, action='store_true', "-b",
help="Binary packages are being specified, " "--binary",
"not source packages (fast)") default=False,
parser.add_option('-u', '--data-url', metavar='URL', action="store_true",
default=DATA_URL, help="Binary packages are being specified, not source packages (fast)",
help='URL for the seeded packages index. ' )
'Default: UbuntuWire') parser.add_option(
"-u",
"--data-url",
metavar="URL",
default=DATA_URL,
help="URL for the seeded packages index. Default: UbuntuWire",
)
options, args = parser.parse_args() options, args = parser.parse_args()
if len(args) < 1: if len(args) < 1:
@ -141,5 +145,5 @@ def main():
output_by_source(index, binaries) output_by_source(index, binaries)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

110
setup.py
View File

@ -21,74 +21,74 @@ def make_pep440_compliant(version: str) -> str:
# look/set what version we have # look/set what version we have
changelog = "debian/changelog" changelog = "debian/changelog"
if os.path.exists(changelog): if os.path.exists(changelog):
head = open(changelog, 'r', encoding='utf-8').readline() head = open(changelog, "r", encoding="utf-8").readline()
match = re.compile(r".*\((.*)\).*").match(head) match = re.compile(r".*\((.*)\).*").match(head)
if match: if match:
version = match.group(1) version = match.group(1)
scripts = [ scripts = [
'backportpackage', "backportpackage",
'bitesize', "bitesize",
'check-mir', "check-mir",
'check-symbols', "check-symbols",
'dch-repeat', "dch-repeat",
'grab-merge', "grab-merge",
'grep-merges', "grep-merges",
'import-bug-from-debian', "import-bug-from-debian",
'merge-changelog', "merge-changelog",
'mk-sbuild', "mk-sbuild",
'pbuilder-dist', "pbuilder-dist",
'pbuilder-dist-simple', "pbuilder-dist-simple",
'pull-pkg', "pull-pkg",
'pull-debian-debdiff', "pull-debian-debdiff",
'pull-debian-source', "pull-debian-source",
'pull-debian-debs', "pull-debian-debs",
'pull-debian-ddebs', "pull-debian-ddebs",
'pull-debian-udebs', "pull-debian-udebs",
'pull-lp-source', "pull-lp-source",
'pull-lp-debs', "pull-lp-debs",
'pull-lp-ddebs', "pull-lp-ddebs",
'pull-lp-udebs', "pull-lp-udebs",
'pull-ppa-source', "pull-ppa-source",
'pull-ppa-debs', "pull-ppa-debs",
'pull-ppa-ddebs', "pull-ppa-ddebs",
'pull-ppa-udebs', "pull-ppa-udebs",
'pull-uca-source', "pull-uca-source",
'pull-uca-debs', "pull-uca-debs",
'pull-uca-ddebs', "pull-uca-ddebs",
'pull-uca-udebs', "pull-uca-udebs",
'requestbackport', "requestbackport",
'requestsync', "requestsync",
'reverse-depends', "reverse-depends",
'seeded-in-ubuntu', "seeded-in-ubuntu",
'setup-packaging-environment', "setup-packaging-environment",
'sponsor-patch', "sponsor-patch",
'submittodebian', "submittodebian",
'syncpackage', "syncpackage",
'ubuntu-build', "ubuntu-build",
'ubuntu-iso', "ubuntu-iso",
'ubuntu-upload-permission', "ubuntu-upload-permission",
'update-maintainer', "update-maintainer",
] ]
data_files = [ data_files = [
('share/bash-completion/completions', glob.glob("bash_completion/*")), ("share/bash-completion/completions", glob.glob("bash_completion/*")),
('share/man/man1', glob.glob("doc/*.1")), ("share/man/man1", glob.glob("doc/*.1")),
('share/man/man5', glob.glob("doc/*.5")), ("share/man/man5", glob.glob("doc/*.5")),
('share/ubuntu-dev-tools', ['enforced-editing-wrapper']), ("share/ubuntu-dev-tools", ["enforced-editing-wrapper"]),
] ]
if __name__ == '__main__': if __name__ == "__main__":
setup( setup(
name='ubuntu-dev-tools', name="ubuntu-dev-tools",
version=make_pep440_compliant(version), version=make_pep440_compliant(version),
scripts=scripts, scripts=scripts,
packages=[ packages=[
'ubuntutools', "ubuntutools",
'ubuntutools/lp', "ubuntutools/lp",
'ubuntutools/requestsync', "ubuntutools/requestsync",
'ubuntutools/sponsor_patch', "ubuntutools/sponsor_patch",
'ubuntutools/test', "ubuntutools/test",
], ],
data_files=data_files, data_files=data_files,
test_suite='ubuntutools.test', test_suite="ubuntutools.test",
) )

View File

@ -26,45 +26,103 @@ from ubuntutools.config import UDTConfig
from ubuntutools.sponsor_patch.sponsor_patch import sponsor_patch, check_dependencies from ubuntutools.sponsor_patch.sponsor_patch import sponsor_patch, check_dependencies
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def parse(script_name): def parse(script_name):
"""Parse the command line parameters.""" """Parse the command line parameters."""
usage = ("%s [options] <bug number>\n" % (script_name) usage = (
+ "One of --upload, --workdir, or --sponsor must be specified.") "%s [options] <bug number>\n" % (script_name)
+ "One of --upload, --workdir, or --sponsor must be specified."
)
epilog = "See %s(1) for more info." % (script_name) epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog) parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-b", "--build", dest="build", parser.add_option(
help="Build the package with the specified builder.", "-b",
action="store_true", default=False) "--build",
parser.add_option("-B", "--builder", dest="builder", default=None, dest="build",
help="Specify the package builder (default pbuilder)") help="Build the package with the specified builder.",
parser.add_option("-e", "--edit", action="store_true",
help="launch sub-shell to allow editing of the patch", default=False,
dest="edit", action="store_true", default=False) )
parser.add_option("-k", "--key", dest="keyid", default=None, parser.add_option(
help="Specify the key ID to be used for signing.") "-B",
parser.add_option("-l", "--lpinstance", dest="lpinstance", default=None, "--builder",
help="Launchpad instance to connect to " dest="builder",
"(default: production)", default=None,
metavar="INSTANCE") help="Specify the package builder (default pbuilder)",
parser.add_option("--no-conf", dest="no_conf", default=False, )
help="Don't read config files or environment variables.", parser.add_option(
action="store_true") "-e",
parser.add_option("-s", "--sponsor", help="sponsoring; equals -b -u ubuntu", "--edit",
dest="sponsoring", action="store_true", default=False) help="launch sub-shell to allow editing of the patch",
parser.add_option("-u", "--upload", dest="upload", default=None, dest="edit",
help="Specify an upload destination (default none).") action="store_true",
parser.add_option("-U", "--update", dest="update", default=False, default=False,
action="store_true", )
help="Update the build environment before building.") parser.add_option(
parser.add_option("-v", "--verbose", help="print more information", "-k",
dest="verbose", action="store_true", default=False) "--key",
parser.add_option("-w", "--workdir", dest="workdir", default=None, dest="keyid",
help="Specify a working directory (default is a " default=None,
"temporary directory, deleted afterwards).") help="Specify the key ID to be used for signing.",
)
parser.add_option(
"-l",
"--lpinstance",
dest="lpinstance",
default=None,
help="Launchpad instance to connect to (default: production)",
metavar="INSTANCE",
)
parser.add_option(
"--no-conf",
dest="no_conf",
default=False,
help="Don't read config files or environment variables.",
action="store_true",
)
parser.add_option(
"-s",
"--sponsor",
help="sponsoring; equals -b -u ubuntu",
dest="sponsoring",
action="store_true",
default=False,
)
parser.add_option(
"-u",
"--upload",
dest="upload",
default=None,
help="Specify an upload destination (default none).",
)
parser.add_option(
"-U",
"--update",
dest="update",
default=False,
action="store_true",
help="Update the build environment before building.",
)
parser.add_option(
"-v",
"--verbose",
help="print more information",
dest="verbose",
action="store_true",
default=False,
)
parser.add_option(
"-w",
"--workdir",
dest="workdir",
default=None,
help="Specify a working directory (default is a "
"temporary directory, deleted afterwards).",
)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.verbose: if options.verbose:
@ -113,19 +171,26 @@ def main():
sys.exit(1) sys.exit(1)
if not options.upload and not options.workdir: if not options.upload and not options.workdir:
Logger.error("Please specify either a working directory or an upload " Logger.error("Please specify either a working directory or an upload target!")
"target!")
sys.exit(1) sys.exit(1)
if options.workdir is None: if options.workdir is None:
workdir = tempfile.mkdtemp(prefix=script_name+"-") workdir = tempfile.mkdtemp(prefix=script_name + "-")
else: else:
workdir = options.workdir workdir = options.workdir
try: try:
sponsor_patch(bug_number, options.build, builder, options.edit, sponsor_patch(
options.keyid, options.lpinstance, options.update, bug_number,
options.upload, workdir) options.build,
builder,
options.edit,
options.keyid,
options.lpinstance,
options.update,
options.upload,
workdir,
)
except KeyboardInterrupt: except KeyboardInterrupt:
Logger.error("User abort.") Logger.error("User abort.")
sys.exit(2) sys.exit(2)

View File

@ -40,13 +40,14 @@ from ubuntutools.question import YesNoQuestion, EditFile
from ubuntutools.update_maintainer import update_maintainer, restore_maintainer from ubuntutools.update_maintainer import update_maintainer, restore_maintainer
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def get_most_recent_debian_version(changelog): def get_most_recent_debian_version(changelog):
for block in changelog: for block in changelog:
version = block.version.full_version version = block.version.full_version
if not re.search('(ubuntu|build)', version): if not re.search("(ubuntu|build)", version):
return version return version
@ -65,19 +66,20 @@ In Ubuntu, the attached patch was applied to achieve the following:
%s %s
Thanks for considering the patch. Thanks for considering the patch.
""" % ("\n".join([a for a in entry.changes()])) """ % (
"\n".join([a for a in entry.changes()])
)
return msg return msg
def build_source_package(): def build_source_package():
if os.path.isdir('.bzr'): if os.path.isdir(".bzr"):
cmd = ['bzr', 'bd', '--builder=dpkg-buildpackage', '-S', cmd = ["bzr", "bd", "--builder=dpkg-buildpackage", "-S", "--", "-uc", "-us", "-nc"]
'--', '-uc', '-us', '-nc']
else: else:
cmd = ['dpkg-buildpackage', '-S', '-uc', '-us', '-nc'] cmd = ["dpkg-buildpackage", "-S", "-uc", "-us", "-nc"]
env = os.environ.copy() env = os.environ.copy()
# Unset DEBEMAIL in case there's an @ubuntu.com e-mail address # Unset DEBEMAIL in case there's an @ubuntu.com e-mail address
env.pop('DEBEMAIL', None) env.pop("DEBEMAIL", None)
check_call(cmd, env=env) check_call(cmd, env=env)
@ -88,30 +90,34 @@ def gen_debdiff(tmpdir, changelog):
newver = next(changelog_it).version newver = next(changelog_it).version
oldver = next(changelog_it).version oldver = next(changelog_it).version
debdiff = os.path.join(tmpdir, '%s_%s.debdiff' % (pkg, newver)) debdiff = os.path.join(tmpdir, "%s_%s.debdiff" % (pkg, newver))
diff_cmd = ['bzr', 'diff', '-r', 'tag:' + str(oldver)] diff_cmd = ["bzr", "diff", "-r", "tag:" + str(oldver)]
if call(diff_cmd, stdout=DEVNULL, stderr=DEVNULL) == 1: if call(diff_cmd, stdout=DEVNULL, stderr=DEVNULL) == 1:
Logger.info("Extracting bzr diff between %s and %s" % (oldver, newver)) Logger.info("Extracting bzr diff between %s and %s" % (oldver, newver))
else: else:
if oldver.epoch is not None: if oldver.epoch is not None:
oldver = str(oldver)[str(oldver).index(":") + 1:] oldver = str(oldver)[str(oldver).index(":") + 1 :]
if newver.epoch is not None: if newver.epoch is not None:
newver = str(newver)[str(newver).index(":") + 1:] newver = str(newver)[str(newver).index(":") + 1 :]
olddsc = '../%s_%s.dsc' % (pkg, oldver) olddsc = "../%s_%s.dsc" % (pkg, oldver)
newdsc = '../%s_%s.dsc' % (pkg, newver) newdsc = "../%s_%s.dsc" % (pkg, newver)
check_file(olddsc) check_file(olddsc)
check_file(newdsc) check_file(newdsc)
Logger.info("Generating debdiff between %s and %s" % (oldver, newver)) Logger.info("Generating debdiff between %s and %s" % (oldver, newver))
diff_cmd = ['debdiff', olddsc, newdsc] diff_cmd = ["debdiff", olddsc, newdsc]
with Popen(diff_cmd, stdout=PIPE, encoding='utf-8') as diff: with Popen(diff_cmd, stdout=PIPE, encoding="utf-8") as diff:
with open(debdiff, 'w', encoding='utf-8') as debdiff_f: with open(debdiff, "w", encoding="utf-8") as debdiff_f:
run(['filterdiff', '-x', '*changelog*'], run(
stdin=diff.stdout, stdout=debdiff_f, encoding='utf-8') ["filterdiff", "-x", "*changelog*"],
stdin=diff.stdout,
stdout=debdiff_f,
encoding="utf-8",
)
return debdiff return debdiff
@ -131,57 +137,65 @@ def submit_bugreport(body, debdiff, deb_version, changelog):
devel = UbuntuDistroInfo().devel() devel = UbuntuDistroInfo().devel()
except DistroDataOutdated as e: except DistroDataOutdated as e:
Logger.info(str(e)) Logger.info(str(e))
devel = '' devel = ""
if os.path.dirname(sys.argv[0]).startswith('/usr/bin'): if os.path.dirname(sys.argv[0]).startswith("/usr/bin"):
editor_path = '/usr/share/ubuntu-dev-tools' editor_path = "/usr/share/ubuntu-dev-tools"
else: else:
editor_path = os.path.dirname(sys.argv[0]) editor_path = os.path.dirname(sys.argv[0])
env = dict(os.environ.items()) env = dict(os.environ.items())
if 'EDITOR' in env: if "EDITOR" in env:
env['UDT_EDIT_WRAPPER_EDITOR'] = env['EDITOR'] env["UDT_EDIT_WRAPPER_EDITOR"] = env["EDITOR"]
if 'VISUAL' in env: if "VISUAL" in env:
env['UDT_EDIT_WRAPPER_VISUAL'] = env['VISUAL'] env["UDT_EDIT_WRAPPER_VISUAL"] = env["VISUAL"]
env['EDITOR'] = os.path.join(editor_path, 'enforced-editing-wrapper') env["EDITOR"] = os.path.join(editor_path, "enforced-editing-wrapper")
env['VISUAL'] = os.path.join(editor_path, 'enforced-editing-wrapper') env["VISUAL"] = os.path.join(editor_path, "enforced-editing-wrapper")
env['UDT_EDIT_WRAPPER_TEMPLATE_RE'] = ( env["UDT_EDIT_WRAPPER_TEMPLATE_RE"] = ".*REPLACE THIS WITH ACTUAL INFORMATION.*"
'.*REPLACE THIS WITH ACTUAL INFORMATION.*') env["UDT_EDIT_WRAPPER_FILE_DESCRIPTION"] = "bug report"
env['UDT_EDIT_WRAPPER_FILE_DESCRIPTION'] = 'bug report'
# In external mua mode, attachments are lost (Reportbug bug: #679907) # In external mua mode, attachments are lost (Reportbug bug: #679907)
internal_mua = True internal_mua = True
for cfgfile in ('/etc/reportbug.conf', '~/.reportbugrc'): for cfgfile in ("/etc/reportbug.conf", "~/.reportbugrc"):
cfgfile = os.path.expanduser(cfgfile) cfgfile = os.path.expanduser(cfgfile)
if not os.path.exists(cfgfile): if not os.path.exists(cfgfile):
continue continue
with open(cfgfile, 'r') as f: with open(cfgfile, "r") as f:
for line in f: for line in f:
line = line.strip() line = line.strip()
if line in ('gnus', 'mutt', 'nmh') or line.startswith('mua '): if line in ("gnus", "mutt", "nmh") or line.startswith("mua "):
internal_mua = False internal_mua = False
break break
cmd = ('reportbug', cmd = (
'--no-check-available', "reportbug",
'--no-check-installed', "--no-check-available",
'--pseudo-header', 'User: ubuntu-devel@lists.ubuntu.com', "--no-check-installed",
'--pseudo-header', 'Usertags: origin-ubuntu %s ubuntu-patch' "--pseudo-header",
% devel, "User: ubuntu-devel@lists.ubuntu.com",
'--tag', 'patch', "--pseudo-header",
'--bts', 'debian', "Usertags: origin-ubuntu %s ubuntu-patch" % devel,
'--include', body, "--tag",
'--attach' if internal_mua else '--include', debdiff, "patch",
'--package-version', deb_version, "--bts",
changelog.package) "debian",
"--include",
body,
"--attach" if internal_mua else "--include",
debdiff,
"--package-version",
deb_version,
changelog.package,
)
check_call(cmd, env=env) check_call(cmd, env=env)
def check_reportbug_config(): def check_reportbug_config():
fn = os.path.expanduser('~/.reportbugrc') fn = os.path.expanduser("~/.reportbugrc")
if os.path.exists(fn): if os.path.exists(fn):
return return
email = ubu_email()[1] email = ubu_email()[1]
reportbugrc = """# Reportbug configuration generated by submittodebian(1) reportbugrc = (
"""# Reportbug configuration generated by submittodebian(1)
# See reportbug.conf(5) for the configuration file format. # See reportbug.conf(5) for the configuration file format.
# Use Debian's reportbug SMTP Server: # Use Debian's reportbug SMTP Server:
@ -195,12 +209,15 @@ no-cc
#smtphost smtp.googlemail.com:587 #smtphost smtp.googlemail.com:587
#smtpuser "<your address>@gmail.com" #smtpuser "<your address>@gmail.com"
#smtptls #smtptls
""" % email """
% email
)
with open(fn, 'w') as f: with open(fn, "w") as f:
f.write(reportbugrc) f.write(reportbugrc)
Logger.info("""\ Logger.info(
"""\
You have not configured reportbug. Assuming this is the first time you have You have not configured reportbug. Assuming this is the first time you have
used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC used it. Writing a ~/.reportbugrc that will use Debian's mail server, and CC
the bug to you at <%s> the bug to you at <%s>
@ -211,26 +228,32 @@ the bug to you at <%s>
If this is not correct, please exit now and edit ~/.reportbugrc or run If this is not correct, please exit now and edit ~/.reportbugrc or run
reportbug --configure for its configuration wizard. reportbug --configure for its configuration wizard.
""" % (email, reportbugrc.strip())) """
% (email, reportbugrc.strip())
)
if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no": if YesNoQuestion().ask("Continue submitting this bug", "yes") == "no":
sys.exit(1) sys.exit(1)
def main(): def main():
description = 'Submit the Ubuntu changes in a package to Debian. ' + \ description = (
'Run inside an unpacked Ubuntu source package.' "Submit the Ubuntu changes in a package to Debian. "
+ "Run inside an unpacked Ubuntu source package."
)
parser = optparse.OptionParser(description=description) parser = optparse.OptionParser(description=description)
parser.parse_args() parser.parse_args()
if not os.path.exists('/usr/bin/reportbug'): if not os.path.exists("/usr/bin/reportbug"):
Logger.error("This utility requires the «reportbug» package, which isn't " Logger.error(
"currently installed.") "This utility requires the «reportbug» package, which isn't currently installed."
)
sys.exit(1) sys.exit(1)
check_reportbug_config() check_reportbug_config()
changelog_file = (check_file('debian/changelog', critical=False) or changelog_file = check_file("debian/changelog", critical=False) or check_file(
check_file('../debian/changelog')) "../debian/changelog"
)
with open(changelog_file) as f: with open(changelog_file) as f:
changelog = Changelog(f.read()) changelog = Changelog(f.read())
@ -238,13 +261,13 @@ def main():
bug_body = get_bug_body(changelog) bug_body = get_bug_body(changelog)
tmpdir = mkdtemp() tmpdir = mkdtemp()
body = os.path.join(tmpdir, 'bug_body') body = os.path.join(tmpdir, "bug_body")
with open(body, 'wb') as f: with open(body, "wb") as f:
f.write(bug_body.encode('utf-8')) f.write(bug_body.encode("utf-8"))
restore_maintainer('debian') restore_maintainer("debian")
build_source_package() build_source_package()
update_maintainer('debian') update_maintainer("debian")
debdiff = gen_debdiff(tmpdir, changelog) debdiff = gen_debdiff(tmpdir, changelog)
@ -252,7 +275,7 @@ def main():
# reverted in the most recent build # reverted in the most recent build
build_source_package() build_source_package()
EditFile(debdiff, 'debdiff').edit(optional=True) EditFile(debdiff, "debdiff").edit(optional=True)
submit_bugreport(body, debdiff, deb_version, changelog) submit_bugreport(body, debdiff, deb_version, changelog)
os.unlink(body) os.unlink(body)
@ -260,5 +283,5 @@ def main():
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -32,27 +32,30 @@ import urllib.request
from lazr.restfulclient.errors import HTTPError from lazr.restfulclient.errors import HTTPError
from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, from ubuntutools.archive import DebianSourcePackage, UbuntuSourcePackage, DownloadError
DownloadError)
from ubuntutools.config import UDTConfig, ubu_email from ubuntutools.config import UDTConfig, ubu_email
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, PersonTeam, from ubuntutools.lp.lpapicache import (
SourcePackagePublishingHistory) Distribution,
Launchpad,
PersonTeam,
SourcePackagePublishingHistory,
)
from ubuntutools.misc import split_release_pocket from ubuntutools.misc import split_release_pocket
from ubuntutools.question import YesNoQuestion from ubuntutools.question import YesNoQuestion
from ubuntutools.requestsync.mail import ( from ubuntutools.requestsync.mail import get_debian_srcpkg as requestsync_mail_get_debian_srcpkg
get_debian_srcpkg as requestsync_mail_get_debian_srcpkg)
from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg
from ubuntutools.version import Version from ubuntutools.version import Version
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def remove_signature(dscname): def remove_signature(dscname):
'''Removes the signature from a .dsc file if the .dsc file is signed.''' """Removes the signature from a .dsc file if the .dsc file is signed."""
dsc_file = open(dscname, encoding='utf-8') dsc_file = open(dscname, encoding="utf-8")
if dsc_file.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----": if dsc_file.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----":
unsigned_file = [] unsigned_file = []
# search until begin of body found # search until begin of body found
@ -67,14 +70,14 @@ def remove_signature(dscname):
unsigned_file.append(line) unsigned_file.append(line)
dsc_file.close() dsc_file.close()
dsc_file = open(dscname, "w", encoding='utf-8') dsc_file = open(dscname, "w", encoding="utf-8")
dsc_file.writelines(unsigned_file) dsc_file.writelines(unsigned_file)
dsc_file.close() dsc_file.close()
def add_fixed_bugs(changes, bugs): def add_fixed_bugs(changes, bugs):
'''Add additional Launchpad bugs to the list of fixed bugs in changes """Add additional Launchpad bugs to the list of fixed bugs in changes
file.''' file."""
changes = [line for line in changes.split("\n") if line.strip() != ""] changes = [line for line in changes.split("\n") if line.strip() != ""]
# Remove duplicates # Remove duplicates
@ -93,12 +96,23 @@ def add_fixed_bugs(changes, bugs):
return "\n".join(changes + [""]) return "\n".join(changes + [""])
def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror, def sync_dsc(
keyid=None, simulate=False, force=False, fakesync=False): src_pkg,
'''Local sync, trying to emulate sync-source.py debian_dist,
release,
name,
email,
bugs,
ubuntu_mirror,
keyid=None,
simulate=False,
force=False,
fakesync=False,
):
"""Local sync, trying to emulate sync-source.py
Grabs a source package, replaces the .orig.tar with the one from Ubuntu, Grabs a source package, replaces the .orig.tar with the one from Ubuntu,
if necessary, writes a sync-appropriate .changes file, and signs it. if necessary, writes a sync-appropriate .changes file, and signs it.
''' """
uploader = name + " <" + email + ">" uploader = name + " <" + email + ">"
@ -106,52 +120,59 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
try: try:
ubuntu_series, ubuntu_pocket = split_release_pocket(release) ubuntu_series, ubuntu_pocket = split_release_pocket(release)
ubuntu_source = get_ubuntu_srcpkg(src_pkg.source, ubuntu_series, ubuntu_source = get_ubuntu_srcpkg(src_pkg.source, ubuntu_series, ubuntu_pocket)
ubuntu_pocket)
ubuntu_ver = Version(ubuntu_source.getVersion()) ubuntu_ver = Version(ubuntu_source.getVersion())
ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version, ubu_pkg = UbuntuSourcePackage(
ubuntu_source.getComponent(), src_pkg.source,
mirrors=[ubuntu_mirror]) ubuntu_ver.full_version,
ubuntu_source.getComponent(),
mirrors=[ubuntu_mirror],
)
need_orig = ubuntu_ver.upstream_version != new_ver.upstream_version need_orig = ubuntu_ver.upstream_version != new_ver.upstream_version
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_ver = Version('~') ubuntu_ver = Version("~")
ubu_pkg = None ubu_pkg = None
need_orig = True need_orig = True
Logger.info('%s does not exist in Ubuntu.', name) Logger.info("%s does not exist in Ubuntu.", name)
Logger.debug('Source %s: current version %s, new version %s', Logger.debug(
src_pkg.source, ubuntu_ver, new_ver) "Source %s: current version %s, new version %s", src_pkg.source, ubuntu_ver, new_ver
Logger.debug('Needs source tarball: %s', str(need_orig)) )
Logger.debug("Needs source tarball: %s", str(need_orig))
cur_ver = ubuntu_ver.get_related_debian_version() cur_ver = ubuntu_ver.get_related_debian_version()
if ubuntu_ver.is_modified_in_ubuntu(): if ubuntu_ver.is_modified_in_ubuntu():
if not force: if not force:
Logger.error('--force is required to discard Ubuntu changes.') Logger.error("--force is required to discard Ubuntu changes.")
sys.exit(1) sys.exit(1)
Logger.warning('Overwriting modified Ubuntu version %s, ' Logger.warning(
'setting current version to %s', "Overwriting modified Ubuntu version %s, setting current version to %s",
ubuntu_ver.full_version, cur_ver.full_version) ubuntu_ver.full_version,
cur_ver.full_version,
)
if simulate: if simulate:
return return
try: try:
src_pkg.pull() src_pkg.pull()
except DownloadError as e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error("Failed to download: %s", str(e))
sys.exit(1) sys.exit(1)
src_pkg.unpack() src_pkg.unpack()
needs_fakesync = not (need_orig or ubu_pkg.verify_orig()) needs_fakesync = not (need_orig or ubu_pkg.verify_orig())
if needs_fakesync and fakesync: if needs_fakesync and fakesync:
Logger.warning('Performing a fakesync') Logger.warning("Performing a fakesync")
elif not needs_fakesync and fakesync: elif not needs_fakesync and fakesync:
Logger.error('Fakesync not required, aborting.') Logger.error("Fakesync not required, aborting.")
sys.exit(1) sys.exit(1)
elif needs_fakesync and not fakesync: elif needs_fakesync and not fakesync:
Logger.error('The checksums of the Debian and Ubuntu packages ' Logger.error(
'mismatch. A fake sync using --fakesync is required.') "The checksums of the Debian and Ubuntu packages "
"mismatch. A fake sync using --fakesync is required."
)
sys.exit(1) sys.exit(1)
if fakesync: if fakesync:
@ -159,47 +180,50 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
try: try:
ubu_pkg.pull() ubu_pkg.pull()
except DownloadError as e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error("Failed to download: %s", str(e))
sys.exit(1) sys.exit(1)
# change into package directory # change into package directory
directory = src_pkg.source + '-' + new_ver.upstream_version directory = src_pkg.source + "-" + new_ver.upstream_version
Logger.debug('cd' + directory) Logger.debug("cd" + directory)
os.chdir(directory) os.chdir(directory)
# read Debian distribution from debian/changelog if not specified # read Debian distribution from debian/changelog if not specified
if debian_dist is None: if debian_dist is None:
line = open("debian/changelog", encoding='utf-8').readline() line = open("debian/changelog", encoding="utf-8").readline()
debian_dist = line.split(" ")[2].strip(";") debian_dist = line.split(" ")[2].strip(";")
if not fakesync: if not fakesync:
# create the changes file # create the changes file
changes_filename = "%s_%s_source.changes" % \ changes_filename = "%s_%s_source.changes" % (src_pkg.source, new_ver.strip_epoch())
(src_pkg.source, new_ver.strip_epoch()) cmd = [
cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver.full_version, "dpkg-genchanges",
"-DDistribution=" + release, "-S",
"-DOrigin=debian/" + debian_dist, "-v" + cur_ver.full_version,
"-e" + uploader] "-DDistribution=" + release,
"-DOrigin=debian/" + debian_dist,
"-e" + uploader,
]
if need_orig: if need_orig:
cmd.append("-sa") cmd.append("-sa")
else: else:
cmd.append("-sd") cmd.append("-sd")
if not Logger.isEnabledFor(logging.DEBUG): if not Logger.isEnabledFor(logging.DEBUG):
cmd += ["-q"] cmd += ["-q"]
Logger.debug(' '.join(cmd) + '> ../' + changes_filename) Logger.debug(" ".join(cmd) + "> ../" + changes_filename)
changes = subprocess.check_output(cmd, encoding='utf-8') changes = subprocess.check_output(cmd, encoding="utf-8")
# Add additional bug numbers # Add additional bug numbers
if len(bugs) > 0: if len(bugs) > 0:
changes = add_fixed_bugs(changes, bugs) changes = add_fixed_bugs(changes, bugs)
# remove extracted (temporary) files # remove extracted (temporary) files
Logger.debug('cd ..') Logger.debug("cd ..")
os.chdir('..') os.chdir("..")
shutil.rmtree(directory, True) shutil.rmtree(directory, True)
# write changes file # write changes file
changes_file = open(changes_filename, "w", encoding='utf-8') changes_file = open(changes_filename, "w", encoding="utf-8")
changes_file.writelines(changes) changes_file.writelines(changes)
changes_file.close() changes_file.close()
@ -209,48 +233,44 @@ def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror,
cmd = ["debsign", changes_filename] cmd = ["debsign", changes_filename]
if keyid is not None: if keyid is not None:
cmd.insert(1, "-k" + keyid) cmd.insert(1, "-k" + keyid)
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
else: else:
# Create fakesync changelog entry # Create fakesync changelog entry
new_ver = Version(new_ver.full_version + "fakesync1") new_ver = Version(new_ver.full_version + "fakesync1")
changes_filename = "%s_%s_source.changes" % \ changes_filename = "%s_%s_source.changes" % (src_pkg.source, new_ver.strip_epoch())
(src_pkg.source, new_ver.strip_epoch())
if len(bugs) > 0: if len(bugs) > 0:
message = "Fake sync due to mismatching orig tarball (LP: %s)." % \ message = "Fake sync due to mismatching orig tarball (LP: %s)." % (
(", ".join(["#" + str(b) for b in bugs])) ", ".join(["#" + str(b) for b in bugs])
)
else: else:
message = "Fake sync due to mismatching orig tarball." message = "Fake sync due to mismatching orig tarball."
cmd = ['dch', '-v', new_ver.full_version, '--force-distribution', cmd = ["dch", "-v", new_ver.full_version, "--force-distribution", "-D", release, message]
'-D', release, message] env = {"DEBFULLNAME": name, "DEBEMAIL": email}
env = {'DEBFULLNAME': name, 'DEBEMAIL': email} Logger.debug(" ".join(cmd))
Logger.debug(' '.join(cmd))
subprocess.check_call(cmd, env=env) subprocess.check_call(cmd, env=env)
# update the Maintainer field # update the Maintainer field
cmd = ["update-maintainer"] cmd = ["update-maintainer"]
if not Logger.isEnabledFor(logging.DEBUG): if not Logger.isEnabledFor(logging.DEBUG):
cmd.append("-q") cmd.append("-q")
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
# Build source package # Build source package
cmd = ["debuild", "--no-lintian", "-nc", "-S", cmd = ["debuild", "--no-lintian", "-nc", "-S", "-v" + cur_ver.full_version]
"-v" + cur_ver.full_version]
if need_orig: if need_orig:
cmd += ['-sa'] cmd += ["-sa"]
if keyid: if keyid:
cmd += ["-k" + keyid] cmd += ["-k" + keyid]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
if returncode != 0: if returncode != 0:
Logger.error('Source-only build with debuild failed. ' Logger.error("Source-only build with debuild failed. Please check build log above.")
'Please check build log above.')
sys.exit(1) sys.exit(1)
def fetch_source_pkg(package, dist, version, component, ubuntu_release, def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror):
mirror):
"""Download the specified source package. """Download the specified source package.
dist, version, component, mirror can all be None. dist, version, component, mirror can all be None.
""" """
@ -259,11 +279,11 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release,
else: else:
mirrors = [mirror] mirrors = [mirror]
if package.endswith('.dsc'): if package.endswith(".dsc"):
return DebianSourcePackage(dscfile=package, mirrors=mirrors) return DebianSourcePackage(dscfile=package, mirrors=mirrors)
if dist is None: if dist is None:
dist = 'unstable' dist = "unstable"
requested_version = version requested_version = version
if type(version) == str: if type(version) == str:
@ -272,19 +292,20 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release,
if version is None or component is None: if version is None or component is None:
try: try:
debian_srcpkg = get_debian_srcpkg(package, dist) debian_srcpkg = get_debian_srcpkg(package, dist)
except (udtexceptions.PackageNotFoundException, except (
udtexceptions.SeriesNotFoundException) as e: udtexceptions.PackageNotFoundException,
udtexceptions.SeriesNotFoundException,
) as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
if version is None: if version is None:
version = Version(debian_srcpkg.getVersion()) version = Version(debian_srcpkg.getVersion())
try: try:
ubuntu_series, ubuntu_pocket = split_release_pocket(ubuntu_release) ubuntu_series, ubuntu_pocket = split_release_pocket(ubuntu_release)
ubuntu_srcpkg = get_ubuntu_srcpkg(package, ubuntu_series, ubuntu_srcpkg = get_ubuntu_srcpkg(package, ubuntu_series, ubuntu_pocket)
ubuntu_pocket)
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) ubuntu_version = Version(ubuntu_srcpkg.getVersion())
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
ubuntu_version = Version('~') ubuntu_version = Version("~")
except udtexceptions.SeriesNotFoundException as e: except udtexceptions.SeriesNotFoundException as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(1) sys.exit(1)
@ -294,72 +315,84 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release,
if requested_version is None: if requested_version is None:
version = Version(debian_srcpkg.getVersion()) version = Version(debian_srcpkg.getVersion())
if ubuntu_version >= version: if ubuntu_version >= version:
Logger.error("Version in Debian %s (%s) isn't newer than " Logger.error(
"Ubuntu %s (%s)", "Version in Debian %s (%s) isn't newer than Ubuntu %s (%s)",
version, dist, ubuntu_version, ubuntu_release) version,
dist,
ubuntu_version,
ubuntu_release,
)
sys.exit(1) sys.exit(1)
if component is None: if component is None:
component = debian_srcpkg.getComponent() component = debian_srcpkg.getComponent()
assert component in ('main', 'contrib', 'non-free') assert component in ("main", "contrib", "non-free")
return DebianSourcePackage(package, version.full_version, component, return DebianSourcePackage(package, version.full_version, component, mirrors=mirrors)
mirrors=mirrors)
def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False): def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False):
"""Copy a source package from Debian to Ubuntu using the Launchpad API.""" """Copy a source package from Debian to Ubuntu using the Launchpad API."""
ubuntu = Distribution('ubuntu') ubuntu = Distribution("ubuntu")
debian_archive = Distribution('debian').getArchive() debian_archive = Distribution("debian").getArchive()
ubuntu_archive = ubuntu.getArchive() ubuntu_archive = ubuntu.getArchive()
if release is None: if release is None:
ubuntu_series = ubuntu.getDevelopmentSeries().name ubuntu_series = ubuntu.getDevelopmentSeries().name
ubuntu_pocket = 'Release' ubuntu_pocket = "Release"
else: else:
ubuntu_series, ubuntu_pocket = split_release_pocket(release) ubuntu_series, ubuntu_pocket = split_release_pocket(release)
# Ensure that the provided Debian version actually exists. # Ensure that the provided Debian version actually exists.
try: try:
debian_spph = SourcePackagePublishingHistory( debian_spph = SourcePackagePublishingHistory(
debian_archive.getPublishedSources( debian_archive.getPublishedSources(
source_name=src_pkg.source, source_name=src_pkg.source, version=src_pkg.version.full_version, exact_match=True
version=src_pkg.version.full_version, )[0]
exact_match=True)[0] )
)
except IndexError: except IndexError:
Logger.error('Debian version %s has not been picked up by LP yet. ' Logger.error(
'Please try again later.', "Debian version %s has not been picked up by LP yet. Please try again later.",
src_pkg.version) src_pkg.version,
)
sys.exit(1) sys.exit(1)
try: try:
ubuntu_spph = get_ubuntu_srcpkg(src_pkg.source, ubuntu_spph = get_ubuntu_srcpkg(src_pkg.source, ubuntu_series, ubuntu_pocket)
ubuntu_series, ubuntu_pocket) ubuntu_pkg = UbuntuSourcePackage(
ubuntu_pkg = UbuntuSourcePackage(src_pkg.source, src_pkg.source, ubuntu_spph.getVersion(), ubuntu_spph.getComponent(), mirrors=[]
ubuntu_spph.getVersion(), )
ubuntu_spph.getComponent(),
mirrors=[])
Logger.info('Source %s -> %s/%s: current version %s, new version %s', Logger.info(
src_pkg.source, ubuntu_series, ubuntu_pocket, "Source %s -> %s/%s: current version %s, new version %s",
ubuntu_pkg.version, src_pkg.version) src_pkg.source,
ubuntu_series,
ubuntu_pocket,
ubuntu_pkg.version,
src_pkg.version,
)
ubuntu_version = Version(ubuntu_pkg.version.full_version) ubuntu_version = Version(ubuntu_pkg.version.full_version)
base_version = ubuntu_version.get_related_debian_version() base_version = ubuntu_version.get_related_debian_version()
if not force and ubuntu_version.is_modified_in_ubuntu(): if not force and ubuntu_version.is_modified_in_ubuntu():
Logger.error('--force is required to discard Ubuntu changes.') Logger.error("--force is required to discard Ubuntu changes.")
sys.exit(1) sys.exit(1)
# Check whether a fakesync would be required. # Check whether a fakesync would be required.
if not src_pkg.dsc.compare_dsc(ubuntu_pkg.dsc): if not src_pkg.dsc.compare_dsc(ubuntu_pkg.dsc):
Logger.error('The checksums of the Debian and Ubuntu packages ' Logger.error(
'mismatch. A fake sync using --fakesync is required.') "The checksums of the Debian and Ubuntu packages "
"mismatch. A fake sync using --fakesync is required."
)
sys.exit(1) sys.exit(1)
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
base_version = Version('~') base_version = Version("~")
Logger.info('Source %s -> %s/%s: not in Ubuntu, new version %s', Logger.info(
src_pkg.source, ubuntu_series, ubuntu_pocket, "Source %s -> %s/%s: not in Ubuntu, new version %s",
src_pkg.version) src_pkg.source,
ubuntu_series,
ubuntu_pocket,
src_pkg.version,
)
changes = debian_spph.getChangelog(since_version=base_version) changes = debian_spph.getChangelog(since_version=base_version)
if changes: if changes:
@ -370,8 +403,7 @@ def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False):
return return
if sponsoree: if sponsoree:
Logger.info("Sponsoring this sync for %s (%s)", Logger.info("Sponsoring this sync for %s (%s)", sponsoree.display_name, sponsoree.name)
sponsoree.display_name, sponsoree.name)
answer = YesNoQuestion().ask("Sync this package", "no") answer = YesNoQuestion().ask("Sync this package", "no")
if answer != "yes": if answer != "yes":
return return
@ -384,65 +416,65 @@ def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False):
to_series=ubuntu_series, to_series=ubuntu_series,
to_pocket=ubuntu_pocket, to_pocket=ubuntu_pocket,
include_binaries=False, include_binaries=False,
sponsored=sponsoree) sponsored=sponsoree,
)
except HTTPError as error: except HTTPError as error:
Logger.error("HTTP Error %s: %s", error.response.status, Logger.error("HTTP Error %s: %s", error.response.status, error.response.reason)
error.response.reason)
Logger.error(error.content) Logger.error(error.content)
sys.exit(1) sys.exit(1)
Logger.info('Request succeeded; you should get an e-mail once it is ' Logger.info("Request succeeded; you should get an e-mail once it is processed.")
'processed.')
bugs = sorted(set(bugs)) bugs = sorted(set(bugs))
if bugs: if bugs:
Logger.info("Launchpad bugs to be closed: %s", Logger.info("Launchpad bugs to be closed: %s", ", ".join(str(bug) for bug in bugs))
', '.join(str(bug) for bug in bugs)) Logger.info("Please wait for the sync to be successful before closing bugs.")
Logger.info('Please wait for the sync to be successful before '
'closing bugs.')
answer = YesNoQuestion().ask("Close bugs", "yes") answer = YesNoQuestion().ask("Close bugs", "yes")
if answer == "yes": if answer == "yes":
close_bugs(bugs, src_pkg.source, src_pkg.version.full_version, close_bugs(bugs, src_pkg.source, src_pkg.version.full_version, changes, sponsoree)
changes, sponsoree)
def is_blacklisted(query): def is_blacklisted(query):
""""Determine if package "query" is in the sync blacklist """Determine if package "query" is in the sync blacklist
Returns tuple of (blacklisted, comments) Returns tuple of (blacklisted, comments)
blacklisted is one of False, 'CURRENT', 'ALWAYS' blacklisted is one of False, 'CURRENT', 'ALWAYS'
""" """
series = Launchpad.distributions['ubuntu'].current_series series = Launchpad.distributions["ubuntu"].current_series
lp_comments = series.getDifferenceComments(source_package_name=query) lp_comments = series.getDifferenceComments(source_package_name=query)
blacklisted = False blacklisted = False
comments = ['%s\n -- %s %s' comments = [
% (c.body_text, c.comment_author.name, "%s\n -- %s %s"
c.comment_date.strftime('%a, %d %b %Y %H:%M:%S +0000')) % (
for c in lp_comments] c.body_text,
c.comment_author.name,
c.comment_date.strftime("%a, %d %b %Y %H:%M:%S +0000"),
)
for c in lp_comments
]
for diff in series.getDifferencesTo(source_package_name_filter=query): for diff in series.getDifferencesTo(source_package_name_filter=query):
if (diff.status == 'Blacklisted current version' if diff.status == "Blacklisted current version" and blacklisted != "ALWAYS":
and blacklisted != 'ALWAYS'): blacklisted = "CURRENT"
blacklisted = 'CURRENT' if diff.status == "Blacklisted always":
if diff.status == 'Blacklisted always': blacklisted = "ALWAYS"
blacklisted = 'ALWAYS'
# Old blacklist: # Old blacklist:
url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' url = "http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt"
with urllib.request.urlopen(url) as f: with urllib.request.urlopen(url) as f:
applicable_lines = [] applicable_lines = []
for line in f: for line in f:
line = line.decode('utf-8') line = line.decode("utf-8")
if not line.strip(): if not line.strip():
applicable_lines = [] applicable_lines = []
continue continue
applicable_lines.append(line) applicable_lines.append(line)
try: try:
line = line[:line.index('#')] line = line[: line.index("#")]
except ValueError: except ValueError:
pass pass
source = line.strip() source = line.strip()
if source and fnmatch.fnmatch(query, source): if source and fnmatch.fnmatch(query, source):
comments += ["From sync-blacklist.txt:"] + applicable_lines comments += ["From sync-blacklist.txt:"] + applicable_lines
blacklisted = 'ALWAYS' blacklisted = "ALWAYS"
break break
return (blacklisted, comments) return (blacklisted, comments)
@ -450,12 +482,10 @@ def is_blacklisted(query):
def close_bugs(bugs, package, version, changes, sponsoree): def close_bugs(bugs, package, version, changes, sponsoree):
"""Close the correct task on all bugs, with changes""" """Close the correct task on all bugs, with changes"""
ubuntu = Launchpad.distributions['ubuntu'] ubuntu = Launchpad.distributions["ubuntu"]
message = ("This bug was fixed in the package %s - %s" message = "This bug was fixed in the package %s - %s" % (package, version)
% (package, version))
if sponsoree: if sponsoree:
message += '\nSponsored for %s (%s)' % (sponsoree.display_name, message += "\nSponsored for %s (%s)" % (sponsoree.display_name, sponsoree.name)
sponsoree.name)
if changes: if changes:
message += "\n\n---------------\n" + changes message += "\n\n---------------\n" + changes
for bug in bugs: for bug in bugs:
@ -464,11 +494,12 @@ def close_bugs(bugs, package, version, changes, sponsoree):
bug = bug.duplicate_of bug = bug.duplicate_of
for task in bug.bug_tasks: for task in bug.bug_tasks:
target = task.target target = task.target
if target == ubuntu or (target.name == package and if target == ubuntu or (
getattr(target, 'distribution', None) == ubuntu): target.name == package and getattr(target, "distribution", None) == ubuntu
if task.status != 'Fix Released': ):
if task.status != "Fix Released":
Logger.info("Closed bug %s", task.web_link) Logger.info("Closed bug %s", task.web_link)
task.status = 'Fix Released' task.status = "Fix Released"
task.lp_save() task.lp_save()
bug.newMessage(content=message) bug.newMessage(content=message)
break break
@ -483,77 +514,116 @@ def parse():
epilog = "See %s(1) for more info." % os.path.basename(sys.argv[0]) epilog = "See %s(1) for more info." % os.path.basename(sys.argv[0])
parser = optparse.OptionParser(usage=usage, epilog=epilog) parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-d", "--distribution", parser.add_option("-d", "--distribution", help="Debian distribution to sync from.")
help="Debian distribution to sync from.") parser.add_option("-r", "--release", help="Specify target Ubuntu release.")
parser.add_option("-r", "--release", parser.add_option("-V", "--debian-version", help="Specify the version to sync from.")
help="Specify target Ubuntu release.") parser.add_option("-c", "--component", help="Specify the Debian component to sync from.")
parser.add_option("-V", "--debian-version", parser.add_option(
help="Specify the version to sync from.") "-b",
parser.add_option("-c", "--component", "--bug",
help="Specify the Debian component to sync from.") metavar="BUG",
parser.add_option("-b", "--bug", metavar="BUG", dest="bugs",
dest="bugs", action="append", default=list(), action="append",
help="Mark Launchpad bug BUG as being fixed by this " default=list(),
"upload.") help="Mark Launchpad bug BUG as being fixed by this upload.",
parser.add_option("-s", "--sponsor", metavar="USERNAME", )
dest="sponsoree", default=None, parser.add_option(
help="Sponsor the sync for USERNAME (a Launchpad " "-s",
"username).") "--sponsor",
parser.add_option("-v", "--verbose", metavar="USERNAME",
action="store_true", default=False, dest="sponsoree",
help="Display more progress information.") default=None,
parser.add_option("-F", "--fakesync", help="Sponsor the sync for USERNAME (a Launchpad username).",
action="store_true", default=False, )
help="Perform a fakesync (a sync where Debian and " parser.add_option(
"Ubuntu have a .orig.tar mismatch). " "-v",
"This implies --no-lp and will leave a signed " "--verbose",
".changes file for you to upload.") action="store_true",
parser.add_option("-f", "--force", default=False,
action="store_true", default=False, help="Display more progress information.",
help="Force sync over the top of Ubuntu changes.") )
parser.add_option('--no-conf', parser.add_option(
default=False, action='store_true', "-F",
help="Don't read config files or environment variables.") "--fakesync",
parser.add_option('-l', '--lpinstance', metavar='INSTANCE', action="store_true",
help='Launchpad instance to connect to ' default=False,
'(default: production).') help="Perform a fakesync (a sync where Debian and "
parser.add_option('--simulate', "Ubuntu have a .orig.tar mismatch). "
default=False, action='store_true', "This implies --no-lp and will leave a signed "
help="Show what would be done, but don't actually do " ".changes file for you to upload.",
"it.") )
parser.add_option(
"-f",
"--force",
action="store_true",
default=False,
help="Force sync over the top of Ubuntu changes.",
)
parser.add_option(
"--no-conf",
default=False,
action="store_true",
help="Don't read config files or environment variables.",
)
parser.add_option(
"-l",
"--lpinstance",
metavar="INSTANCE",
help="Launchpad instance to connect to (default: production).",
)
parser.add_option(
"--simulate",
default=False,
action="store_true",
help="Show what would be done, but don't actually do it.",
)
no_lp = optparse.OptionGroup( no_lp = optparse.OptionGroup(
parser, "Local sync preparation options", parser,
"Local sync preparation options",
"Options that only apply when using --no-lp. " "Options that only apply when using --no-lp. "
"WARNING: The use of --no-lp is not recommended for uploads " "WARNING: The use of --no-lp is not recommended for uploads "
"targeted at Ubuntu. " "targeted at Ubuntu. "
"The archive-admins discourage its use, except for fakesyncs.") "The archive-admins discourage its use, except for fakesyncs.",
no_lp.add_option("--no-lp", )
dest="lp", action="store_false", default=True, no_lp.add_option(
help="Construct sync locally, rather than letting " "--no-lp",
"Launchpad copy the package directly. " dest="lp",
"It will leave a signed .changes file for you to " action="store_false",
"upload.") default=True,
no_lp.add_option("-n", "--uploader-name", help="Construct sync locally, rather than letting "
help="Use UPLOADER_NAME as the name of the maintainer " "Launchpad copy the package directly. "
"for this upload.") "It will leave a signed .changes file for you to "
no_lp.add_option("-e", "--uploader-email", "upload.",
help="Use UPLOADER_EMAIL as email address of the " )
"maintainer for this upload.") no_lp.add_option(
no_lp.add_option("-k", "--key", "-n",
dest="keyid", "--uploader-name",
help="Specify the key ID to be used for signing.") help="Use UPLOADER_NAME as the name of the maintainer for this upload.",
no_lp.add_option('--dont-sign', )
dest='keyid', action='store_false', no_lp.add_option(
help='Do not sign the upload.') "-e",
no_lp.add_option('-D', '--debian-mirror', metavar='DEBIAN_MIRROR', "--uploader-email",
help='Preferred Debian mirror ' help="Use UPLOADER_EMAIL as email address of the maintainer for this upload.",
'(default: %s)' )
% UDTConfig.defaults['DEBIAN_MIRROR']) no_lp.add_option(
no_lp.add_option('-U', '--ubuntu-mirror', metavar='UBUNTU_MIRROR', "-k", "--key", dest="keyid", help="Specify the key ID to be used for signing."
help='Preferred Ubuntu mirror ' )
'(default: %s)' no_lp.add_option(
% UDTConfig.defaults['UBUNTU_MIRROR']) "--dont-sign", dest="keyid", action="store_false", help="Do not sign the upload."
)
no_lp.add_option(
"-D",
"--debian-mirror",
metavar="DEBIAN_MIRROR",
help="Preferred Debian mirror (default: %s)" % UDTConfig.defaults["DEBIAN_MIRROR"],
)
no_lp.add_option(
"-U",
"--ubuntu-mirror",
metavar="UBUNTU_MIRROR",
help="Preferred Ubuntu mirror (default: %s)" % UDTConfig.defaults["UBUNTU_MIRROR"],
)
parser.add_option_group(no_lp) parser.add_option_group(no_lp)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -562,58 +632,56 @@ def parse():
options.lp = False options.lp = False
if len(args) == 0: if len(args) == 0:
parser.error('No .dsc URL/path or package name specified.') parser.error("No .dsc URL/path or package name specified.")
if len(args) > 1: if len(args) > 1:
parser.error('Multiple .dsc URLs/paths or package names specified: ' parser.error("Multiple .dsc URLs/paths or package names specified: " + ", ".join(args))
+ ', '.join(args))
try: try:
options.bugs = [int(b) for b in options.bugs] options.bugs = [int(b) for b in options.bugs]
except TypeError: except TypeError:
parser.error('Invalid bug number(s) specified.') parser.error("Invalid bug number(s) specified.")
if options.component not in (None, "main", "contrib", "non-free"): if options.component not in (None, "main", "contrib", "non-free"):
parser.error('%s is not a valid Debian component. ' parser.error(
'It should be one of main, contrib, or non-free.' "%s is not a valid Debian component. "
% options.component) "It should be one of main, contrib, or non-free." % options.component
)
if options.lp and options.uploader_name: if options.lp and options.uploader_name:
parser.error('Uploader name can only be overridden using --no-lp.') parser.error("Uploader name can only be overridden using --no-lp.")
if options.lp and options.uploader_email: if options.lp and options.uploader_email:
parser.error('Uploader email address can only be overridden using ' parser.error("Uploader email address can only be overridden using --no-lp.")
'--no-lp.')
# --key, --dont-sign, --debian-mirror, and --ubuntu-mirror are just # --key, --dont-sign, --debian-mirror, and --ubuntu-mirror are just
# ignored with options.lp, and do not require warnings. # ignored with options.lp, and do not require warnings.
if options.lp: if options.lp:
if args[0].endswith('.dsc'): if args[0].endswith(".dsc"):
parser.error('.dsc files can only be synced using --no-lp.') parser.error(".dsc files can only be synced using --no-lp.")
return (options, args[0]) return (options, args[0])
def main(): def main():
'''Handle parameters and get the ball rolling''' """Handle parameters and get the ball rolling"""
(options, package) = parse() (options, package) = parse()
if options.verbose: if options.verbose:
Logger.setLevel('DEBUG') Logger.setLevel("DEBUG")
config = UDTConfig(options.no_conf) config = UDTConfig(options.no_conf)
if options.debian_mirror is None: if options.debian_mirror is None:
options.debian_mirror = config.get_value('DEBIAN_MIRROR') options.debian_mirror = config.get_value("DEBIAN_MIRROR")
if options.ubuntu_mirror is None: if options.ubuntu_mirror is None:
options.ubuntu_mirror = config.get_value('UBUNTU_MIRROR') options.ubuntu_mirror = config.get_value("UBUNTU_MIRROR")
if options.keyid is None: if options.keyid is None:
options.keyid = config.get_value('KEYID') options.keyid = config.get_value("KEYID")
if options.lpinstance is None: if options.lpinstance is None:
options.lpinstance = config.get_value('LPINSTANCE') options.lpinstance = config.get_value("LPINSTANCE")
try: try:
# devel for copyPackage and changelogUrl # devel for copyPackage and changelogUrl
kwargs = {'service': options.lpinstance, kwargs = {"service": options.lpinstance, "api_version": "devel"}
'api_version': 'devel'}
if options.lp and not options.simulate: if options.lp and not options.simulate:
Launchpad.login(**kwargs) Launchpad.login(**kwargs)
else: else:
@ -626,18 +694,19 @@ def main():
options.release = "%s-proposed" % ubuntu.current_series.name options.release = "%s-proposed" % ubuntu.current_series.name
if not options.fakesync and not options.lp: if not options.fakesync and not options.lp:
Logger.warning("The use of --no-lp is not recommended for uploads " Logger.warning(
"targeted at Ubuntu. " "The use of --no-lp is not recommended for uploads "
"The archive-admins discourage its use, except for " "targeted at Ubuntu. "
"fakesyncs.") "The archive-admins discourage its use, except for "
"fakesyncs."
)
sponsoree = None sponsoree = None
if options.sponsoree: if options.sponsoree:
try: try:
sponsoree = PersonTeam(options.sponsoree) sponsoree = PersonTeam(options.sponsoree)
except KeyError: except KeyError:
Logger.error('Cannot find the username "%s" in Launchpad.', Logger.error('Cannot find the username "%s" in Launchpad.', options.sponsoree)
options.sponsoree)
sys.exit(1) sys.exit(1)
if sponsoree and options.uploader_name is None: if sponsoree and options.uploader_name is None:
@ -650,44 +719,54 @@ def main():
options.uploader_email = sponsoree.preferred_email_address.email options.uploader_email = sponsoree.preferred_email_address.email
except ValueError: except ValueError:
if not options.lp: if not options.lp:
Logger.error("%s doesn't have a publicly visible e-mail " Logger.error(
"address in LP, please provide one " "%s doesn't have a publicly visible e-mail "
"--uploader-email option", sponsoree.display_name) "address in LP, please provide one "
"--uploader-email option",
sponsoree.display_name,
)
sys.exit(1) sys.exit(1)
elif options.uploader_email is None: elif options.uploader_email is None:
options.uploader_email = ubu_email(export=False)[1] options.uploader_email = ubu_email(export=False)[1]
src_pkg = fetch_source_pkg(package, options.distribution, src_pkg = fetch_source_pkg(
options.debian_version, package,
options.component, options.distribution,
options.release, options.debian_version,
options.debian_mirror) options.component,
options.release,
options.debian_mirror,
)
blacklisted, comments = is_blacklisted(src_pkg.source) blacklisted, comments = is_blacklisted(src_pkg.source)
blacklist_fail = False blacklist_fail = False
if blacklisted: if blacklisted:
messages = [] messages = []
if blacklisted == 'CURRENT': if blacklisted == "CURRENT":
Logger.debug("Source package %s is temporarily blacklisted " Logger.debug(
"(blacklisted_current). " "Source package %s is temporarily blacklisted "
"Ubuntu ignores these for now. " "(blacklisted_current). "
"See also LP: #841372", src_pkg.source) "Ubuntu ignores these for now. "
"See also LP: #841372",
src_pkg.source,
)
else: else:
if options.fakesync: if options.fakesync:
messages += ["Doing a fakesync, overriding blacklist."] messages += ["Doing a fakesync, overriding blacklist."]
else: else:
blacklist_fail = True blacklist_fail = True
messages += ["If this package needs a fakesync, " messages += [
"use --fakesync", "If this package needs a fakesync, use --fakesync",
"If you think this package shouldn't be " "If you think this package shouldn't be "
"blacklisted, please file a bug explaining your " "blacklisted, please file a bug explaining your "
"reasoning and subscribe ~ubuntu-archive."] "reasoning and subscribe ~ubuntu-archive.",
]
if blacklist_fail: if blacklist_fail:
Logger.error("Source package %s is blacklisted.", src_pkg.source) Logger.error("Source package %s is blacklisted.", src_pkg.source)
elif blacklisted == 'ALWAYS': elif blacklisted == "ALWAYS":
Logger.info(u"Source package %s is blacklisted.", src_pkg.source) Logger.info("Source package %s is blacklisted.", src_pkg.source)
if messages: if messages:
for message in messages: for message in messages:
for line in textwrap.wrap(message): for line in textwrap.wrap(message):
@ -703,18 +782,26 @@ def main():
sys.exit(1) sys.exit(1)
if options.lp: if options.lp:
copy(src_pkg, options.release, options.bugs, sponsoree, copy(src_pkg, options.release, options.bugs, sponsoree, options.simulate, options.force)
options.simulate, options.force)
else: else:
os.environ['DEB_VENDOR'] = 'Ubuntu' os.environ["DEB_VENDOR"] = "Ubuntu"
sync_dsc(src_pkg, options.distribution, options.release, sync_dsc(
options.uploader_name, options.uploader_email, options.bugs, src_pkg,
options.ubuntu_mirror, options.keyid, options.simulate, options.distribution,
options.force, options.fakesync) options.release,
options.uploader_name,
options.uploader_email,
options.bugs,
options.ubuntu_mirror,
options.keyid,
options.simulate,
options.force,
options.fakesync,
)
if __name__ == "__main__": if __name__ == "__main__":
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
Logger.info('User abort.') Logger.info("User abort.")

View File

@ -26,14 +26,17 @@
import sys import sys
from optparse import OptionGroup from optparse import OptionGroup
from optparse import OptionParser from optparse import OptionParser
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException, from ubuntutools.lp.udtexceptions import (
PackageNotFoundException, SeriesNotFoundException,
PocketDoesNotExistError,) PackageNotFoundException,
PocketDoesNotExistError,
)
from ubuntutools.lp.lpapicache import Distribution, Launchpad, PersonTeam from ubuntutools.lp.lpapicache import Distribution, Launchpad, PersonTeam
from launchpadlib.credentials import TokenAuthorizationException from launchpadlib.credentials import TokenAuthorizationException
from ubuntutools.misc import split_release_pocket from ubuntutools.misc import split_release_pocket
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
@ -44,48 +47,84 @@ def main():
usage += "Only Launchpad Buildd Admins may rescore package builds." usage += "Only Launchpad Buildd Admins may rescore package builds."
# Valid architectures. # Valid architectures.
valid_archs = set([ valid_archs = set(
"armel", "armhf", "arm64", "amd64", "hppa", "i386", "ia64", [
"lpia", "powerpc", "ppc64el", "riscv64", "s390x", "sparc", "armel",
]) "armhf",
"arm64",
"amd64",
"hppa",
"i386",
"ia64",
"lpia",
"powerpc",
"ppc64el",
"riscv64",
"s390x",
"sparc",
]
)
# Prepare our option parser. # Prepare our option parser.
opt_parser = OptionParser(usage) opt_parser = OptionParser(usage)
# Retry options # Retry options
retry_rescore_options = OptionGroup(opt_parser, "Retry and rescore options", retry_rescore_options = OptionGroup(
"These options may only be used with " opt_parser,
"the 'retry' and 'rescore' operations.") "Retry and rescore options",
retry_rescore_options.add_option("-a", "--arch", type="string", "These options may only be used with the 'retry' and 'rescore' operations.",
action="append", dest="architecture", )
help="Rebuild or rescore a specific " retry_rescore_options.add_option(
"architecture. Valid architectures " "-a",
"include: %s." % "--arch",
", ".join(valid_archs)) type="string",
action="append",
dest="architecture",
help="Rebuild or rescore a specific "
"architecture. Valid architectures "
"include: %s." % ", ".join(valid_archs),
)
# Batch processing options # Batch processing options
batch_options = OptionGroup(opt_parser, "Batch processing", batch_options = OptionGroup(
"These options and parameter ordering is only " opt_parser,
"available in --batch mode.\nUsage: " "Batch processing",
"ubuntu-build --batch [options] <package>...") "These options and parameter ordering is only "
batch_options.add_option('--batch', "available in --batch mode.\nUsage: "
action='store_true', dest='batch', default=False, "ubuntu-build --batch [options] <package>...",
help='Enable batch mode') )
batch_options.add_option('--series', batch_options.add_option(
action='store', dest='series', type='string', "--batch", action="store_true", dest="batch", default=False, help="Enable batch mode"
help='Selects the Ubuntu series to operate on ' )
'(default: current development series)') batch_options.add_option(
batch_options.add_option('--retry', "--series",
action='store_true', dest='retry', default=False, action="store",
help='Retry builds (give-back).') dest="series",
batch_options.add_option('--rescore', type="string",
action='store', dest='priority', type='int', help="Selects the Ubuntu series to operate on (default: current development series)",
help='Rescore builds to <priority>.') )
batch_options.add_option('--arch2', action='append', dest='architecture', batch_options.add_option(
type='string', "--retry",
help="Affect only 'architecture' (can be used " action="store_true",
"several times). Valid architectures are: %s." dest="retry",
% ', '.join(valid_archs)) default=False,
help="Retry builds (give-back).",
)
batch_options.add_option(
"--rescore",
action="store",
dest="priority",
type="int",
help="Rescore builds to <priority>.",
)
batch_options.add_option(
"--arch2",
action="append",
dest="architecture",
type="string",
help="Affect only 'architecture' (can be used "
"several times). Valid architectures are: %s." % ", ".join(valid_archs),
)
# Add the retry options to the main group. # Add the retry options to the main group.
opt_parser.add_option_group(retry_rescore_options) opt_parser.add_option_group(retry_rescore_options)
@ -121,8 +160,7 @@ def main():
# rebuild it and nothing else. # rebuild it and nothing else.
if options.architecture: if options.architecture:
if options.architecture[0] not in valid_archs: if options.architecture[0] not in valid_archs:
Logger.error("Invalid architecture specified: %s." Logger.error("Invalid architecture specified: %s." % options.architecture[0])
% options.architecture[0])
sys.exit(1) sys.exit(1)
else: else:
one_arch = True one_arch = True
@ -143,11 +181,11 @@ def main():
sys.exit(1) sys.exit(1)
# Get the ubuntu archive # Get the ubuntu archive
ubuntu_archive = Distribution('ubuntu').getArchive() ubuntu_archive = Distribution("ubuntu").getArchive()
# Get list of published sources for package in question. # Get list of published sources for package in question.
try: try:
sources = ubuntu_archive.getSourcePackage(package, release, pocket) sources = ubuntu_archive.getSourcePackage(package, release, pocket)
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution("ubuntu").getSeries(release)
except (SeriesNotFoundException, PackageNotFoundException) as error: except (SeriesNotFoundException, PackageNotFoundException) as error:
Logger.error(error) Logger.error(error)
sys.exit(1) sys.exit(1)
@ -163,22 +201,29 @@ def main():
# are in place. # are in place.
me = PersonTeam.me me = PersonTeam.me
if op == "rescore": if op == "rescore":
necessary_privs = me.isLpTeamMember('launchpad-buildd-admins') necessary_privs = me.isLpTeamMember("launchpad-buildd-admins")
if op == "retry": if op == "retry":
necessary_privs = me.canUploadPackage(ubuntu_archive, distroseries, necessary_privs = me.canUploadPackage(
sources.getPackageName(), ubuntu_archive,
sources.getComponent(), distroseries,
pocket=pocket) sources.getPackageName(),
sources.getComponent(),
pocket=pocket,
)
if op in ('rescore', 'retry') and not necessary_privs: if op in ("rescore", "retry") and not necessary_privs:
Logger.error("You cannot perform the %s operation on a %s " Logger.error(
"package as you do not have the permissions " "You cannot perform the %s operation on a %s "
"to do this action." % (op, component)) "package as you do not have the permissions "
"to do this action." % (op, component)
)
sys.exit(1) sys.exit(1)
# Output details. # Output details.
Logger.info("The source version for '%s' in %s (%s) is at %s." % Logger.info(
(package, release.capitalize(), component, version)) "The source version for '%s' in %s (%s) is at %s."
% (package, release.capitalize(), component, version)
)
Logger.info("Current build status for this package:") Logger.info("Current build status for this package:")
@ -191,20 +236,20 @@ def main():
done = True done = True
Logger.info("%s: %s." % (build.arch_tag, build.buildstate)) Logger.info("%s: %s." % (build.arch_tag, build.buildstate))
if op == 'rescore': if op == "rescore":
if build.can_be_rescored: if build.can_be_rescored:
# FIXME: make priority an option # FIXME: make priority an option
priority = 5000 priority = 5000
Logger.info('Rescoring build %s to %d...' % (build.arch_tag, priority)) Logger.info("Rescoring build %s to %d..." % (build.arch_tag, priority))
build.rescore(score=priority) build.rescore(score=priority)
else: else:
Logger.info('Cannot rescore build on %s.' % build.arch_tag) Logger.info("Cannot rescore build on %s." % build.arch_tag)
if op == 'retry': if op == "retry":
if build.can_be_retried: if build.can_be_retried:
Logger.info('Retrying build on %s...' % build.arch_tag) Logger.info("Retrying build on %s..." % build.arch_tag)
build.retry() build.retry()
else: else:
Logger.info('Cannot retry build on %s.' % build.arch_tag) Logger.info("Cannot retry build on %s." % build.arch_tag)
# We are done # We are done
if done: if done:
@ -227,29 +272,27 @@ def main():
release = options.series release = options.series
if not release: if not release:
release = (Distribution('ubuntu').getDevelopmentSeries().name release = Distribution("ubuntu").getDevelopmentSeries().name + "-proposed"
+ '-proposed')
try: try:
(release, pocket) = split_release_pocket(release) (release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError as error: except PocketDoesNotExistError as error:
Logger.error(error) Logger.error(error)
sys.exit(1) sys.exit(1)
ubuntu_archive = Distribution('ubuntu').getArchive() ubuntu_archive = Distribution("ubuntu").getArchive()
try: try:
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution("ubuntu").getSeries(release)
except SeriesNotFoundException as error: except SeriesNotFoundException as error:
Logger.error(error) Logger.error(error)
sys.exit(1) sys.exit(1)
me = PersonTeam.me me = PersonTeam.me
# Check permisions (part 1): Rescoring can only be done by buildd admins # Check permisions (part 1): Rescoring can only be done by buildd admins
can_rescore = ((options.priority can_rescore = (options.priority and me.isLpTeamMember("launchpad-buildd-admins")) or False
and me.isLpTeamMember('launchpad-buildd-admins'))
or False)
if options.priority and not can_rescore: if options.priority and not can_rescore:
Logger.error("You don't have the permissions to rescore " Logger.error(
"builds. Ignoring your rescore request.") "You don't have the permissions to rescore builds. Ignoring your rescore request."
)
for pkg in args: for pkg in args:
try: try:
@ -260,17 +303,19 @@ def main():
# Check permissions (part 2): check upload permissions for the source # Check permissions (part 2): check upload permissions for the source
# package # package
can_retry = options.retry and me.canUploadPackage(ubuntu_archive, can_retry = options.retry and me.canUploadPackage(
distroseries, ubuntu_archive, distroseries, pkg.getPackageName(), pkg.getComponent()
pkg.getPackageName(), )
pkg.getComponent())
if options.retry and not can_retry: if options.retry and not can_retry:
Logger.error("You don't have the permissions to retry the " Logger.error(
"build of '%s'. Ignoring your request." "You don't have the permissions to retry the "
% pkg.getPackageName()) "build of '%s'. Ignoring your request." % pkg.getPackageName()
)
Logger.info("The source version for '%s' in '%s' (%s) is: %s" % Logger.info(
(pkg.getPackageName(), release, pocket, pkg.getVersion())) "The source version for '%s' in '%s' (%s) is: %s"
% (pkg.getPackageName(), release, pocket, pkg.getVersion())
)
Logger.info(pkg.getBuildStates(archs)) Logger.info(pkg.getBuildStates(archs))
if can_retry: if can_retry:
@ -278,8 +323,8 @@ def main():
if options.priority and can_rescore: if options.priority and can_rescore:
Logger.info(pkg.rescoreBuilds(archs, options.priority)) Logger.info(pkg.rescoreBuilds(archs, options.priority))
Logger.info('') Logger.info("")
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -25,14 +25,15 @@ import subprocess
import sys import sys
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def extract(iso, path): def extract(iso, path):
command = ['isoinfo', '-R', '-i', iso, '-x', path] command = ["isoinfo", "-R", "-i", iso, "-x", path]
pipe = subprocess.run(command, encoding='utf-8', pipe = subprocess.run(
stdout=subprocess.PIPE, command, encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.PIPE
stderr=subprocess.PIPE) )
if pipe.returncode != 0: if pipe.returncode != 0:
sys.stderr.write(pipe.stderr) sys.stderr.write(pipe.stderr)
@ -42,22 +43,21 @@ def extract(iso, path):
def main(): def main():
desc = 'Given an ISO, %prog will display the Ubuntu version information' desc = "Given an ISO, %prog will display the Ubuntu version information"
parser = optparse.OptionParser(usage='%prog [options] iso...', parser = optparse.OptionParser(usage="%prog [options] iso...", description=desc)
description=desc)
isos = parser.parse_args()[1] isos = parser.parse_args()[1]
err = False err = False
for iso in isos: for iso in isos:
if len(isos) > 1: if len(isos) > 1:
prefix = '%s:' % iso prefix = "%s:" % iso
else: else:
prefix = '' prefix = ""
version = extract(iso, '/.disk/info') version = extract(iso, "/.disk/info")
if len(version) == 0: if len(version) == 0:
Logger.error('%s does not appear to be an Ubuntu ISO' % iso) Logger.error("%s does not appear to be an Ubuntu ISO" % iso)
err = True err = True
continue continue
@ -67,6 +67,6 @@ def main():
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == "__main__":
main() main()
sys.exit(0) sys.exit(0)

View File

@ -17,28 +17,45 @@
import optparse import optparse
import sys import sys
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam, from ubuntutools.lp.lpapicache import (
Packageset, PackageNotFoundException, Launchpad,
SeriesNotFoundException) Distribution,
PersonTeam,
Packageset,
PackageNotFoundException,
SeriesNotFoundException,
)
from ubuntutools.misc import split_release_pocket from ubuntutools.misc import split_release_pocket
from ubuntutools import getLogger from ubuntutools import getLogger
Logger = getLogger() Logger = getLogger()
def parse_arguments(): def parse_arguments():
'''Parse arguments and return (options, package)''' """Parse arguments and return (options, package)"""
parser = optparse.OptionParser('%prog [options] package') parser = optparse.OptionParser("%prog [options] package")
parser.add_option('-r', '--release', default=None, metavar='RELEASE', parser.add_option(
help='Use RELEASE, rather than the current development ' "-r",
'release') "--release",
parser.add_option('-a', '--list-uploaders', default=None,
default=False, action='store_true', metavar="RELEASE",
help='List all the people/teams with upload rights') help="Use RELEASE, rather than the current development release",
parser.add_option('-t', '--list-team-members', )
default=False, action='store_true', parser.add_option(
help='List all team members of teams with upload rights ' "-a",
'(implies --list-uploaders)') "--list-uploaders",
default=False,
action="store_true",
help="List all the people/teams with upload rights",
)
parser.add_option(
"-t",
"--list-team-members",
default=False,
action="store_true",
help="List all team members of teams with upload rights (implies --list-uploaders)",
)
options, args = parser.parse_args() options, args = parser.parse_args()
if len(args) != 1: if len(args) != 1:
@ -52,12 +69,12 @@ def parse_arguments():
def main(): def main():
'''Query upload permissions''' """Query upload permissions"""
options, package = parse_arguments() options, package = parse_arguments()
# Need to be logged in to see uploaders: # Need to be logged in to see uploaders:
Launchpad.login() Launchpad.login()
ubuntu = Distribution('ubuntu') ubuntu = Distribution("ubuntu")
archive = ubuntu.getArchive() archive = ubuntu.getArchive()
if options.release is None: if options.release is None:
options.release = ubuntu.getDevelopmentSeries().name options.release = ubuntu.getDevelopmentSeries().name
@ -74,20 +91,22 @@ def main():
Logger.error(str(e)) Logger.error(str(e))
sys.exit(2) sys.exit(2)
component = spph.getComponent() component = spph.getComponent()
if (options.list_uploaders and (pocket != 'Release' or series.status in if options.list_uploaders and (
('Experimental', 'Active Development', 'Pre-release Freeze'))): pocket != "Release"
or series.status in ("Experimental", "Active Development", "Pre-release Freeze")
):
component_uploader = archive.getUploadersForComponent( component_uploader = archive.getUploadersForComponent(component_name=component)[0]
component_name=component)[0]
Logger.info("All upload permissions for %s:" % package) Logger.info("All upload permissions for %s:" % package)
Logger.info("") Logger.info("")
Logger.info("Component (%s)" % component) Logger.info("Component (%s)" % component)
Logger.info("============" + ("=" * len(component))) Logger.info("============" + ("=" * len(component)))
print_uploaders([component_uploader], options.list_team_members) print_uploaders([component_uploader], options.list_team_members)
packagesets = sorted(Packageset.setsIncludingSource( packagesets = sorted(
distroseries=series, Packageset.setsIncludingSource(distroseries=series, sourcepackagename=package),
sourcepackagename=package), key=lambda p: p.name) key=lambda p: p.name,
)
if packagesets: if packagesets:
Logger.info("") Logger.info("")
Logger.info("Packagesets") Logger.info("Packagesets")
@ -95,11 +114,12 @@ def main():
for packageset in packagesets: for packageset in packagesets:
Logger.info("") Logger.info("")
Logger.info("%s:" % packageset.name) Logger.info("%s:" % packageset.name)
print_uploaders(archive.getUploadersForPackageset( print_uploaders(
packageset=packageset), options.list_team_members) archive.getUploadersForPackageset(packageset=packageset),
options.list_team_members,
)
ppu_uploaders = archive.getUploadersForPackage( ppu_uploaders = archive.getUploadersForPackage(source_package_name=package)
source_package_name=package)
if ppu_uploaders: if ppu_uploaders:
Logger.info("") Logger.info("")
Logger.info("Per-Package-Uploaders") Logger.info("Per-Package-Uploaders")
@ -108,37 +128,45 @@ def main():
print_uploaders(ppu_uploaders, options.list_team_members) print_uploaders(ppu_uploaders, options.list_team_members)
Logger.info("") Logger.info("")
if PersonTeam.me.canUploadPackage(archive, series, package, component, if PersonTeam.me.canUploadPackage(archive, series, package, component, pocket):
pocket):
Logger.info("You can upload %s to %s." % (package, options.release)) Logger.info("You can upload %s to %s." % (package, options.release))
else: else:
Logger.info("You can not upload %s to %s, yourself." % (package, options.release)) Logger.info("You can not upload %s to %s, yourself." % (package, options.release))
if (series.status in ('Current Stable Release', 'Supported', 'Obsolete') if (
and pocket == 'Release'): series.status in ("Current Stable Release", "Supported", "Obsolete")
Logger.info("%s is in the '%s' state. You may want to query the %s-proposed pocket." % and pocket == "Release"
(release, series.status, release)) ):
Logger.info(
"%s is in the '%s' state. You may want to query the %s-proposed pocket."
% (release, series.status, release)
)
else: else:
Logger.info("But you can still contribute to it via the sponsorship " Logger.info(
"process: https://wiki.ubuntu.com/SponsorshipProcess") "But you can still contribute to it via the sponsorship "
"process: https://wiki.ubuntu.com/SponsorshipProcess"
)
if not options.list_uploaders: if not options.list_uploaders:
Logger.info("To see who has the necessary upload rights, " Logger.info(
"use the --list-uploaders option.") "To see who has the necessary upload rights, "
"use the --list-uploaders option."
)
sys.exit(1) sys.exit(1)
def print_uploaders(uploaders, expand_teams=False, prefix=''): def print_uploaders(uploaders, expand_teams=False, prefix=""):
"""Given a list of uploaders, pretty-print them all """Given a list of uploaders, pretty-print them all
Each line is prefixed with prefix. Each line is prefixed with prefix.
If expand_teams is set, recurse, adding more spaces to prefix on each If expand_teams is set, recurse, adding more spaces to prefix on each
recursion. recursion.
""" """
for uploader in sorted(uploaders, key=lambda p: p.display_name): for uploader in sorted(uploaders, key=lambda p: p.display_name):
Logger.info("%s* %s (%s)%s" % Logger.info(
(prefix, uploader.display_name, uploader.name, "%s* %s (%s)%s"
' [team]' if uploader.is_team else '')) % (prefix, uploader.display_name, uploader.name, " [team]" if uploader.is_team else "")
)
if expand_teams and uploader.is_team: if expand_teams and uploader.is_team:
print_uploaders(uploader.participants, True, prefix=prefix + ' ') print_uploaders(uploader.participants, True, prefix=prefix + " ")
if __name__ == '__main__': if __name__ == "__main__":
main() main()

View File

@ -8,7 +8,7 @@ import sys
def getLogger(): def getLogger():
''' Get the logger instance for this module """Get the logger instance for this module
Quick guide for using this or not: if you want to call ubuntutools Quick guide for using this or not: if you want to call ubuntutools
module code and have its output print to stdout/stderr ONLY, you can module code and have its output print to stdout/stderr ONLY, you can
@ -33,12 +33,12 @@ def getLogger():
This should only be used by runnable scripts provided by the This should only be used by runnable scripts provided by the
ubuntu-dev-tools package, or other runnable scripts that want the behavior ubuntu-dev-tools package, or other runnable scripts that want the behavior
described above. described above.
''' """
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
logger.propagate = False logger.propagate = False
fmt = logging.Formatter('%(message)s') fmt = logging.Formatter("%(message)s")
stdout_handler = logging.StreamHandler(stream=sys.stdout) stdout_handler = logging.StreamHandler(stream=sys.stdout)
stdout_handler.setFormatter(fmt) stdout_handler.setFormatter(fmt)
@ -47,7 +47,7 @@ def getLogger():
stderr_handler = logging.StreamHandler(stream=sys.stderr) stderr_handler = logging.StreamHandler(stream=sys.stderr)
stderr_handler.setFormatter(fmt) stderr_handler.setFormatter(fmt)
stderr_handler.setLevel(logging.INFO+1) stderr_handler.setLevel(logging.INFO + 1)
logger.addHandler(stderr_handler) logger.addHandler(stderr_handler)
return logger return logger

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ import os
import subprocess import subprocess
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
@ -35,16 +36,17 @@ class Builder(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"] cmd = ["dpkg-architecture", "-qDEB_BUILD_ARCH_CPU"]
self.architecture = subprocess.check_output(cmd, encoding='utf-8').strip() self.architecture = subprocess.check_output(cmd, encoding="utf-8").strip()
def _build_failure(self, returncode, dsc_file): def _build_failure(self, returncode, dsc_file):
if returncode != 0: if returncode != 0:
Logger.error("Failed to build %s from source with %s." % Logger.error(
(os.path.basename(dsc_file), self.name)) "Failed to build %s from source with %s." % (os.path.basename(dsc_file), self.name)
)
return returncode return returncode
def exists_in_path(self): def exists_in_path(self):
for path in os.environ.get('PATH', os.defpath).split(os.pathsep): for path in os.environ.get("PATH", os.defpath).split(os.pathsep):
if os.path.isfile(os.path.join(path, self.name)): if os.path.isfile(os.path.join(path, self.name)):
return True return True
return False return False
@ -57,8 +59,7 @@ class Builder(object):
def _update_failure(self, returncode, dist): def _update_failure(self, returncode, dist):
if returncode != 0: if returncode != 0:
Logger.error("Failed to update %s chroot for %s." % Logger.error("Failed to update %s chroot for %s." % (dist, self.name))
(dist, self.name))
return returncode return returncode
@ -68,19 +69,39 @@ class Pbuilder(Builder):
def build(self, dsc_file, dist, result_directory): def build(self, dsc_file, dist, result_directory):
_build_preparation(result_directory) _build_preparation(result_directory)
cmd = ["sudo", "-E", "ARCH=" + self.architecture, "DIST=" + dist, cmd = [
self.name, "--build", "sudo",
"--architecture", self.architecture, "--distribution", dist, "-E",
"--buildresult", result_directory, dsc_file] "ARCH=" + self.architecture,
Logger.debug(' '.join(cmd)) "DIST=" + dist,
self.name,
"--build",
"--architecture",
self.architecture,
"--distribution",
dist,
"--buildresult",
result_directory,
dsc_file,
]
Logger.debug(" ".join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
return self._build_failure(returncode, dsc_file) return self._build_failure(returncode, dsc_file)
def update(self, dist): def update(self, dist):
cmd = ["sudo", "-E", "ARCH=" + self.architecture, "DIST=" + dist, cmd = [
self.name, "--update", "sudo",
"--architecture", self.architecture, "--distribution", dist] "-E",
Logger.debug(' '.join(cmd)) "ARCH=" + self.architecture,
"DIST=" + dist,
self.name,
"--update",
"--architecture",
self.architecture,
"--distribution",
dist,
]
Logger.debug(" ".join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
return self._update_failure(returncode, dist) return self._update_failure(returncode, dist)
@ -91,15 +112,22 @@ class Pbuilderdist(Builder):
def build(self, dsc_file, dist, result_directory): def build(self, dsc_file, dist, result_directory):
_build_preparation(result_directory) _build_preparation(result_directory)
cmd = [self.name, dist, self.architecture, cmd = [
"build", dsc_file, "--buildresult", result_directory] self.name,
Logger.debug(' '.join(cmd)) dist,
self.architecture,
"build",
dsc_file,
"--buildresult",
result_directory,
]
Logger.debug(" ".join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
return self._build_failure(returncode, dsc_file) return self._build_failure(returncode, dsc_file)
def update(self, dist): def update(self, dist):
cmd = [self.name, dist, self.architecture, "update"] cmd = [self.name, dist, self.architecture, "update"]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
return self._update_failure(returncode, dist) return self._update_failure(returncode, dist)
@ -113,9 +141,8 @@ class Sbuild(Builder):
workdir = os.getcwd() workdir = os.getcwd()
Logger.debug("cd " + result_directory) Logger.debug("cd " + result_directory)
os.chdir(result_directory) os.chdir(result_directory)
cmd = ["sbuild", "--arch-all", "--dist=" + dist, cmd = ["sbuild", "--arch-all", "--dist=" + dist, "--arch=" + self.architecture, dsc_file]
"--arch=" + self.architecture, dsc_file] Logger.debug(" ".join(cmd))
Logger.debug(' '.join(cmd))
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
Logger.debug("cd " + workdir) Logger.debug("cd " + workdir)
os.chdir(workdir) os.chdir(workdir)
@ -123,29 +150,29 @@ class Sbuild(Builder):
def update(self, dist): def update(self, dist):
cmd = ["schroot", "--list"] cmd = ["schroot", "--list"]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
process = subprocess.run(cmd, stdout=subprocess.PIPE, encoding='utf-8') process = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf-8")
chroots, _ = process.stdout.strip().split() chroots, _ = process.stdout.strip().split()
if process.returncode != 0: if process.returncode != 0:
return process.returncode return process.returncode
params = {"dist": dist, "arch": self.architecture} params = {"dist": dist, "arch": self.architecture}
for chroot in ("%(dist)s-%(arch)s-sbuild-source", for chroot in (
"%(dist)s-sbuild-source", "%(dist)s-%(arch)s-sbuild-source",
"%(dist)s-%(arch)s-source", "%(dist)s-sbuild-source",
"%(dist)s-source"): "%(dist)s-%(arch)s-source",
"%(dist)s-source",
):
chroot = chroot % params chroot = chroot % params
if chroot in chroots: if chroot in chroots:
break break
else: else:
return 1 return 1
commands = [["sbuild-update"], commands = [["sbuild-update"], ["sbuild-distupgrade"], ["sbuild-clean", "-a", "-c"]]
["sbuild-distupgrade"],
["sbuild-clean", "-a", "-c"]]
for cmd in commands: for cmd in commands:
# pylint: disable=W0631 # pylint: disable=W0631
Logger.debug(' '.join(cmd) + " " + chroot) Logger.debug(" ".join(cmd) + " " + chroot)
ret = subprocess.call(cmd + [chroot]) ret = subprocess.call(cmd + [chroot])
# pylint: enable=W0631 # pylint: enable=W0631
if ret != 0: if ret != 0:
@ -170,5 +197,4 @@ def get_builder(name):
Logger.error("Builder doesn't appear to be installed: %s", name) Logger.error("Builder doesn't appear to be installed: %s", name)
else: else:
Logger.error("Unsupported builder specified: %s.", name) Logger.error("Unsupported builder specified: %s.", name)
Logger.error("Supported builders: %s", Logger.error("Supported builders: %s", ", ".join(sorted(_SUPPORTED_BUILDERS.keys())))
", ".join(sorted(_SUPPORTED_BUILDERS.keys())))

View File

@ -24,6 +24,7 @@ import sys
import locale import locale
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
@ -31,23 +32,24 @@ class UDTConfig(object):
"""Ubuntu Dev Tools configuration file (devscripts config file) and """Ubuntu Dev Tools configuration file (devscripts config file) and
environment variable parsing. environment variable parsing.
""" """
no_conf = False no_conf = False
# Package wide configuration variables. # Package wide configuration variables.
# These are reqired to be used by at least two scripts. # These are reqired to be used by at least two scripts.
defaults = { defaults = {
'BUILDER': 'pbuilder', "BUILDER": "pbuilder",
'DEBIAN_MIRROR': 'http://deb.debian.org/debian', "DEBIAN_MIRROR": "http://deb.debian.org/debian",
'DEBSEC_MIRROR': 'http://security.debian.org', "DEBSEC_MIRROR": "http://security.debian.org",
'DEBIAN_DDEBS_MIRROR': 'http://debug.mirrors.debian.org/debian-debug', "DEBIAN_DDEBS_MIRROR": "http://debug.mirrors.debian.org/debian-debug",
'LPINSTANCE': 'production', "LPINSTANCE": "production",
'MIRROR_FALLBACK': True, "MIRROR_FALLBACK": True,
'UBUNTU_MIRROR': 'http://archive.ubuntu.com/ubuntu', "UBUNTU_MIRROR": "http://archive.ubuntu.com/ubuntu",
'UBUNTU_PORTS_MIRROR': 'http://ports.ubuntu.com', "UBUNTU_PORTS_MIRROR": "http://ports.ubuntu.com",
'UBUNTU_INTERNAL_MIRROR': 'http://ftpmaster.internal/ubuntu', "UBUNTU_INTERNAL_MIRROR": "http://ftpmaster.internal/ubuntu",
'UBUNTU_DDEBS_MIRROR': 'http://ddebs.ubuntu.com', "UBUNTU_DDEBS_MIRROR": "http://ddebs.ubuntu.com",
'UPDATE_BUILDER': False, "UPDATE_BUILDER": False,
'WORKDIR': None, "WORKDIR": None,
'KEYID': None, "KEYID": None,
} }
# Populated from the configuration files: # Populated from the configuration files:
config = {} config = {}
@ -55,7 +57,7 @@ class UDTConfig(object):
def __init__(self, no_conf=False, prefix=None): def __init__(self, no_conf=False, prefix=None):
self.no_conf = no_conf self.no_conf = no_conf
if prefix is None: if prefix is None:
prefix = os.path.basename(sys.argv[0]).upper().replace('-', '_') prefix = os.path.basename(sys.argv[0]).upper().replace("-", "_")
self.prefix = prefix self.prefix = prefix
if not no_conf: if not no_conf:
self.config = self.parse_devscripts_config() self.config = self.parse_devscripts_config()
@ -65,18 +67,21 @@ class UDTConfig(object):
dictionary dictionary
""" """
config = {} config = {}
for filename in ('/etc/devscripts.conf', '~/.devscripts'): for filename in ("/etc/devscripts.conf", "~/.devscripts"):
try: try:
f = open(os.path.expanduser(filename), 'r') f = open(os.path.expanduser(filename), "r")
except IOError: except IOError:
continue continue
for line in f: for line in f:
parsed = shlex.split(line, comments=True) parsed = shlex.split(line, comments=True)
if len(parsed) > 1: if len(parsed) > 1:
Logger.warning('Cannot parse variable assignment in %s: %s', Logger.warning(
getattr(f, 'name', '<config>'), line) "Cannot parse variable assignment in %s: %s",
if len(parsed) >= 1 and '=' in parsed[0]: getattr(f, "name", "<config>"),
key, value = parsed[0].split('=', 1) line,
)
if len(parsed) >= 1 and "=" in parsed[0]:
key, value = parsed[0].split("=", 1)
config[key] = value config[key] = value
f.close() f.close()
return config return config
@ -95,9 +100,9 @@ class UDTConfig(object):
if default is None and key in self.defaults: if default is None and key in self.defaults:
default = self.defaults[key] default = self.defaults[key]
keys = [self.prefix + '_' + key] keys = [self.prefix + "_" + key]
if key in self.defaults: if key in self.defaults:
keys.append('UBUNTUTOOLS_' + key) keys.append("UBUNTUTOOLS_" + key)
keys += compat_keys keys += compat_keys
for k in keys: for k in keys:
@ -105,16 +110,19 @@ class UDTConfig(object):
if k in store: if k in store:
value = store[k] value = store[k]
if boolean: if boolean:
if value in ('yes', 'no'): if value in ("yes", "no"):
value = value == 'yes' value = value == "yes"
else: else:
continue continue
if k in compat_keys: if k in compat_keys:
replacements = self.prefix + '_' + key replacements = self.prefix + "_" + key
if key in self.defaults: if key in self.defaults:
replacements += 'or UBUNTUTOOLS_' + key replacements += "or UBUNTUTOOLS_" + key
Logger.warning('Using deprecated configuration variable %s. ' Logger.warning(
'You should use %s.', k, replacements) "Using deprecated configuration variable %s. You should use %s.",
k,
replacements,
)
return value return value
return default return default
@ -132,7 +140,7 @@ def ubu_email(name=None, email=None, export=True):
Return name, email. Return name, email.
""" """
name_email_re = re.compile(r'^\s*(.+?)\s*<(.+@.+)>\s*$') name_email_re = re.compile(r"^\s*(.+?)\s*<(.+@.+)>\s*$")
if email: if email:
match = name_email_re.match(email) match = name_email_re.match(email)
@ -140,11 +148,16 @@ def ubu_email(name=None, email=None, export=True):
name = match.group(1) name = match.group(1)
email = match.group(2) email = match.group(2)
if export and not name and not email and 'UBUMAIL' not in os.environ: if export and not name and not email and "UBUMAIL" not in os.environ:
export = False export = False
for var, target in (('UBUMAIL', 'email'), ('DEBFULLNAME', 'name'), ('DEBEMAIL', 'email'), for var, target in (
('EMAIL', 'email'), ('NAME', 'name')): ("UBUMAIL", "email"),
("DEBFULLNAME", "name"),
("DEBEMAIL", "email"),
("EMAIL", "email"),
("NAME", "name"),
):
if name and email: if name and email:
break break
if var in os.environ: if var in os.environ:
@ -154,30 +167,30 @@ def ubu_email(name=None, email=None, export=True):
name = match.group(1) name = match.group(1)
if not email: if not email:
email = match.group(2) email = match.group(2)
elif target == 'name' and not name: elif target == "name" and not name:
name = os.environ[var].strip() name = os.environ[var].strip()
elif target == 'email' and not email: elif target == "email" and not email:
email = os.environ[var].strip() email = os.environ[var].strip()
if not name: if not name:
gecos_name = pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip() gecos_name = pwd.getpwuid(os.getuid()).pw_gecos.split(",")[0].strip()
if gecos_name: if gecos_name:
name = gecos_name name = gecos_name
if not email: if not email:
mailname = socket.getfqdn() mailname = socket.getfqdn()
if os.path.isfile('/etc/mailname'): if os.path.isfile("/etc/mailname"):
mailname = open('/etc/mailname', 'r').read().strip() mailname = open("/etc/mailname", "r").read().strip()
email = pwd.getpwuid(os.getuid()).pw_name + '@' + mailname email = pwd.getpwuid(os.getuid()).pw_name + "@" + mailname
if export: if export:
os.environ['DEBFULLNAME'] = name os.environ["DEBFULLNAME"] = name
os.environ['DEBEMAIL'] = email os.environ["DEBEMAIL"] = email
# decode env var or gecos raw string with the current locale's encoding # decode env var or gecos raw string with the current locale's encoding
encoding = locale.getdefaultlocale()[1] encoding = locale.getdefaultlocale()[1]
if not encoding: if not encoding:
encoding = 'utf-8' encoding = "utf-8"
if name and isinstance(name, bytes): if name and isinstance(name, bytes):
name = name.decode(encoding) name = name.decode(encoding)
return name, email return name, email

View File

@ -2,5 +2,5 @@
# ubuntu-dev-tools Launchpad Python modules. # ubuntu-dev-tools Launchpad Python modules.
# #
service = 'production' service = "production"
api_version = 'devel' api_version = "devel"

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,40 @@
class PackageNotFoundException(BaseException): class PackageNotFoundException(BaseException):
""" Thrown when a package is not found """ """Thrown when a package is not found"""
pass pass
class SeriesNotFoundException(BaseException): class SeriesNotFoundException(BaseException):
""" Thrown when a distroseries is not found """ """Thrown when a distroseries is not found"""
pass pass
class PocketDoesNotExistError(Exception): class PocketDoesNotExistError(Exception):
'''Raised when a invalid pocket is used.''' """Raised when a invalid pocket is used."""
pass pass
class ArchiveNotFoundException(BaseException): class ArchiveNotFoundException(BaseException):
""" Thrown when an archive for a distibution is not found """ """Thrown when an archive for a distibution is not found"""
pass pass
class AlreadyLoggedInError(Exception): class AlreadyLoggedInError(Exception):
'''Raised when a second login is attempted.''' """Raised when a second login is attempted."""
pass pass
class ArchSeriesNotFoundException(BaseException): class ArchSeriesNotFoundException(BaseException):
"""Thrown when a distroarchseries is not found.""" """Thrown when a distroarchseries is not found."""
pass pass
class InvalidDistroValueError(ValueError): class InvalidDistroValueError(ValueError):
""" Thrown when distro value is invalid """ """Thrown when distro value is invalid"""
pass pass

View File

@ -39,16 +39,17 @@ from urllib.parse import urlparse
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
DEFAULT_POCKETS = ('Release', 'Security', 'Updates', 'Proposed') DEFAULT_POCKETS = ("Release", "Security", "Updates", "Proposed")
POCKETS = DEFAULT_POCKETS + ('Backports',) POCKETS = DEFAULT_POCKETS + ("Backports",)
DEFAULT_STATUSES = ('Pending', 'Published') DEFAULT_STATUSES = ("Pending", "Published")
STATUSES = DEFAULT_STATUSES + ('Superseded', 'Deleted', 'Obsolete') STATUSES = DEFAULT_STATUSES + ("Superseded", "Deleted", "Obsolete")
UPLOAD_QUEUE_STATUSES = ('New', 'Unapproved', 'Accepted', 'Done', 'Rejected') UPLOAD_QUEUE_STATUSES = ("New", "Unapproved", "Accepted", "Done", "Rejected")
DOWNLOAD_BLOCKSIZE_DEFAULT = 8192 DOWNLOAD_BLOCKSIZE_DEFAULT = 8192
@ -66,7 +67,7 @@ class NotFoundError(DownloadError):
def system_distribution_chain(): def system_distribution_chain():
""" system_distribution_chain() -> [string] """system_distribution_chain() -> [string]
Detect the system's distribution as well as all of its parent Detect the system's distribution as well as all of its parent
distributions and return them as a list of strings, with the distributions and return them as a list of strings, with the
@ -77,18 +78,24 @@ def system_distribution_chain():
global _system_distribution_chain global _system_distribution_chain
if len(_system_distribution_chain) == 0: if len(_system_distribution_chain) == 0:
try: try:
vendor = check_output(('dpkg-vendor', '--query', 'Vendor'), vendor = check_output(("dpkg-vendor", "--query", "Vendor"), encoding="utf-8").strip()
encoding='utf-8').strip()
_system_distribution_chain.append(vendor) _system_distribution_chain.append(vendor)
except CalledProcessError: except CalledProcessError:
Logger.error('Could not determine what distribution you are running.') Logger.error("Could not determine what distribution you are running.")
return [] return []
while True: while True:
try: try:
parent = check_output(( parent = check_output(
'dpkg-vendor', '--vendor', _system_distribution_chain[-1], (
'--query', 'Parent'), encoding='utf-8').strip() "dpkg-vendor",
"--vendor",
_system_distribution_chain[-1],
"--query",
"Parent",
),
encoding="utf-8",
).strip()
except CalledProcessError: except CalledProcessError:
# Vendor has no parent # Vendor has no parent
break break
@ -98,7 +105,7 @@ def system_distribution_chain():
def system_distribution(): def system_distribution():
""" system_distro() -> string """system_distro() -> string
Detect the system's distribution and return it as a string. If the Detect the system's distribution and return it as a string. If the
name of the distribution can't be determined, print an error message name of the distribution can't be determined, print an error message
@ -108,28 +115,26 @@ def system_distribution():
def host_architecture(): def host_architecture():
""" host_architecture -> string """host_architecture -> string
Detect the host's architecture and return it as a string. If the Detect the host's architecture and return it as a string. If the
architecture can't be determined, print an error message and return None. architecture can't be determined, print an error message and return None.
""" """
try: try:
arch = check_output(('dpkg', '--print-architecture'), arch = check_output(("dpkg", "--print-architecture"), encoding="utf-8").strip()
encoding='utf-8').strip()
except CalledProcessError: except CalledProcessError:
arch = None arch = None
if not arch or 'not found' in arch: if not arch or "not found" in arch:
Logger.error('Not running on a Debian based system; ' Logger.error("Not running on a Debian based system; could not detect its architecture.")
'could not detect its architecture.')
return None return None
return arch return arch
def readlist(filename, uniq=True): def readlist(filename, uniq=True):
""" readlist(filename, uniq) -> list """readlist(filename, uniq) -> list
Read a list of words from the indicated file. If 'uniq' is True, filter Read a list of words from the indicated file. If 'uniq' is True, filter
out duplicated words. out duplicated words.
@ -137,13 +142,13 @@ def readlist(filename, uniq=True):
p = Path(filename) p = Path(filename)
if not p.is_file(): if not p.is_file():
Logger.error(f'File {p} does not exist.') Logger.error(f"File {p} does not exist.")
return False return False
content = p.read_text().replace('\n', ' ').replace(',', ' ') content = p.read_text().replace("\n", " ").replace(",", " ")
if not content.strip(): if not content.strip():
Logger.error(f'File {p} is empty.') Logger.error(f"File {p} is empty.")
return False return False
items = [item for item in content.split() if item] items = [item for item in content.split() if item]
@ -154,21 +159,21 @@ def readlist(filename, uniq=True):
return items return items
def split_release_pocket(release, default='Release'): def split_release_pocket(release, default="Release"):
'''Splits the release and pocket name. """Splits the release and pocket name.
If the argument doesn't contain a pocket name then the 'Release' pocket If the argument doesn't contain a pocket name then the 'Release' pocket
is assumed. is assumed.
Returns the release and pocket name. Returns the release and pocket name.
''' """
pocket = default pocket = default
if release is None: if release is None:
raise ValueError('No release name specified') raise ValueError("No release name specified")
if '-' in release: if "-" in release:
(release, pocket) = release.rsplit('-', 1) (release, pocket) = release.rsplit("-", 1)
pocket = pocket.capitalize() pocket = pocket.capitalize()
if pocket not in POCKETS: if pocket not in POCKETS:
@ -178,18 +183,20 @@ def split_release_pocket(release, default='Release'):
def require_utf8(): def require_utf8():
'''Can be called by programs that only function in UTF-8 locales''' """Can be called by programs that only function in UTF-8 locales"""
if locale.getpreferredencoding() != 'UTF-8': if locale.getpreferredencoding() != "UTF-8":
Logger.error("This program only functions in a UTF-8 locale. Aborting.") Logger.error("This program only functions in a UTF-8 locale. Aborting.")
sys.exit(1) sys.exit(1)
_vendor_to_distroinfo = {"Debian": distro_info.DebianDistroInfo, _vendor_to_distroinfo = {
"Ubuntu": distro_info.UbuntuDistroInfo} "Debian": distro_info.DebianDistroInfo,
"Ubuntu": distro_info.UbuntuDistroInfo,
}
def vendor_to_distroinfo(vendor): def vendor_to_distroinfo(vendor):
""" vendor_to_distroinfo(string) -> DistroInfo class """vendor_to_distroinfo(string) -> DistroInfo class
Convert a string name of a distribution into a DistroInfo subclass Convert a string name of a distribution into a DistroInfo subclass
representing that distribution, or None if the distribution is representing that distribution, or None if the distribution is
@ -199,7 +206,7 @@ def vendor_to_distroinfo(vendor):
def codename_to_distribution(codename): def codename_to_distribution(codename):
""" codename_to_distribution(string) -> string """codename_to_distribution(string) -> string
Finds a given release codename in your distribution's genaology Finds a given release codename in your distribution's genaology
(i.e. looking at the current distribution and its parents), or (i.e. looking at the current distribution and its parents), or
@ -215,7 +222,7 @@ def codename_to_distribution(codename):
def verify_file_checksums(pathname, checksums={}, size=0): def verify_file_checksums(pathname, checksums={}, size=0):
""" verify checksums of file """verify checksums of file
Any failure will log an error. Any failure will log an error.
@ -231,16 +238,16 @@ def verify_file_checksums(pathname, checksums={}, size=0):
p = Path(pathname) p = Path(pathname)
if not p.is_file(): if not p.is_file():
Logger.error(f'File {p} not found') Logger.error(f"File {p} not found")
return False return False
filesize = p.stat().st_size filesize = p.stat().st_size
if size and size != filesize: if size and size != filesize:
Logger.error(f'File {p} incorrect size, got {filesize} expected {size}') Logger.error(f"File {p} incorrect size, got {filesize} expected {size}")
return False return False
for (alg, checksum) in checksums.items(): for (alg, checksum) in checksums.items():
h = hashlib.new(alg) h = hashlib.new(alg)
with p.open('rb') as f: with p.open("rb") as f:
while True: while True:
block = f.read(h.block_size) block = f.read(h.block_size)
if len(block) == 0: if len(block) == 0:
@ -248,15 +255,15 @@ def verify_file_checksums(pathname, checksums={}, size=0):
h.update(block) h.update(block)
digest = h.hexdigest() digest = h.hexdigest()
if digest == checksum: if digest == checksum:
Logger.debug(f'File {p} checksum ({alg}) verified: {checksum}') Logger.debug(f"File {p} checksum ({alg}) verified: {checksum}")
else: else:
Logger.error(f'File {p} checksum ({alg}) mismatch: got {digest} expected {checksum}') Logger.error(f"File {p} checksum ({alg}) mismatch: got {digest} expected {checksum}")
return False return False
return True return True
def verify_file_checksum(pathname, alg, checksum, size=0): def verify_file_checksum(pathname, alg, checksum, size=0):
""" verify checksum of file """verify checksum of file
pathname: str or Path pathname: str or Path
full path to file full path to file
@ -273,7 +280,7 @@ def verify_file_checksum(pathname, alg, checksum, size=0):
def extract_authentication(url): def extract_authentication(url):
""" Remove plaintext authentication data from a URL """Remove plaintext authentication data from a URL
If the URL has a username:password in its netloc, this removes it If the URL has a username:password in its netloc, this removes it
and returns the remaining URL, along with the username and password and returns the remaining URL, along with the username and password
@ -289,7 +296,7 @@ def extract_authentication(url):
def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
""" download/copy a file/url to local file """download/copy a file/url to local file
src: str or Path src: str or Path
Source to copy from (file path or url) Source to copy from (file path or url)
@ -315,18 +322,18 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
dst = dst / Path(parsedsrc.path).name dst = dst / Path(parsedsrc.path).name
# Copy if src is a local file # Copy if src is a local file
if parsedsrc.scheme in ['', 'file']: if parsedsrc.scheme in ["", "file"]:
src = Path(parsedsrc.path).expanduser().resolve() src = Path(parsedsrc.path).expanduser().resolve()
if src != parsedsrc.path: if src != parsedsrc.path:
Logger.info(f'Parsed {parsedsrc.path} as {src}') Logger.info(f"Parsed {parsedsrc.path} as {src}")
if not src.exists(): if not src.exists():
raise NotFoundError(f'Source file {src} not found') raise NotFoundError(f"Source file {src} not found")
if dst.exists(): if dst.exists():
if src.samefile(dst): if src.samefile(dst):
Logger.info(f'Using existing file {dst}') Logger.info(f"Using existing file {dst}")
return dst return dst
Logger.info(f'Replacing existing file {dst}') Logger.info(f"Replacing existing file {dst}")
Logger.info(f'Copying file {src} to {dst}') Logger.info(f"Copying file {src} to {dst}")
shutil.copyfile(src, dst) shutil.copyfile(src, dst)
return dst return dst
@ -334,18 +341,18 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
auth = (username, password) if username or password else None auth = (username, password) if username or password else None
with tempfile.TemporaryDirectory() as d: with tempfile.TemporaryDirectory() as d:
tmpdst = Path(d) / 'dst' tmpdst = Path(d) / "dst"
try: try:
with requests.get(src, stream=True, auth=auth) as fsrc, tmpdst.open('wb') as fdst: with requests.get(src, stream=True, auth=auth) as fsrc, tmpdst.open("wb") as fdst:
fsrc.raise_for_status() fsrc.raise_for_status()
_download(fsrc, fdst, size, blocksize=blocksize) _download(fsrc, fdst, size, blocksize=blocksize)
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e:
if e.response is not None and e.response.status_code == 404: if e.response is not None and e.response.status_code == 404:
raise NotFoundError(f'URL {src} not found: {e}') raise NotFoundError(f"URL {src} not found: {e}")
raise DownloadError(e) raise DownloadError(e)
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
# This is likely a archive hostname that doesn't resolve, like 'ftpmaster.internal' # This is likely a archive hostname that doesn't resolve, like 'ftpmaster.internal'
raise NotFoundError(f'URL {src} not found: {e}') raise NotFoundError(f"URL {src} not found: {e}")
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
raise DownloadError(e) raise DownloadError(e)
shutil.move(tmpdst, dst) shutil.move(tmpdst, dst)
@ -358,60 +365,64 @@ class _StderrProgressBar(object):
def __init__(self, max_width): def __init__(self, max_width):
self.full_width = min(max_width, self.BAR_WIDTH_DEFAULT) self.full_width = min(max_width, self.BAR_WIDTH_DEFAULT)
self.width = self.full_width - len('[] 99%') self.width = self.full_width - len("[] 99%")
self.show_progress = self.full_width >= self.BAR_WIDTH_MIN self.show_progress = self.full_width >= self.BAR_WIDTH_MIN
def update(self, progress, total): def update(self, progress, total):
if not self.show_progress: if not self.show_progress:
return return
pct = progress * 100 // total pct = progress * 100 // total
pctstr = f'{pct:>3}%' pctstr = f"{pct:>3}%"
barlen = self.width * pct // 100 barlen = self.width * pct // 100
barstr = '=' * barlen barstr = "=" * barlen
barstr = barstr[:-1] + '>' barstr = barstr[:-1] + ">"
barstr = barstr.ljust(self.width) barstr = barstr.ljust(self.width)
fullstr = f'\r[{barstr}]{pctstr}' fullstr = f"\r[{barstr}]{pctstr}"
sys.stderr.write(fullstr) sys.stderr.write(fullstr)
sys.stderr.flush() sys.stderr.flush()
def finish(self): def finish(self):
if not self.show_progress: if not self.show_progress:
return return
sys.stderr.write('\n') sys.stderr.write("\n")
sys.stderr.flush() sys.stderr.flush()
def _download(fsrc, fdst, size, *, blocksize): def _download(fsrc, fdst, size, *, blocksize):
""" helper method to download src to dst using requests library. """ """helper method to download src to dst using requests library."""
url = fsrc.url url = fsrc.url
Logger.debug(f'Using URL: {url}') Logger.debug(f"Using URL: {url}")
if not size: if not size:
with suppress(AttributeError, TypeError, ValueError): with suppress(AttributeError, TypeError, ValueError):
size = int(fsrc.headers.get('Content-Length')) size = int(fsrc.headers.get("Content-Length"))
parsed = urlparse(url) parsed = urlparse(url)
filename = Path(parsed.path).name filename = Path(parsed.path).name
hostname = parsed.hostname hostname = parsed.hostname
sizemb = ' (%0.3f MiB)' % (size / 1024.0 / 1024) if size else '' sizemb = " (%0.3f MiB)" % (size / 1024.0 / 1024) if size else ""
Logger.info(f'Downloading {filename} from {hostname}{sizemb}') Logger.info(f"Downloading {filename} from {hostname}{sizemb}")
# Don't show progress if: # Don't show progress if:
# logging INFO is suppressed # logging INFO is suppressed
# stderr isn't a tty # stderr isn't a tty
# we don't know the total file size # we don't know the total file size
# the file is content-encoded (i.e. compressed) # the file is content-encoded (i.e. compressed)
show_progress = all((Logger.isEnabledFor(logging.INFO), show_progress = all(
sys.stderr.isatty(), (
size > 0, Logger.isEnabledFor(logging.INFO),
'Content-Encoding' not in fsrc.headers)) sys.stderr.isatty(),
size > 0,
"Content-Encoding" not in fsrc.headers,
)
)
terminal_width = 0 terminal_width = 0
if show_progress: if show_progress:
try: try:
terminal_width = os.get_terminal_size(sys.stderr.fileno()).columns terminal_width = os.get_terminal_size(sys.stderr.fileno()).columns
except Exception as e: except Exception as e:
Logger.error(f'Error finding stderr width, suppressing progress bar: {e}') Logger.error(f"Error finding stderr width, suppressing progress bar: {e}")
progress_bar = _StderrProgressBar(max_width=terminal_width) progress_bar = _StderrProgressBar(max_width=terminal_width)
downloaded = 0 downloaded = 0
@ -423,20 +434,21 @@ def _download(fsrc, fdst, size, *, blocksize):
finally: finally:
progress_bar.finish() progress_bar.finish()
if size and size > downloaded: if size and size > downloaded:
Logger.error('Partial download: %0.3f MiB of %0.3f MiB' % Logger.error(
(downloaded / 1024.0 / 1024, "Partial download: %0.3f MiB of %0.3f MiB"
size / 1024.0 / 1024)) % (downloaded / 1024.0 / 1024, size / 1024.0 / 1024)
)
def _download_text(src, binary, *, blocksize): def _download_text(src, binary, *, blocksize):
with tempfile.TemporaryDirectory() as d: with tempfile.TemporaryDirectory() as d:
dst = Path(d) / 'dst' dst = Path(d) / "dst"
download(src, dst, blocksize=blocksize) download(src, dst, blocksize=blocksize)
return dst.read_bytes() if binary else dst.read_text() return dst.read_bytes() if binary else dst.read_text()
def download_text(src, mode=None, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): def download_text(src, mode=None, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
""" Return the text content of a downloaded file """Return the text content of a downloaded file
src: str or Path src: str or Path
Source to copy from (file path or url) Source to copy from (file path or url)
@ -449,9 +461,9 @@ def download_text(src, mode=None, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
Returns text content of downloaded file Returns text content of downloaded file
""" """
return _download_text(src, binary='b' in (mode or ''), blocksize=blocksize) return _download_text(src, binary="b" in (mode or ""), blocksize=blocksize)
def download_bytes(src, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): def download_bytes(src, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT):
""" Same as download_text() but returns bytes """ """Same as download_text() but returns bytes"""
return _download_text(src, binary=True, blocksize=blocksize) return _download_text(src, binary=True, blocksize=blocksize)

View File

@ -34,42 +34,50 @@ from distro_info import DebianDistroInfo
from urllib.parse import urlparse from urllib.parse import urlparse
from ubuntutools.archive import (UbuntuSourcePackage, DebianSourcePackage, from ubuntutools.archive import (
UbuntuCloudArchiveSourcePackage, UbuntuSourcePackage,
PersonalPackageArchiveSourcePackage) DebianSourcePackage,
UbuntuCloudArchiveSourcePackage,
PersonalPackageArchiveSourcePackage,
)
from ubuntutools.config import UDTConfig from ubuntutools.config import UDTConfig
from ubuntutools.lp.lpapicache import (Distribution, Launchpad) from ubuntutools.lp.lpapicache import Distribution, Launchpad
from ubuntutools.lp.udtexceptions import (AlreadyLoggedInError, from ubuntutools.lp.udtexceptions import (
SeriesNotFoundException, AlreadyLoggedInError,
PackageNotFoundException, SeriesNotFoundException,
PocketDoesNotExistError, PackageNotFoundException,
InvalidDistroValueError) PocketDoesNotExistError,
from ubuntutools.misc import (split_release_pocket, InvalidDistroValueError,
host_architecture, )
download, from ubuntutools.misc import (
UPLOAD_QUEUE_STATUSES, split_release_pocket,
STATUSES) host_architecture,
download,
UPLOAD_QUEUE_STATUSES,
STATUSES,
)
# by default we use standard logging.getLogger() and only use # by default we use standard logging.getLogger() and only use
# ubuntutools.getLogger() in PullPkg().main() # ubuntutools.getLogger() in PullPkg().main()
from ubuntutools import getLogger as ubuntutools_getLogger from ubuntutools import getLogger as ubuntutools_getLogger
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
PULL_SOURCE = 'source' PULL_SOURCE = "source"
PULL_DEBS = 'debs' PULL_DEBS = "debs"
PULL_DDEBS = 'ddebs' PULL_DDEBS = "ddebs"
PULL_UDEBS = 'udebs' PULL_UDEBS = "udebs"
PULL_LIST = 'list' PULL_LIST = "list"
VALID_PULLS = [PULL_SOURCE, PULL_DEBS, PULL_DDEBS, PULL_UDEBS, PULL_LIST] VALID_PULLS = [PULL_SOURCE, PULL_DEBS, PULL_DDEBS, PULL_UDEBS, PULL_LIST]
VALID_BINARY_PULLS = [PULL_DEBS, PULL_DDEBS, PULL_UDEBS] VALID_BINARY_PULLS = [PULL_DEBS, PULL_DDEBS, PULL_UDEBS]
DISTRO_DEBIAN = 'debian' DISTRO_DEBIAN = "debian"
DISTRO_UBUNTU = 'ubuntu' DISTRO_UBUNTU = "ubuntu"
DISTRO_UCA = 'uca' DISTRO_UCA = "uca"
DISTRO_PPA = 'ppa' DISTRO_PPA = "ppa"
DISTRO_PKG_CLASS = { DISTRO_PKG_CLASS = {
DISTRO_DEBIAN: DebianSourcePackage, DISTRO_DEBIAN: DebianSourcePackage,
@ -81,12 +89,14 @@ VALID_DISTROS = DISTRO_PKG_CLASS.keys()
class InvalidPullValueError(ValueError): class InvalidPullValueError(ValueError):
""" Thrown when --pull value is invalid """ """Thrown when --pull value is invalid"""
pass pass
class PullPkg(object): class PullPkg(object):
"""Class used to pull file(s) associated with a specific package""" """Class used to pull file(s) associated with a specific package"""
@classmethod @classmethod
def main(cls, *args, **kwargs): def main(cls, *args, **kwargs):
"""For use by stand-alone cmdline scripts. """For use by stand-alone cmdline scripts.
@ -107,53 +117,67 @@ class PullPkg(object):
cls(*args, **kwargs).pull() cls(*args, **kwargs).pull()
return return
except KeyboardInterrupt: except KeyboardInterrupt:
Logger.info('User abort.') Logger.info("User abort.")
except (PackageNotFoundException, SeriesNotFoundException, except (
PocketDoesNotExistError, InvalidDistroValueError, PackageNotFoundException,
InvalidPullValueError) as e: SeriesNotFoundException,
PocketDoesNotExistError,
InvalidDistroValueError,
InvalidPullValueError,
) as e:
Logger.error(str(e)) Logger.error(str(e))
sys.exit(errno.ENOENT) sys.exit(errno.ENOENT)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self._default_pull = kwargs.get('pull') self._default_pull = kwargs.get("pull")
self._default_distro = kwargs.get('distro') self._default_distro = kwargs.get("distro")
self._default_arch = kwargs.get('arch', host_architecture()) self._default_arch = kwargs.get("arch", host_architecture())
def parse_args(self, args): def parse_args(self, args):
args = args[:] args = args[:]
help_default_pull = "What to pull: " + ", ".join(VALID_PULLS) help_default_pull = "What to pull: " + ", ".join(VALID_PULLS)
if self._default_pull: if self._default_pull:
help_default_pull += (" (default: %s)" % self._default_pull) help_default_pull += " (default: %s)" % self._default_pull
help_default_distro = "Pull from: " + ", ".join(VALID_DISTROS) help_default_distro = "Pull from: " + ", ".join(VALID_DISTROS)
if self._default_distro: if self._default_distro:
help_default_distro += (" (default: %s)" % self._default_distro) help_default_distro += " (default: %s)" % self._default_distro
help_default_arch = ("Get binary packages for arch") help_default_arch = "Get binary packages for arch"
help_default_arch += ("(default: %s)" % self._default_arch) help_default_arch += "(default: %s)" % self._default_arch
# use add_help=False because we do parse_known_args() below, and if # use add_help=False because we do parse_known_args() below, and if
# that sees --help then it exits immediately # that sees --help then it exits immediately
parser = ArgumentParser(add_help=False) parser = ArgumentParser(add_help=False)
parser.add_argument('-L', '--login', action='store_true', parser.add_argument("-L", "--login", action="store_true", help="Login to Launchpad")
help="Login to Launchpad") parser.add_argument(
parser.add_argument('-v', '--verbose', action='count', default=0, "-v", "--verbose", action="count", default=0, help="Increase verbosity/debug"
help="Increase verbosity/debug") )
parser.add_argument('-d', '--download-only', action='store_true', parser.add_argument(
help="Do not extract the source package") "-d", "--download-only", action="store_true", help="Do not extract the source package"
parser.add_argument('-m', '--mirror', action='append', )
help='Preferred mirror(s)') parser.add_argument("-m", "--mirror", action="append", help="Preferred mirror(s)")
parser.add_argument('--no-conf', action='store_true', parser.add_argument(
help="Don't read config files or environment variables") "--no-conf",
parser.add_argument('--no-verify-signature', action='store_true', action="store_true",
help="Don't fail if dsc signature can't be verified") help="Don't read config files or environment variables",
parser.add_argument('-s', '--status', action='append', default=[], )
help="Search for packages with specific status(es)") parser.add_argument(
parser.add_argument('-a', '--arch', default=self._default_arch, "--no-verify-signature",
help=help_default_arch) action="store_true",
parser.add_argument('-p', '--pull', default=self._default_pull, help="Don't fail if dsc signature can't be verified",
help=help_default_pull) )
parser.add_argument('-D', '--distro', default=self._default_distro, parser.add_argument(
help=help_default_distro) "-s",
"--status",
action="append",
default=[],
help="Search for packages with specific status(es)",
)
parser.add_argument("-a", "--arch", default=self._default_arch, help=help_default_arch)
parser.add_argument("-p", "--pull", default=self._default_pull, help=help_default_pull)
parser.add_argument(
"-D", "--distro", default=self._default_distro, help=help_default_distro
)
# add distro-specific params # add distro-specific params
try: try:
@ -163,30 +187,36 @@ class PullPkg(object):
distro = None distro = None
if distro == DISTRO_UBUNTU: if distro == DISTRO_UBUNTU:
parser.add_argument('--security', action='store_true', parser.add_argument(
help='Pull from the Ubuntu Security Team (proposed) PPA') "--security",
parser.add_argument('--upload-queue', action='store_true', action="store_true",
help='Pull from the Ubuntu upload queue') help="Pull from the Ubuntu Security Team (proposed) PPA",
)
parser.add_argument(
"--upload-queue", action="store_true", help="Pull from the Ubuntu upload queue"
)
if distro == DISTRO_PPA: if distro == DISTRO_PPA:
parser.add_argument('--ppa', help='PPA to pull from') parser.add_argument("--ppa", help="PPA to pull from")
if parser.parse_known_args(args)[0].ppa is None: if parser.parse_known_args(args)[0].ppa is None:
# check for any param starting with "ppa:" # check for any param starting with "ppa:"
# if found, move it to a --ppa param # if found, move it to a --ppa param
for param in args: for param in args:
if param.startswith('ppa:'): if param.startswith("ppa:"):
args.remove(param) args.remove(param)
args.insert(0, param) args.insert(0, param)
args.insert(0, '--ppa') args.insert(0, "--ppa")
break break
# add the positional params # add the positional params
parser.add_argument('package', help="Package name to pull") parser.add_argument("package", help="Package name to pull")
parser.add_argument('release', nargs='?', help="Release to pull from") parser.add_argument("release", nargs="?", help="Release to pull from")
parser.add_argument('version', nargs='?', help="Package version to pull") parser.add_argument("version", nargs="?", help="Package version to pull")
epilog = ("Note on --status: if a version is provided, all status types " epilog = (
"will be searched; if no version is provided, by default only " "Note on --status: if a version is provided, all status types "
"'Pending' and 'Published' status will be searched.") "will be searched; if no version is provided, by default only "
"'Pending' and 'Published' status will be searched."
)
# since parser has no --help handler, create a new parser that does # since parser has no --help handler, create a new parser that does
newparser = ArgumentParser(parents=[parser], epilog=epilog) newparser = ArgumentParser(parents=[parser], epilog=epilog)
@ -198,11 +228,11 @@ class PullPkg(object):
raise InvalidPullValueError("Must specify --pull") raise InvalidPullValueError("Must specify --pull")
# allow 'dbgsym' as alias for 'ddebs' # allow 'dbgsym' as alias for 'ddebs'
if pull == 'dbgsym': if pull == "dbgsym":
Logger.debug("Pulling '%s' for '%s'", PULL_DDEBS, pull) Logger.debug("Pulling '%s' for '%s'", PULL_DDEBS, pull)
pull = PULL_DDEBS pull = PULL_DDEBS
# assume anything starting with 'bin' means 'debs' # assume anything starting with 'bin' means 'debs'
if str(pull).startswith('bin'): if str(pull).startswith("bin"):
Logger.debug("Pulling '%s' for '%s'", PULL_DEBS, pull) Logger.debug("Pulling '%s' for '%s'", PULL_DEBS, pull)
pull = PULL_DEBS pull = PULL_DEBS
# verify pull action is valid # verify pull action is valid
@ -218,11 +248,11 @@ class PullPkg(object):
distro = distro.lower() distro = distro.lower()
# allow 'lp' for 'ubuntu' # allow 'lp' for 'ubuntu'
if distro == 'lp': if distro == "lp":
Logger.debug("Using distro '%s' for '%s'", DISTRO_UBUNTU, distro) Logger.debug("Using distro '%s' for '%s'", DISTRO_UBUNTU, distro)
distro = DISTRO_UBUNTU distro = DISTRO_UBUNTU
# assume anything with 'cloud' is UCA # assume anything with 'cloud' is UCA
if re.match(r'.*cloud.*', distro): if re.match(r".*cloud.*", distro):
Logger.debug("Using distro '%s' for '%s'", DISTRO_UCA, distro) Logger.debug("Using distro '%s' for '%s'", DISTRO_UCA, distro)
distro = DISTRO_UCA distro = DISTRO_UCA
# verify distro is valid # verify distro is valid
@ -256,8 +286,7 @@ class PullPkg(object):
# let SeriesNotFoundException flow up # let SeriesNotFoundException flow up
d.getSeries(release) d.getSeries(release)
Logger.debug("Using distro '%s' release '%s' pocket '%s'", Logger.debug("Using distro '%s' release '%s' pocket '%s'", distro, release, pocket)
distro, release, pocket)
return (release, pocket) return (release, pocket)
def parse_release_and_version(self, distro, release, version, try_swap=True): def parse_release_and_version(self, distro, release, version, try_swap=True):
@ -281,95 +310,99 @@ class PullPkg(object):
# they should all be provided, though the optional ones may be None # they should all be provided, though the optional ones may be None
# type bool # type bool
assert 'verbose' in options assert "verbose" in options
assert 'download_only' in options assert "download_only" in options
assert 'no_conf' in options assert "no_conf" in options
assert 'no_verify_signature' in options assert "no_verify_signature" in options
assert 'status' in options assert "status" in options
# type string # type string
assert 'pull' in options assert "pull" in options
assert 'distro' in options assert "distro" in options
assert 'arch' in options assert "arch" in options
assert 'package' in options assert "package" in options
# type string, optional # type string, optional
assert 'release' in options assert "release" in options
assert 'version' in options assert "version" in options
# type list of strings, optional # type list of strings, optional
assert 'mirror' in options assert "mirror" in options
options['pull'] = self.parse_pull(options['pull']) options["pull"] = self.parse_pull(options["pull"])
options['distro'] = self.parse_distro(options['distro']) options["distro"] = self.parse_distro(options["distro"])
# ensure these are always included so we can just check for None/False later # ensure these are always included so we can just check for None/False later
options['ppa'] = options.get('ppa', None) options["ppa"] = options.get("ppa", None)
options['security'] = options.get('security', False) options["security"] = options.get("security", False)
options['upload_queue'] = options.get('upload_queue', False) options["upload_queue"] = options.get("upload_queue", False)
return options return options
def _get_params(self, options): def _get_params(self, options):
distro = options['distro'] distro = options["distro"]
pull = options['pull'] pull = options["pull"]
params = {} params = {}
params['package'] = options['package'] params["package"] = options["package"]
if options['release']: if options["release"]:
(r, v, p) = self.parse_release_and_version(distro, options['release'], (r, v, p) = self.parse_release_and_version(
options['version']) distro, options["release"], options["version"]
params['series'] = r )
params['version'] = v params["series"] = r
params['pocket'] = p params["version"] = v
params["pocket"] = p
if (params['package'].endswith('.dsc') and not params['series'] and not params['version']): if params["package"].endswith(".dsc") and not params["series"] and not params["version"]:
params['dscfile'] = params['package'] params["dscfile"] = params["package"]
params.pop('package') params.pop("package")
if options['security']: if options["security"]:
if options['ppa']: if options["ppa"]:
Logger.warning('Both --security and --ppa specified, ignoring --ppa') Logger.warning("Both --security and --ppa specified, ignoring --ppa")
Logger.debug('Checking Ubuntu Security PPA') Logger.debug("Checking Ubuntu Security PPA")
# --security is just a shortcut for --ppa ppa:ubuntu-security-proposed/ppa # --security is just a shortcut for --ppa ppa:ubuntu-security-proposed/ppa
options['ppa'] = 'ubuntu-security-proposed/ppa' options["ppa"] = "ubuntu-security-proposed/ppa"
if options['ppa']: if options["ppa"]:
if options['ppa'].startswith('ppa:'): if options["ppa"].startswith("ppa:"):
params['ppa'] = options['ppa'][4:] params["ppa"] = options["ppa"][4:]
else: else:
params['ppa'] = options['ppa'] params["ppa"] = options["ppa"]
elif distro == DISTRO_PPA: elif distro == DISTRO_PPA:
raise ValueError('Must specify PPA to pull from') raise ValueError("Must specify PPA to pull from")
mirrors = [] mirrors = []
if options['mirror']: if options["mirror"]:
mirrors.extend(options['mirror']) mirrors.extend(options["mirror"])
if pull == PULL_DDEBS: if pull == PULL_DDEBS:
config = UDTConfig(options['no_conf']) config = UDTConfig(options["no_conf"])
ddebs_mirror = config.get_value(distro.upper() + '_DDEBS_MIRROR') ddebs_mirror = config.get_value(distro.upper() + "_DDEBS_MIRROR")
if ddebs_mirror: if ddebs_mirror:
mirrors.append(ddebs_mirror) mirrors.append(ddebs_mirror)
if mirrors: if mirrors:
Logger.debug("using mirrors %s", ", ".join(mirrors)) Logger.debug("using mirrors %s", ", ".join(mirrors))
params['mirrors'] = mirrors params["mirrors"] = mirrors
params['verify_signature'] = not options['no_verify_signature'] params["verify_signature"] = not options["no_verify_signature"]
params['status'] = STATUSES if 'all' in options['status'] else options['status'] params["status"] = STATUSES if "all" in options["status"] else options["status"]
# special handling for upload queue # special handling for upload queue
if options['upload_queue']: if options["upload_queue"]:
if len(options['status']) > 1: if len(options["status"]) > 1:
raise ValueError("Too many --status provided, " raise ValueError(
"can only search for a single status or 'all'") "Too many --status provided, can only search for a single status or 'all'"
if not options['status']: )
params['status'] = None if not options["status"]:
elif options['status'][0].lower() == 'all': params["status"] = None
params['status'] = 'all' elif options["status"][0].lower() == "all":
elif options['status'][0].capitalize() in UPLOAD_QUEUE_STATUSES: params["status"] = "all"
params['status'] = options['status'][0].capitalize() elif options["status"][0].capitalize() in UPLOAD_QUEUE_STATUSES:
params["status"] = options["status"][0].capitalize()
else: else:
msg = ("Invalid upload queue status '%s': valid values are %s" % msg = "Invalid upload queue status '%s': valid values are %s" % (
(options['status'][0], ', '.join(UPLOAD_QUEUE_STATUSES))) options["status"][0],
", ".join(UPLOAD_QUEUE_STATUSES),
)
raise ValueError(msg) raise ValueError(msg)
return params return params
@ -378,56 +411,58 @@ class PullPkg(object):
"""Pull (download) specified package file(s)""" """Pull (download) specified package file(s)"""
options = self.parse_args(args) options = self.parse_args(args)
if options['verbose']: if options["verbose"]:
Logger.setLevel(logging.DEBUG) Logger.setLevel(logging.DEBUG)
if options['verbose'] > 1: if options["verbose"] > 1:
logging.getLogger(__package__).setLevel(logging.DEBUG) logging.getLogger(__package__).setLevel(logging.DEBUG)
Logger.debug("pullpkg options: %s", options) Logger.debug("pullpkg options: %s", options)
pull = options['pull'] pull = options["pull"]
distro = options['distro'] distro = options["distro"]
if options['login']: if options["login"]:
Logger.debug("Logging in to Launchpad:") Logger.debug("Logging in to Launchpad:")
try: try:
Launchpad.login() Launchpad.login()
except AlreadyLoggedInError: except AlreadyLoggedInError:
Logger.error("Launchpad singleton has already performed a login, " Logger.error(
"and its design prevents another login") "Launchpad singleton has already performed a login, "
"and its design prevents another login"
)
Logger.warning("Continuing anyway, with existing Launchpad instance") Logger.warning("Continuing anyway, with existing Launchpad instance")
params = self._get_params(options) params = self._get_params(options)
package = params['package'] package = params["package"]
if options['upload_queue']: if options["upload_queue"]:
# upload queue API is different/simpler # upload queue API is different/simpler
self.pull_upload_queue(pull, arch=options['arch'], self.pull_upload_queue(
download_only=options['download_only'], pull, arch=options["arch"], download_only=options["download_only"], **params
**params) )
return return
# call implementation, and allow exceptions to flow up to caller # call implementation, and allow exceptions to flow up to caller
srcpkg = DISTRO_PKG_CLASS[distro](**params) srcpkg = DISTRO_PKG_CLASS[distro](**params)
spph = srcpkg.lp_spph spph = srcpkg.lp_spph
Logger.info('Found %s', spph.display_name) Logger.info("Found %s", spph.display_name)
if pull == PULL_LIST: if pull == PULL_LIST:
Logger.info("Source files:") Logger.info("Source files:")
for f in srcpkg.dsc['Files']: for f in srcpkg.dsc["Files"]:
Logger.info(" %s", f['name']) Logger.info(" %s", f["name"])
Logger.info("Binary files:") Logger.info("Binary files:")
for f in spph.getBinaries(options['arch']): for f in spph.getBinaries(options["arch"]):
archtext = '' archtext = ""
name = f.getFileName() name = f.getFileName()
if name.rpartition('.')[0].endswith('all'): if name.rpartition(".")[0].endswith("all"):
archtext = f" ({f.arch})" archtext = f" ({f.arch})"
Logger.info(f" {name}{archtext}") Logger.info(f" {name}{archtext}")
elif pull == PULL_SOURCE: elif pull == PULL_SOURCE:
# allow DownloadError to flow up to caller # allow DownloadError to flow up to caller
srcpkg.pull() srcpkg.pull()
if options['download_only']: if options["download_only"]:
Logger.debug("--download-only specified, not extracting") Logger.debug("--download-only specified, not extracting")
else: else:
srcpkg.unpack() srcpkg.unpack()
@ -435,70 +470,86 @@ class PullPkg(object):
name = None name = None
if package != spph.getPackageName(): if package != spph.getPackageName():
Logger.info("Pulling only binary package '%s'", package) Logger.info("Pulling only binary package '%s'", package)
Logger.info("Use package name '%s' to pull all binary packages", Logger.info(
spph.getPackageName()) "Use package name '%s' to pull all binary packages", spph.getPackageName()
)
name = package name = package
# e.g. 'debs' -> 'deb' # e.g. 'debs' -> 'deb'
ext = pull.rstrip('s') ext = pull.rstrip("s")
if distro == DISTRO_DEBIAN: if distro == DISTRO_DEBIAN:
# Debian ddebs don't use .ddeb extension, unfortunately :( # Debian ddebs don't use .ddeb extension, unfortunately :(
if pull in [PULL_DEBS, PULL_DDEBS]: if pull in [PULL_DEBS, PULL_DDEBS]:
name = name or '.*' name = name or ".*"
ext = 'deb' ext = "deb"
if pull == PULL_DEBS: if pull == PULL_DEBS:
name += r'(?<!-dbgsym)$' name += r"(?<!-dbgsym)$"
if pull == PULL_DDEBS: if pull == PULL_DDEBS:
name += r'-dbgsym$' name += r"-dbgsym$"
# allow DownloadError to flow up to caller # allow DownloadError to flow up to caller
total = srcpkg.pull_binaries(name=name, ext=ext, arch=options['arch']) total = srcpkg.pull_binaries(name=name, ext=ext, arch=options["arch"])
if total < 1: if total < 1:
Logger.error("No %s found for %s %s", pull, Logger.error("No %s found for %s %s", pull, package, spph.getVersion())
package, spph.getVersion())
else: else:
Logger.error("Internal error: invalid pull value after parse_pull()") Logger.error("Internal error: invalid pull value after parse_pull()")
raise InvalidPullValueError("Invalid pull value '%s'" % pull) raise InvalidPullValueError("Invalid pull value '%s'" % pull)
def pull_upload_queue(self, pull, *, def pull_upload_queue(
package, version=None, arch=None, series=None, pocket=None, self,
status=None, download_only=None, **kwargs): pull,
*,
package,
version=None,
arch=None,
series=None,
pocket=None,
status=None,
download_only=None,
**kwargs,
):
if not series: if not series:
Logger.error("Using --upload-queue requires specifying series") Logger.error("Using --upload-queue requires specifying series")
return return
series = Distribution('ubuntu').getSeries(series) series = Distribution("ubuntu").getSeries(series)
queueparams = {'name': package} queueparams = {"name": package}
if pocket: if pocket:
queueparams['pocket'] = pocket queueparams["pocket"] = pocket
if status == 'all': if status == "all":
queueparams['status'] = None queueparams["status"] = None
queuetype = 'any' queuetype = "any"
elif status: elif status:
queueparams['status'] = status queueparams["status"] = status
queuetype = status queuetype = status
else: else:
queuetype = 'Unapproved' queuetype = "Unapproved"
packages = [p for p in series.getPackageUploads(**queueparams) if packages = [
p.package_version == version or p
str(p.id) == version or for p in series.getPackageUploads(**queueparams)
not version] if p.package_version == version or str(p.id) == version or not version
]
if pull == PULL_SOURCE: if pull == PULL_SOURCE:
packages = [p for p in packages if p.contains_source] packages = [p for p in packages if p.contains_source]
elif pull in VALID_BINARY_PULLS: elif pull in VALID_BINARY_PULLS:
packages = [p for p in packages if packages = [
p.contains_build and p
(arch in ['all', 'any'] or for p in packages
arch in p.display_arches.replace(',', '').split())] if p.contains_build
and (arch in ["all", "any"] or arch in p.display_arches.replace(",", "").split())
]
if not packages: if not packages:
msg = ("Package %s not found in %s upload queue for %s" % msg = "Package %s not found in %s upload queue for %s" % (
(package, queuetype, series.name)) package,
queuetype,
series.name,
)
if version: if version:
msg += " with version/id %s" % version msg += " with version/id %s" % version
if pull in VALID_BINARY_PULLS: if pull in VALID_BINARY_PULLS:
@ -563,28 +614,29 @@ class PullPkg(object):
dscfile = None dscfile = None
for url in urls: for url in urls:
dst = download(url, os.getcwd()) dst = download(url, os.getcwd())
if dst.name.endswith('.dsc'): if dst.name.endswith(".dsc"):
dscfile = dst dscfile = dst
if download_only: if download_only:
Logger.debug("--download-only specified, not extracting") Logger.debug("--download-only specified, not extracting")
elif not dscfile: elif not dscfile:
Logger.error("No source dsc file found, cannot extract") Logger.error("No source dsc file found, cannot extract")
else: else:
cmd = ['dpkg-source', '-x', dscfile.name] cmd = ["dpkg-source", "-x", dscfile.name]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
result = subprocess.run(cmd, encoding='utf-8', result = subprocess.run(
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) cmd, encoding="utf-8", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if result.returncode != 0: if result.returncode != 0:
Logger.error('Source unpack failed.') Logger.error("Source unpack failed.")
Logger.debug(result.stdout) Logger.debug(result.stdout)
else: else:
name = '.*' name = ".*"
if pull == PULL_DEBS: if pull == PULL_DEBS:
name = r'{}(?<!-di)(?<!-dbgsym)$'.format(name) name = r"{}(?<!-di)(?<!-dbgsym)$".format(name)
elif pull == PULL_DDEBS: elif pull == PULL_DDEBS:
name += '-dbgsym$' name += "-dbgsym$"
elif pull == PULL_UDEBS: elif pull == PULL_UDEBS:
name += '-di$' name += "-di$"
else: else:
raise InvalidPullValueError("Invalid pull value %s" % pull) raise InvalidPullValueError("Invalid pull value %s" % pull)

View File

@ -57,7 +57,7 @@ class Question(object):
try: try:
selected = input(question).strip().lower() selected = input(question).strip().lower()
except (EOFError, KeyboardInterrupt): except (EOFError, KeyboardInterrupt):
print('\nAborting as requested.') print("\nAborting as requested.")
sys.exit(1) sys.exit(1)
if selected == "": if selected == "":
selected = default selected = default
@ -86,7 +86,7 @@ def input_number(question, min_number, max_number, default=None):
try: try:
selected = input(question).strip() selected = input(question).strip()
except (EOFError, KeyboardInterrupt): except (EOFError, KeyboardInterrupt):
print('\nAborting as requested.') print("\nAborting as requested.")
sys.exit(1) sys.exit(1)
if default and selected == "": if default and selected == "":
selected = default selected = default
@ -102,17 +102,17 @@ def input_number(question, min_number, max_number, default=None):
def confirmation_prompt(message=None, action=None): def confirmation_prompt(message=None, action=None):
'''Display message, or a stock message including action, and wait for the """Display message, or a stock message including action, and wait for the
user to press Enter user to press Enter
''' """
if message is None: if message is None:
if action is None: if action is None:
action = 'continue' action = "continue"
message = 'Press [Enter] to %s. Press [Ctrl-C] to abort now.' % action message = "Press [Enter] to %s. Press [Ctrl-C] to abort now." % action
try: try:
input(message) input(message)
except (EOFError, KeyboardInterrupt): except (EOFError, KeyboardInterrupt):
print('\nAborting as requested.') print("\nAborting as requested.")
sys.exit(1) sys.exit(1)
@ -121,13 +121,13 @@ class EditFile(object):
self.filename = filename self.filename = filename
self.description = description self.description = description
if placeholders is None: if placeholders is None:
placeholders = (re.compile(r'^>>>.*<<<$', re.UNICODE),) placeholders = (re.compile(r"^>>>.*<<<$", re.UNICODE),)
self.placeholders = placeholders self.placeholders = placeholders
def edit(self, optional=False): def edit(self, optional=False):
if optional: if optional:
print("\n\nCurrently the %s looks like:" % self.description) print("\n\nCurrently the %s looks like:" % self.description)
with open(self.filename, 'r', encoding='utf-8') as f: with open(self.filename, "r", encoding="utf-8") as f:
print(f.read()) print(f.read())
if YesNoQuestion().ask("Edit", "no") == "no": if YesNoQuestion().ask("Edit", "no") == "no":
return return
@ -135,21 +135,22 @@ class EditFile(object):
done = False done = False
while not done: while not done:
old_mtime = os.stat(self.filename).st_mtime old_mtime = os.stat(self.filename).st_mtime
subprocess.check_call(['sensible-editor', self.filename]) subprocess.check_call(["sensible-editor", self.filename])
modified = old_mtime != os.stat(self.filename).st_mtime modified = old_mtime != os.stat(self.filename).st_mtime
placeholders_present = False placeholders_present = False
if self.placeholders: if self.placeholders:
with open(self.filename, 'r', encoding='utf-8') as f: with open(self.filename, "r", encoding="utf-8") as f:
for line in f: for line in f:
for placeholder in self.placeholders: for placeholder in self.placeholders:
if placeholder.search(line.strip()): if placeholder.search(line.strip()):
placeholders_present = True placeholders_present = True
if placeholders_present: if placeholders_present:
print("Placeholders still present in the %s. " print(
"Please replace them with useful information." "Placeholders still present in the %s. "
% self.description) "Please replace them with useful information." % self.description
confirmation_prompt(action='edit again') )
confirmation_prompt(action="edit again")
elif not modified: elif not modified:
print("The %s was not modified" % self.description) print("The %s was not modified" % self.description)
if YesNoQuestion().ask("Edit again", "yes") == "no": if YesNoQuestion().ask("Edit again", "yes") == "no":
@ -158,45 +159,44 @@ class EditFile(object):
done = True done = True
def check_edit(self): def check_edit(self):
'''Override this to implement extra checks on the edited report. """Override this to implement extra checks on the edited report.
Should return False if another round of editing is needed, Should return False if another round of editing is needed,
and should prompt the user to confirm that, if necessary. and should prompt the user to confirm that, if necessary.
''' """
return True return True
class EditBugReport(EditFile): class EditBugReport(EditFile):
split_re = re.compile(r'^Summary.*?:\s+(.*?)\s+' split_re = re.compile(r"^Summary.*?:\s+(.*?)\s+Description:\s+(.*)$", re.DOTALL | re.UNICODE)
r'Description:\s+(.*)$',
re.DOTALL | re.UNICODE)
def __init__(self, subject, body, placeholders=None): def __init__(self, subject, body, placeholders=None):
prefix = os.path.basename(sys.argv[0]) + '_' prefix = os.path.basename(sys.argv[0]) + "_"
tmpfile = tempfile.NamedTemporaryFile(prefix=prefix, suffix='.txt', tmpfile = tempfile.NamedTemporaryFile(prefix=prefix, suffix=".txt", delete=False)
delete=False) tmpfile.write(
tmpfile.write((u'Summary (one line):\n%s\n\nDescription:\n%s' ("Summary (one line):\n%s\n\nDescription:\n%s" % (subject, body)).encode("utf-8")
% (subject, body)).encode('utf-8')) )
tmpfile.close() tmpfile.close()
super(EditBugReport, self).__init__(tmpfile.name, 'bug report', super(EditBugReport, self).__init__(tmpfile.name, "bug report", placeholders)
placeholders)
def check_edit(self): def check_edit(self):
with open(self.filename, 'r', encoding='utf-8') as f: with open(self.filename, "r", encoding="utf-8") as f:
report = f.read() report = f.read()
if self.split_re.match(report) is None: if self.split_re.match(report) is None:
print("The %s doesn't start with 'Summary:' and 'Description:' " print(
"blocks" % self.description) "The %s doesn't start with 'Summary:' and 'Description:' "
confirmation_prompt('edit again') "blocks" % self.description
)
confirmation_prompt("edit again")
return False return False
return True return True
def get_report(self): def get_report(self):
with open(self.filename, 'r', encoding='utf-8') as f: with open(self.filename, "r", encoding="utf-8") as f:
report = f.read() report = f.read()
match = self.split_re.match(report) match = self.split_re.match(report)
title = match.group(1).replace(u'\n', u' ') title = match.group(1).replace("\n", " ")
report = (title, match.group(2)) report = (title, match.group(2))
os.unlink(self.filename) os.unlink(self.filename)
return report return report

View File

@ -22,13 +22,12 @@ class RDependsException(Exception):
pass pass
def query_rdepends(package, release, arch, def query_rdepends(package, release, arch, server="http://qa.ubuntuwire.org/rdepends"):
server='http://qa.ubuntuwire.org/rdepends'):
"""Look up a packages reverse-dependencies on the Ubuntuwire """Look up a packages reverse-dependencies on the Ubuntuwire
Reverse- webservice Reverse- webservice
""" """
url = os.path.join(server, 'v1', release, arch, package) url = os.path.join(server, "v1", release, arch, package)
response, data = httplib2.Http().request(url) response, data = httplib2.Http().request(url)
if response.status != 200: if response.status != 200:

View File

@ -27,16 +27,21 @@ from distro_info import DebianDistroInfo, DistroDataOutdated
from httplib2 import Http, HttpLib2Error from httplib2 import Http, HttpLib2Error
from ubuntutools.lp import udtexceptions from ubuntutools.lp import udtexceptions
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, PersonTeam, from ubuntutools.lp.lpapicache import (
DistributionSourcePackage) Launchpad,
Distribution,
PersonTeam,
DistributionSourcePackage,
)
from ubuntutools.question import confirmation_prompt from ubuntutools.question import confirmation_prompt
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
def get_debian_srcpkg(name, release): def get_debian_srcpkg(name, release):
debian = Distribution('debian') debian = Distribution("debian")
debian_archive = debian.getArchive() debian_archive = debian.getArchive()
try: try:
@ -47,82 +52,86 @@ def get_debian_srcpkg(name, release):
return debian_archive.getSourcePackage(name, release) return debian_archive.getSourcePackage(name, release)
def get_ubuntu_srcpkg(name, release, pocket='Release'): def get_ubuntu_srcpkg(name, release, pocket="Release"):
ubuntu = Distribution('ubuntu') ubuntu = Distribution("ubuntu")
ubuntu_archive = ubuntu.getArchive() ubuntu_archive = ubuntu.getArchive()
try: try:
return ubuntu_archive.getSourcePackage(name, release, pocket) return ubuntu_archive.getSourcePackage(name, release, pocket)
except udtexceptions.PackageNotFoundException: except udtexceptions.PackageNotFoundException:
if pocket != 'Release': if pocket != "Release":
parent_pocket = 'Release' parent_pocket = "Release"
if pocket == 'Updates': if pocket == "Updates":
parent_pocket = 'Proposed' parent_pocket = "Proposed"
return get_ubuntu_srcpkg(name, release, parent_pocket) return get_ubuntu_srcpkg(name, release, parent_pocket)
raise raise
def need_sponsorship(name, component, release): def need_sponsorship(name, component, release):
''' """
Check if the user has upload permissions for either the package Check if the user has upload permissions for either the package
itself or the component itself or the component
''' """
archive = Distribution('ubuntu').getArchive() archive = Distribution("ubuntu").getArchive()
distroseries = Distribution('ubuntu').getSeries(release) distroseries = Distribution("ubuntu").getSeries(release)
need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, need_sponsor = not PersonTeam.me.canUploadPackage(archive, distroseries, name, component)
name, component)
if need_sponsor: if need_sponsor:
print('''You are not able to upload this package directly to Ubuntu. print(
"""You are not able to upload this package directly to Ubuntu.
Your sync request shall require an approval by a member of the appropriate Your sync request shall require an approval by a member of the appropriate
sponsorship team, who shall be subscribed to this bug report. sponsorship team, who shall be subscribed to this bug report.
This must be done before it can be processed by a member of the Ubuntu Archive This must be done before it can be processed by a member of the Ubuntu Archive
team.''') team."""
)
confirmation_prompt() confirmation_prompt()
return need_sponsor return need_sponsor
def check_existing_reports(srcpkg): def check_existing_reports(srcpkg):
''' """
Check existing bug reports on Launchpad for a possible sync request. Check existing bug reports on Launchpad for a possible sync request.
If found ask for confirmation on filing a request. If found ask for confirmation on filing a request.
''' """
# Fetch the package's bug list from Launchpad # Fetch the package's bug list from Launchpad
pkg = Distribution('ubuntu').getSourcePackage(name=srcpkg) pkg = Distribution("ubuntu").getSourcePackage(name=srcpkg)
pkg_bug_list = pkg.searchTasks(status=["Incomplete", "New", "Confirmed", pkg_bug_list = pkg.searchTasks(
"Triaged", "In Progress", status=["Incomplete", "New", "Confirmed", "Triaged", "In Progress", "Fix Committed"],
"Fix Committed"], omit_duplicates=True,
omit_duplicates=True) )
# Search bug list for other sync requests. # Search bug list for other sync requests.
for bug in pkg_bug_list: for bug in pkg_bug_list:
# check for Sync or sync and the package name # check for Sync or sync and the package name
if not bug.is_complete and 'ync %s' % srcpkg in bug.title: if not bug.is_complete and "ync %s" % srcpkg in bug.title:
print('The following bug could be a possible duplicate sync bug ' print(
'on Launchpad:\n' "The following bug could be a possible duplicate sync bug "
' * %s (%s)\n' "on Launchpad:\n"
'Please check the above URL to verify this before ' " * %s (%s)\n"
'continuing.' "Please check the above URL to verify this before "
% (bug.title, bug.web_link)) "continuing." % (bug.title, bug.web_link)
)
confirmation_prompt() confirmation_prompt()
def get_ubuntu_delta_changelog(srcpkg): def get_ubuntu_delta_changelog(srcpkg):
''' """
Download the Ubuntu changelog and extract the entries since the last sync Download the Ubuntu changelog and extract the entries since the last sync
from Debian. from Debian.
''' """
archive = Distribution('ubuntu').getArchive() archive = Distribution("ubuntu").getArchive()
spph = archive.getPublishedSources(source_name=srcpkg.getPackageName(), spph = archive.getPublishedSources(
exact_match=True, pocket='Release') source_name=srcpkg.getPackageName(), exact_match=True, pocket="Release"
)
debian_info = DebianDistroInfo() debian_info = DebianDistroInfo()
topline = re.compile(r'^(\w%(name_chars)s*) \(([^\(\) \t]+)\)' topline = re.compile(
r'((\s+%(name_chars)s+)+)\;' r"^(\w%(name_chars)s*) \(([^\(\) \t]+)\)"
% {'name_chars': '[-+0-9a-z.]'}, r"((\s+%(name_chars)s+)+)\;" % {"name_chars": "[-+0-9a-z.]"},
re.IGNORECASE) re.IGNORECASE,
)
delta = [] delta = []
for record in spph: for record in spph:
changes_url = record.changesFileUrl() changes_url = record.changesFileUrl()
@ -135,56 +144,53 @@ def get_ubuntu_delta_changelog(srcpkg):
Logger.error(str(e)) Logger.error(str(e))
break break
if response.status != 200: if response.status != 200:
Logger.error("%s: %s %s", changes_url, response.status, Logger.error("%s: %s %s", changes_url, response.status, response.reason)
response.reason)
break break
changes = Changes(Http().request(changes_url)[1]) changes = Changes(Http().request(changes_url)[1])
for line in changes['Changes'].splitlines(): for line in changes["Changes"].splitlines():
line = line[1:] line = line[1:]
m = topline.match(line) m = topline.match(line)
if m: if m:
distribution = m.group(3).split()[0].split('-')[0] distribution = m.group(3).split()[0].split("-")[0]
if debian_info.valid(distribution): if debian_info.valid(distribution):
break break
if line.startswith(u' '): if line.startswith(" "):
delta.append(line) delta.append(line)
else: else:
continue continue
break break
return '\n'.join(delta) return "\n".join(delta)
def post_bug(srcpkg, subscribe, status, bugtitle, bugtext): def post_bug(srcpkg, subscribe, status, bugtitle, bugtext):
''' """
Use the LP API to file the sync request. Use the LP API to file the sync request.
''' """
print('The final report is:\nSummary: %s\nDescription:\n%s\n' print("The final report is:\nSummary: %s\nDescription:\n%s\n" % (bugtitle, bugtext))
% (bugtitle, bugtext))
confirmation_prompt() confirmation_prompt()
if srcpkg: if srcpkg:
bug_target = DistributionSourcePackage( bug_target = DistributionSourcePackage(
'%subuntu/+source/%s' % (Launchpad._root_uri, srcpkg)) "%subuntu/+source/%s" % (Launchpad._root_uri, srcpkg)
)
else: else:
# new source package # new source package
bug_target = Distribution('ubuntu') bug_target = Distribution("ubuntu")
# create bug # create bug
bug = Launchpad.bugs.createBug(title=bugtitle, description=bugtext, bug = Launchpad.bugs.createBug(title=bugtitle, description=bugtext, target=bug_target())
target=bug_target())
# newly created bugreports have only one task # newly created bugreports have only one task
task = bug.bug_tasks[0] task = bug.bug_tasks[0]
# only members of ubuntu-bugcontrol can set importance # only members of ubuntu-bugcontrol can set importance
if PersonTeam.me.isLpTeamMember('ubuntu-bugcontrol'): if PersonTeam.me.isLpTeamMember("ubuntu-bugcontrol"):
task.importance = 'Wishlist' task.importance = "Wishlist"
task.status = status task.status = status
task.lp_save() task.lp_save()
bug.subscribe(person=PersonTeam(subscribe)()) bug.subscribe(person=PersonTeam(subscribe)())
print('Sync request filed as bug #%i: %s' print("Sync request filed as bug #%i: %s" % (bug.id, bug.web_link))
% (bug.id, bug.web_link))

View File

@ -36,16 +36,17 @@ from ubuntutools.lp.udtexceptions import PackageNotFoundException
from ubuntutools.question import confirmation_prompt, YesNoQuestion from ubuntutools.question import confirmation_prompt, YesNoQuestion
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
__all__ = [ __all__ = [
'get_debian_srcpkg', "get_debian_srcpkg",
'get_ubuntu_srcpkg', "get_ubuntu_srcpkg",
'need_sponsorship', "need_sponsorship",
'check_existing_reports', "check_existing_reports",
'get_ubuntu_delta_changelog', "get_ubuntu_delta_changelog",
'mail_bug', "mail_bug",
] ]
@ -67,73 +68,91 @@ def get_ubuntu_srcpkg(name, release):
def need_sponsorship(name, component, release): def need_sponsorship(name, component, release):
''' """
Ask the user if he has upload permissions for the package or the Ask the user if he has upload permissions for the package or the
component. component.
''' """
val = YesNoQuestion().ask("Do you have upload permissions for the '%s' component or " val = YesNoQuestion().ask(
"the package '%s' in Ubuntu %s?\nIf in doubt answer 'n'." % "Do you have upload permissions for the '%s' component or "
(component, name, release), 'no') "the package '%s' in Ubuntu %s?\nIf in doubt answer 'n'." % (component, name, release),
return val == 'no' "no",
)
return val == "no"
def check_existing_reports(srcpkg): def check_existing_reports(srcpkg):
''' """
Point the user to the URL to manually check for duplicate bug reports. Point the user to the URL to manually check for duplicate bug reports.
''' """
print('Please check on ' print(
'https://bugs.launchpad.net/ubuntu/+source/%s/+bugs\n' "Please check on "
'for duplicate sync requests before continuing.' % srcpkg) "https://bugs.launchpad.net/ubuntu/+source/%s/+bugs\n"
"for duplicate sync requests before continuing." % srcpkg
)
confirmation_prompt() confirmation_prompt()
def get_ubuntu_delta_changelog(srcpkg): def get_ubuntu_delta_changelog(srcpkg):
''' """
Download the Ubuntu changelog and extract the entries since the last sync Download the Ubuntu changelog and extract the entries since the last sync
from Debian. from Debian.
''' """
changelog = Changelog(srcpkg.getChangelog()) changelog = Changelog(srcpkg.getChangelog())
if changelog is None: if changelog is None:
return '' return ""
delta = [] delta = []
debian_info = DebianDistroInfo() debian_info = DebianDistroInfo()
for block in changelog: for block in changelog:
distribution = block.distributions.split()[0].split('-')[0] distribution = block.distributions.split()[0].split("-")[0]
if debian_info.valid(distribution): if debian_info.valid(distribution):
break break
delta += [str(change) for change in block.changes() delta += [str(change) for change in block.changes() if change.strip()]
if change.strip()]
return '\n'.join(delta) return "\n".join(delta)
def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain, def mail_bug(
keyid, myemailaddr, mailserver_host, mailserver_port, srcpkg,
mailserver_user, mailserver_pass): subscribe,
''' status,
bugtitle,
bugtext,
bug_mail_domain,
keyid,
myemailaddr,
mailserver_host,
mailserver_port,
mailserver_user,
mailserver_pass,
):
"""
Submit the sync request per email. Submit the sync request per email.
''' """
to = 'new@' + bug_mail_domain to = "new@" + bug_mail_domain
# generate mailbody # generate mailbody
if srcpkg: if srcpkg:
mailbody = ' affects ubuntu/%s\n' % srcpkg mailbody = " affects ubuntu/%s\n" % srcpkg
else: else:
mailbody = ' affects ubuntu\n' mailbody = " affects ubuntu\n"
mailbody += '''\ mailbody += """\
status %s status %s
importance wishlist importance wishlist
subscribe %s subscribe %s
done done
%s''' % (status, subscribe, bugtext) %s""" % (
status,
subscribe,
bugtext,
)
# prepare sign command # prepare sign command
gpg_command = None gpg_command = None
for cmd in ('gnome-gpg', 'gpg2', 'gpg'): for cmd in ("gnome-gpg", "gpg2", "gpg"):
if os.access('/usr/bin/%s' % cmd, os.X_OK): if os.access("/usr/bin/%s" % cmd, os.X_OK):
gpg_command = [cmd] gpg_command = [cmd]
break break
@ -141,107 +160,135 @@ def mail_bug(srcpkg, subscribe, status, bugtitle, bugtext, bug_mail_domain,
Logger.error("Cannot locate gpg, please install the 'gnupg' package!") Logger.error("Cannot locate gpg, please install the 'gnupg' package!")
sys.exit(1) sys.exit(1)
gpg_command.append('--clearsign') gpg_command.append("--clearsign")
if keyid: if keyid:
gpg_command.extend(('-u', keyid)) gpg_command.extend(("-u", keyid))
# sign the mail body # sign the mail body
gpg = subprocess.Popen( gpg = subprocess.Popen(
gpg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, gpg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding="utf-8"
encoding='utf-8') )
signed_report = gpg.communicate(mailbody)[0] signed_report = gpg.communicate(mailbody)[0]
if gpg.returncode != 0: if gpg.returncode != 0:
Logger.error("%s failed.", gpg_command[0]) Logger.error("%s failed.", gpg_command[0])
sys.exit(1) sys.exit(1)
# generate email # generate email
mail = '''\ mail = """\
From: %s From: %s
To: %s To: %s
Subject: %s Subject: %s
Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset=UTF-8
%s''' % (myemailaddr, to, bugtitle, signed_report) %s""" % (
myemailaddr,
to,
bugtitle,
signed_report,
)
print('The final report is:\n%s' % mail) print("The final report is:\n%s" % mail)
confirmation_prompt() confirmation_prompt()
# save mail in temporary file # save mail in temporary file
backup = tempfile.NamedTemporaryFile( backup = tempfile.NamedTemporaryFile(
mode='w', mode="w",
delete=False, delete=False,
prefix='requestsync-' + re.sub(r'[^a-zA-Z0-9_-]', '', bugtitle.replace(' ', '_')) prefix="requestsync-" + re.sub(r"[^a-zA-Z0-9_-]", "", bugtitle.replace(" ", "_")),
) )
with backup: with backup:
backup.write(mail) backup.write(mail)
Logger.info('The e-mail has been saved in %s and will be deleted ' Logger.info(
'after succesful transmission', backup.name) "The e-mail has been saved in %s and will be deleted after succesful transmission",
backup.name,
)
# connect to the server # connect to the server
while True: while True:
try: try:
Logger.info('Connecting to %s:%s ...', mailserver_host, Logger.info("Connecting to %s:%s ...", mailserver_host, mailserver_port)
mailserver_port)
s = smtplib.SMTP(mailserver_host, mailserver_port) s = smtplib.SMTP(mailserver_host, mailserver_port)
break break
except smtplib.SMTPConnectError as s: except smtplib.SMTPConnectError as s:
try: try:
# py2 path # py2 path
# pylint: disable=unsubscriptable-object # pylint: disable=unsubscriptable-object
Logger.error('Could not connect to %s:%s: %s (%i)', Logger.error(
mailserver_host, mailserver_port, s[1], s[0]) "Could not connect to %s:%s: %s (%i)",
mailserver_host,
mailserver_port,
s[1],
s[0],
)
except TypeError: except TypeError:
# pylint: disable=no-member # pylint: disable=no-member
Logger.error('Could not connect to %s:%s: %s (%i)', Logger.error(
mailserver_host, mailserver_port, s.strerror, s.errno) "Could not connect to %s:%s: %s (%i)",
mailserver_host,
mailserver_port,
s.strerror,
s.errno,
)
if s.smtp_code == 421: if s.smtp_code == 421:
confirmation_prompt(message='This is a temporary error, press [Enter] ' confirmation_prompt(
'to retry. Press [Ctrl-C] to abort now.') message="This is a temporary error, press [Enter] "
"to retry. Press [Ctrl-C] to abort now."
)
except socket.error as s: except socket.error as s:
try: try:
# py2 path # py2 path
# pylint: disable=unsubscriptable-object # pylint: disable=unsubscriptable-object
Logger.error('Could not connect to %s:%s: %s (%i)', Logger.error(
mailserver_host, mailserver_port, s[1], s[0]) "Could not connect to %s:%s: %s (%i)",
mailserver_host,
mailserver_port,
s[1],
s[0],
)
except TypeError: except TypeError:
# pylint: disable=no-member # pylint: disable=no-member
Logger.error('Could not connect to %s:%s: %s (%i)', Logger.error(
mailserver_host, mailserver_port, s.strerror, s.errno) "Could not connect to %s:%s: %s (%i)",
mailserver_host,
mailserver_port,
s.strerror,
s.errno,
)
return return
if mailserver_user and mailserver_pass: if mailserver_user and mailserver_pass:
try: try:
s.login(mailserver_user, mailserver_pass) s.login(mailserver_user, mailserver_pass)
except smtplib.SMTPAuthenticationError: except smtplib.SMTPAuthenticationError:
Logger.error('Error authenticating to the server: ' Logger.error("Error authenticating to the server: invalid username and password.")
'invalid username and password.')
s.quit() s.quit()
return return
except smtplib.SMTPException: except smtplib.SMTPException:
Logger.error('Unknown SMTP error.') Logger.error("Unknown SMTP error.")
s.quit() s.quit()
return return
while True: while True:
try: try:
s.sendmail(myemailaddr, to, mail.encode('utf-8')) s.sendmail(myemailaddr, to, mail.encode("utf-8"))
s.quit() s.quit()
os.remove(backup.name) os.remove(backup.name)
Logger.info('Sync request mailed.') Logger.info("Sync request mailed.")
break break
except smtplib.SMTPRecipientsRefused as smtperror: except smtplib.SMTPRecipientsRefused as smtperror:
smtp_code, smtp_message = smtperror.recipients[to] smtp_code, smtp_message = smtperror.recipients[to]
Logger.error('Error while sending: %i, %s', smtp_code, smtp_message) Logger.error("Error while sending: %i, %s", smtp_code, smtp_message)
if smtp_code == 450: if smtp_code == 450:
confirmation_prompt(message='This is a temporary error, press [Enter] ' confirmation_prompt(
'to retry. Press [Ctrl-C] to abort now.') message="This is a temporary error, press [Enter] "
"to retry. Press [Ctrl-C] to abort now."
)
else: else:
return return
except smtplib.SMTPResponseException as e: except smtplib.SMTPResponseException as e:
Logger.error('Error while sending: %i, %s', Logger.error("Error while sending: %i, %s", e.smtp_code, e.smtp_error)
e.smtp_code, e.smtp_error)
return return
except smtplib.SMTPServerDisconnected: except smtplib.SMTPServerDisconnected:
Logger.error('Server disconnected while sending the mail.') Logger.error("Server disconnected while sending the mail.")
return return

View File

@ -26,6 +26,7 @@ import httplib2
from ubuntutools.version import Version from ubuntutools.version import Version
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
@ -58,7 +59,7 @@ class BugTask(object):
self.series = components[2].lower() self.series = components[2].lower()
if self.package is None: if self.package is None:
title_re = r'^Sync ([a-z0-9+.-]+) [a-z0-9.+:~-]+ \([a-z]+\) from.*' title_re = r"^Sync ([a-z0-9+.-]+) [a-z0-9.+:~-]+ \([a-z]+\) from.*"
match = re.match(title_re, self.get_bug_title(), re.U | re.I) match = re.match(title_re, self.get_bug_title(), re.U | re.I)
if match is not None: if match is not None:
self.package = match.group(1) self.package = match.group(1)
@ -74,7 +75,7 @@ class BugTask(object):
if url.endswith(".dsc"): if url.endswith(".dsc"):
response, data = httplib2.Http().request(url) response, data = httplib2.Http().request(url)
assert response.status == 200 assert response.status == 200
with open(filename, 'wb') as f: with open(filename, "wb") as f:
f.write(data) f.write(data)
dsc_file = os.path.join(os.getcwd(), filename) dsc_file = os.path.join(os.getcwd(), filename)
@ -84,18 +85,26 @@ class BugTask(object):
return dsc_file return dsc_file
def get_branch_link(self): def get_branch_link(self):
return "lp:" + self.project + "/" + self.get_series() + "/" + \ return "lp:" + self.project + "/" + self.get_series() + "/" + self.package
self.package
def get_bug_title(self): def get_bug_title(self):
"""Returns the title of the related bug.""" """Returns the title of the related bug."""
return self.bug_task.bug.title return self.bug_task.bug.title
def get_long_info(self): def get_long_info(self):
return "Bug task: " + str(self.bug_task) + "\n" + \ return (
"Package: " + str(self.package) + "\n" + \ "Bug task: "
"Project: " + str(self.project) + "\n" + \ + str(self.bug_task)
"Series: " + str(self.series) + "\n"
+ "Package: "
+ str(self.package)
+ "\n"
+ "Project: "
+ str(self.project)
+ "\n"
+ "Series: "
+ str(self.series)
)
def get_lp_task(self): def get_lp_task(self):
"""Returns the Launchpad bug task object.""" """Returns the Launchpad bug task object."""
@ -137,14 +146,16 @@ class BugTask(object):
dist = self.launchpad.distributions[project] dist = self.launchpad.distributions[project]
archive = dist.getArchive(name="primary") archive = dist.getArchive(name="primary")
distro_series = dist.getSeries(name_or_version=series) distro_series = dist.getSeries(name_or_version=series)
published = archive.getPublishedSources(source_name=self.package, published = archive.getPublishedSources(
distro_series=distro_series, source_name=self.package,
status="Published", distro_series=distro_series,
exact_match=True) status="Published",
exact_match=True,
)
latest_source = None latest_source = None
for source in published: for source in published:
if source.pocket in ('Release', 'Security', 'Updates', 'Proposed'): if source.pocket in ("Release", "Security", "Updates", "Proposed"):
latest_source = source latest_source = source
break break
return latest_source return latest_source
@ -156,7 +167,7 @@ class BugTask(object):
def get_latest_released_version(self): def get_latest_released_version(self):
source = self.get_source(True) source = self.get_source(True)
if source is None: # Not currently published in Ubuntu if source is None: # Not currently published in Ubuntu
version = '~' version = "~"
else: else:
version = source.source_package_version version = source.source_package_version
return Version(version) return Version(version)

View File

@ -23,6 +23,7 @@ from ubuntutools.sponsor_patch.question import ask_for_manual_fixing
from functools import reduce from functools import reduce
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
@ -32,10 +33,10 @@ class Patch(object):
def __init__(self, patch): def __init__(self, patch):
self._patch = patch self._patch = patch
self._patch_file = re.sub(" |/", "_", patch.title) self._patch_file = re.sub(" |/", "_", patch.title)
if not reduce(lambda r, x: r or self._patch.title.endswith(x), if not reduce(
(".debdiff", ".diff", ".patch"), False): lambda r, x: r or self._patch.title.endswith(x), (".debdiff", ".diff", ".patch"), False
Logger.debug("Patch %s does not have a proper file extension." % ):
(self._patch.title)) Logger.debug("Patch %s does not have a proper file extension." % (self._patch.title))
self._patch_file += ".patch" self._patch_file += ".patch"
self._full_path = os.path.realpath(self._patch_file) self._full_path = os.path.realpath(self._patch_file)
self._changed_files = None self._changed_files = None
@ -45,21 +46,36 @@ class Patch(object):
assert self._changed_files is not None, "You forgot to download the patch." assert self._changed_files is not None, "You forgot to download the patch."
edit = False edit = False
if self.is_debdiff(): if self.is_debdiff():
cmd = ["patch", "--merge", "--force", "-p", cmd = [
str(self.get_strip_level()), "-i", self._full_path] "patch",
Logger.debug(' '.join(cmd)) "--merge",
"--force",
"-p",
str(self.get_strip_level()),
"-i",
self._full_path,
]
Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Failed to apply debdiff %s to %s %s.", Logger.error(
self._patch_file, task.package, task.get_version()) "Failed to apply debdiff %s to %s %s.",
self._patch_file,
task.package,
task.get_version(),
)
if not edit: if not edit:
ask_for_manual_fixing() ask_for_manual_fixing()
edit = True edit = True
else: else:
cmd = ["add-patch", self._full_path] cmd = ["add-patch", self._full_path]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Failed to apply diff %s to %s %s.", Logger.error(
self._patch_file, task.package, task.get_version()) "Failed to apply diff %s to %s %s.",
self._patch_file,
task.package,
task.get_version(),
)
if not edit: if not edit:
ask_for_manual_fixing() ask_for_manual_fixing()
edit = True edit = True
@ -73,7 +89,7 @@ class Patch(object):
patch_f.close() patch_f.close()
cmd = ["diffstat", "-l", "-p0", self._full_path] cmd = ["diffstat", "-l", "-p0", self._full_path]
changed_files = subprocess.check_output(cmd, encoding='utf-8') changed_files = subprocess.check_output(cmd, encoding="utf-8")
self._changed_files = [f for f in changed_files.split("\n") if f != ""] self._changed_files = [f for f in changed_files.split("\n") if f != ""]
def get_strip_level(self): def get_strip_level(self):
@ -81,13 +97,11 @@ class Patch(object):
assert self._changed_files is not None, "You forgot to download the patch." assert self._changed_files is not None, "You forgot to download the patch."
strip_level = None strip_level = None
if self.is_debdiff(): if self.is_debdiff():
changelog = [f for f in self._changed_files changelog = [f for f in self._changed_files if f.endswith("debian/changelog")][0]
if f.endswith("debian/changelog")][0]
strip_level = len(changelog.split(os.sep)) - 2 strip_level = len(changelog.split(os.sep)) - 2
return strip_level return strip_level
def is_debdiff(self): def is_debdiff(self):
"""Checks if the patch is a debdiff (= modifies debian/changelog).""" """Checks if the patch is a debdiff (= modifies debian/changelog)."""
assert self._changed_files is not None, "You forgot to download the patch." assert self._changed_files is not None, "You forgot to download the patch."
return len([f for f in self._changed_files return len([f for f in self._changed_files if f.endswith("debian/changelog")]) > 0
if f.endswith("debian/changelog")]) > 0

View File

@ -37,8 +37,7 @@ def ask_for_ignoring_or_fixing():
def ask_for_manual_fixing(): def ask_for_manual_fixing():
"""Ask the user to resolve an issue manually.""" """Ask the user to resolve an issue manually."""
answer = YesNoQuestion().ask("Do you want to resolve this issue manually", answer = YesNoQuestion().ask("Do you want to resolve this issue manually", "yes")
"yes")
if answer == "no": if answer == "no":
user_abort() user_abort()

View File

@ -25,20 +25,24 @@ import debian.deb822
from ubuntutools.question import Question, YesNoQuestion from ubuntutools.question import Question, YesNoQuestion
from ubuntutools.sponsor_patch.question import (ask_for_ignoring_or_fixing, from ubuntutools.sponsor_patch.question import (
ask_for_manual_fixing, ask_for_ignoring_or_fixing,
user_abort) ask_for_manual_fixing,
user_abort,
)
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
def _get_series(launchpad): def _get_series(launchpad):
"""Returns a tuple with the development and list of supported series.""" """Returns a tuple with the development and list of supported series."""
ubuntu = launchpad.distributions['ubuntu'] ubuntu = launchpad.distributions["ubuntu"]
devel_series = ubuntu.current_series.name devel_series = ubuntu.current_series.name
supported_series = [series.name for series in ubuntu.series supported_series = [
if series.active and series.name != devel_series] series.name for series in ubuntu.series if series.active and series.name != devel_series
]
return (devel_series, supported_series) return (devel_series, supported_series)
@ -49,10 +53,10 @@ def strip_epoch(version):
return "1.1.3-1". return "1.1.3-1".
""" """
parts = version.full_version.split(':') parts = version.full_version.split(":")
if len(parts) > 1: if len(parts) > 1:
del parts[0] del parts[0]
version_without_epoch = ':'.join(parts) version_without_epoch = ":".join(parts)
return version_without_epoch return version_without_epoch
@ -74,8 +78,7 @@ class SourcePackage(object):
if upload == "ubuntu": if upload == "ubuntu":
self._print_logs() self._print_logs()
question = Question(["yes", "edit", "no"]) question = Question(["yes", "edit", "no"])
answer = question.ask("Do you want to acknowledge the sync request", answer = question.ask("Do you want to acknowledge the sync request", "no")
"no")
if answer == "edit": if answer == "edit":
return False return False
elif answer == "no": elif answer == "no":
@ -90,33 +93,33 @@ class SourcePackage(object):
msg = "Sync request ACK'd." msg = "Sync request ACK'd."
if self._build_log: if self._build_log:
msg = ("%s %s builds on %s. " + msg) % \ msg = ("%s %s builds on %s. " + msg) % (
(self._package, self._version, self._package,
self._builder.get_architecture()) self._version,
self._builder.get_architecture(),
)
bug.newMessage(content=msg, subject="sponsor-patch") bug.newMessage(content=msg, subject="sponsor-patch")
Logger.debug("Acknowledged sync request bug #%i.", bug.id) Logger.debug("Acknowledged sync request bug #%i.", bug.id)
bug.subscribe(person=launchpad.people['ubuntu-archive']) bug.subscribe(person=launchpad.people["ubuntu-archive"])
Logger.debug("Subscribed ubuntu-archive to bug #%i.", bug.id) Logger.debug("Subscribed ubuntu-archive to bug #%i.", bug.id)
bug.subscribe(person=launchpad.me) bug.subscribe(person=launchpad.me)
Logger.debug("Subscribed me to bug #%i.", bug.id) Logger.debug("Subscribed me to bug #%i.", bug.id)
sponsorsteam = launchpad.people['ubuntu-sponsors'] sponsorsteam = launchpad.people["ubuntu-sponsors"]
for sub in bug.subscriptions: for sub in bug.subscriptions:
if sub.person == sponsorsteam and sub.canBeUnsubscribedByUser(): if sub.person == sponsorsteam and sub.canBeUnsubscribedByUser():
bug.unsubscribe(person=launchpad.people['ubuntu-sponsors']) bug.unsubscribe(person=launchpad.people["ubuntu-sponsors"])
Logger.debug("Unsubscribed ubuntu-sponsors from bug #%i.", Logger.debug("Unsubscribed ubuntu-sponsors from bug #%i.", bug.id)
bug.id)
elif sub.person == sponsorsteam: elif sub.person == sponsorsteam:
Logger.debug("Couldn't unsubscribe ubuntu-sponsors from " Logger.debug("Couldn't unsubscribe ubuntu-sponsors from bug #%i.", bug.id)
"bug #%i.", bug.id)
Logger.info("Successfully acknowledged sync request bug #%i.", Logger.info("Successfully acknowledged sync request bug #%i.", bug.id)
bug.id)
else: else:
Logger.error("Sync requests can only be acknowledged when the " Logger.error(
"upload target is Ubuntu.") "Sync requests can only be acknowledged when the upload target is Ubuntu."
)
sys.exit(1) sys.exit(1)
return True return True
@ -141,28 +144,29 @@ class SourcePackage(object):
elif answer == "no": elif answer == "no":
user_abort() user_abort()
cmd = ["dput", "--force", upload, self._changes_file] cmd = ["dput", "--force", upload, self._changes_file]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Upload of %s to %s failed." % Logger.error(
(os.path.basename(self._changes_file), upload)) "Upload of %s to %s failed." % (os.path.basename(self._changes_file), upload)
)
sys.exit(1) sys.exit(1)
# Push the branch if the package is uploaded to the Ubuntu archive. # Push the branch if the package is uploaded to the Ubuntu archive.
if upload == "ubuntu" and self._branch: if upload == "ubuntu" and self._branch:
cmd = ['debcommit'] cmd = ["debcommit"]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error('Bzr commit failed.') Logger.error("Bzr commit failed.")
sys.exit(1) sys.exit(1)
cmd = ['bzr', 'mark-uploaded'] cmd = ["bzr", "mark-uploaded"]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error('Bzr tagging failed.') Logger.error("Bzr tagging failed.")
sys.exit(1) sys.exit(1)
cmd = ['bzr', 'push', ':parent'] cmd = ["bzr", "push", ":parent"]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error('Bzr push failed.') Logger.error("Bzr push failed.")
sys.exit(1) sys.exit(1)
return True return True
@ -175,8 +179,9 @@ class SourcePackage(object):
if dist is None: if dist is None:
dist = re.sub("-.*$", "", self._changelog.distributions) dist = re.sub("-.*$", "", self._changelog.distributions)
build_name = "{}_{}_{}.build".format(self._package, strip_epoch(self._version), build_name = "{}_{}_{}.build".format(
self._builder.get_architecture()) self._package, strip_epoch(self._version), self._builder.get_architecture()
)
self._build_log = os.path.join(self._buildresult, build_name) self._build_log = os.path.join(self._buildresult, build_name)
successful_built = False successful_built = False
@ -191,8 +196,7 @@ class SourcePackage(object):
update = False update = False
# build package # build package
result = self._builder.build(self._dsc_file, dist, result = self._builder.build(self._dsc_file, dist, self._buildresult)
self._buildresult)
if result != 0: if result != 0:
question = Question(["yes", "update", "retry", "no"]) question = Question(["yes", "update", "retry", "no"])
answer = question.ask("Do you want to resolve this issue manually", "yes") answer = question.ask("Do you want to resolve this issue manually", "yes")
@ -224,13 +228,14 @@ class SourcePackage(object):
""" """
if self._branch: if self._branch:
cmd = ['bzr', 'builddeb', '--builder=debuild', '-S', cmd = ["bzr", "builddeb", "--builder=debuild", "-S", "--", "--no-lintian", "-nc"]
'--', '--no-lintian', '-nc']
else: else:
cmd = ['debuild', '--no-lintian', '-nc', '-S'] cmd = ["debuild", "--no-lintian", "-nc", "-S"]
cmd.append("-v" + previous_version.full_version) cmd.append("-v" + previous_version.full_version)
if previous_version.upstream_version == \ if (
self._changelog.upstream_version and upload == "ubuntu": previous_version.upstream_version == self._changelog.upstream_version
and upload == "ubuntu"
):
# FIXME: Add proper check that catches cases like changed # FIXME: Add proper check that catches cases like changed
# compression (.tar.gz -> tar.bz2) and multiple orig source tarballs # compression (.tar.gz -> tar.bz2) and multiple orig source tarballs
cmd.append("-sd") cmd.append("-sd")
@ -239,9 +244,9 @@ class SourcePackage(object):
if keyid is not None: if keyid is not None:
cmd += ["-k" + keyid] cmd += ["-k" + keyid]
env = os.environ env = os.environ
if upload == 'ubuntu': if upload == "ubuntu":
env['DEB_VENDOR'] = 'Ubuntu' env["DEB_VENDOR"] = "Ubuntu"
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd, env=env) != 0: if subprocess.call(cmd, env=env) != 0:
Logger.error("Failed to build source tarball.") Logger.error("Failed to build source tarball.")
# TODO: Add a "retry" option # TODO: Add a "retry" option
@ -252,8 +257,9 @@ class SourcePackage(object):
@property @property
def _changes_file(self): def _changes_file(self):
"""Returns the file name of the .changes file.""" """Returns the file name of the .changes file."""
return os.path.join(self._workdir, "{}_{}_source.changes" return os.path.join(
.format(self._package, strip_epoch(self._version))) self._workdir, "{}_{}_source.changes".format(self._package, strip_epoch(self._version))
)
def check_target(self, upload, launchpad): def check_target(self, upload, launchpad):
"""Make sure that the target is correct. """Make sure that the target is correct.
@ -265,18 +271,22 @@ class SourcePackage(object):
(devel_series, supported_series) = _get_series(launchpad) (devel_series, supported_series) = _get_series(launchpad)
if upload == "ubuntu": if upload == "ubuntu":
allowed = supported_series + \ allowed = (
[s + "-proposed" for s in supported_series] + \ supported_series + [s + "-proposed" for s in supported_series] + [devel_series]
[devel_series] )
if self._changelog.distributions not in allowed: if self._changelog.distributions not in allowed:
Logger.error("%s is not an allowed series. It needs to be one of %s." % Logger.error(
(self._changelog.distributions, ", ".join(allowed))) "%s is not an allowed series. It needs to be one of %s."
% (self._changelog.distributions, ", ".join(allowed))
)
return ask_for_ignoring_or_fixing() return ask_for_ignoring_or_fixing()
elif upload and upload.startswith("ppa/"): elif upload and upload.startswith("ppa/"):
allowed = supported_series + [devel_series] allowed = supported_series + [devel_series]
if self._changelog.distributions not in allowed: if self._changelog.distributions not in allowed:
Logger.error("%s is not an allowed series. It needs to be one of %s." % Logger.error(
(self._changelog.distributions, ", ".join(allowed))) "%s is not an allowed series. It needs to be one of %s."
% (self._changelog.distributions, ", ".join(allowed))
)
return ask_for_ignoring_or_fixing() return ask_for_ignoring_or_fixing()
return True return True
@ -288,14 +298,17 @@ class SourcePackage(object):
""" """
if self._version <= previous_version: if self._version <= previous_version:
Logger.error("The version %s is not greater than the already " Logger.error(
"available %s.", self._version, previous_version) "The version %s is not greater than the already available %s.",
self._version,
previous_version,
)
return ask_for_ignoring_or_fixing() return ask_for_ignoring_or_fixing()
return True return True
def check_sync_request_version(self, bug_number, task): def check_sync_request_version(self, bug_number, task):
"""Check if the downloaded version of the package is mentioned in the """Check if the downloaded version of the package is mentioned in the
bug title.""" bug title."""
if not task.title_contains(self._version): if not task.title_contains(self._version):
print("Bug #%i title: %s" % (bug_number, task.get_bug_title())) print("Bug #%i title: %s" % (bug_number, task.get_bug_title()))
@ -313,20 +326,20 @@ class SourcePackage(object):
@property @property
def _dsc_file(self): def _dsc_file(self):
"""Returns the file name of the .dsc file.""" """Returns the file name of the .dsc file."""
return os.path.join(self._workdir, "{}_{}.dsc".format(self._package, return os.path.join(
strip_epoch(self._version))) self._workdir, "{}_{}.dsc".format(self._package, strip_epoch(self._version))
)
def generate_debdiff(self, dsc_file): def generate_debdiff(self, dsc_file):
"""Generates a debdiff between the given .dsc file and this source """Generates a debdiff between the given .dsc file and this source
package.""" package."""
assert os.path.isfile(dsc_file), "%s does not exist." % (dsc_file) assert os.path.isfile(dsc_file), "%s does not exist." % (dsc_file)
assert os.path.isfile(self._dsc_file), "%s does not exist." % \ assert os.path.isfile(self._dsc_file), "%s does not exist." % (self._dsc_file)
(self._dsc_file)
cmd = ["debdiff", dsc_file, self._dsc_file] cmd = ["debdiff", dsc_file, self._dsc_file]
if not Logger.isEnabledFor(logging.DEBUG): if not Logger.isEnabledFor(logging.DEBUG):
cmd.insert(1, "-q") cmd.insert(1, "-q")
Logger.debug(' '.join(cmd) + " > " + self._debdiff_filename) Logger.debug(" ".join(cmd) + " > " + self._debdiff_filename)
with open(self._debdiff_filename, "w") as debdiff_file: with open(self._debdiff_filename, "w") as debdiff_file:
debdiff = subprocess.run(cmd, check=False, stdout=debdiff_file) debdiff = subprocess.run(cmd, check=False, stdout=debdiff_file)
assert debdiff.returncode in (0, 1) assert debdiff.returncode in (0, 1)
@ -376,8 +389,7 @@ class SourcePackage(object):
# Check the changelog # Check the changelog
self._changelog = debian.changelog.Changelog() self._changelog = debian.changelog.Changelog()
try: try:
self._changelog.parse_changelog(open("debian/changelog"), self._changelog.parse_changelog(open("debian/changelog"), max_blocks=1, strict=True)
max_blocks=1, strict=True)
except debian.changelog.ChangelogParseError as error: except debian.changelog.ChangelogParseError as error:
Logger.error("The changelog entry doesn't validate: %s", str(error)) Logger.error("The changelog entry doesn't validate: %s", str(error))
ask_for_manual_fixing() ask_for_manual_fixing()
@ -387,8 +399,10 @@ class SourcePackage(object):
try: try:
self._version = self._changelog.get_version() self._version = self._changelog.get_version()
except IndexError: except IndexError:
Logger.error("Debian package version could not be determined. " Logger.error(
"debian/changelog is probably malformed.") "Debian package version could not be determined. "
"debian/changelog is probably malformed."
)
ask_for_manual_fixing() ask_for_manual_fixing()
return False return False
@ -402,22 +416,26 @@ class SourcePackage(object):
# Determine whether to use the source or binary build for lintian # Determine whether to use the source or binary build for lintian
if self._build_log: if self._build_log:
build_changes = self._package + "_" + strip_epoch(self._version) + \ build_changes = (
"_" + self._builder.get_architecture() + ".changes" self._package
+ "_"
+ strip_epoch(self._version)
+ "_"
+ self._builder.get_architecture()
+ ".changes"
)
changes_for_lintian = os.path.join(self._buildresult, build_changes) changes_for_lintian = os.path.join(self._buildresult, build_changes)
else: else:
changes_for_lintian = self._changes_file changes_for_lintian = self._changes_file
# Check lintian # Check lintian
assert os.path.isfile(changes_for_lintian), "%s does not exist." % \ assert os.path.isfile(changes_for_lintian), "%s does not exist." % (changes_for_lintian)
(changes_for_lintian) cmd = ["lintian", "-IE", "--pedantic", "-q", "--profile", "ubuntu", changes_for_lintian]
cmd = ["lintian", "-IE", "--pedantic", "-q", "--profile", "ubuntu", lintian_filename = os.path.join(
changes_for_lintian] self._workdir, self._package + "_" + strip_epoch(self._version) + ".lintian"
lintian_filename = os.path.join(self._workdir, )
self._package + "_" + Logger.debug(" ".join(cmd) + " > " + lintian_filename)
strip_epoch(self._version) + ".lintian") report = subprocess.check_output(cmd, encoding="utf-8")
Logger.debug(' '.join(cmd) + " > " + lintian_filename)
report = subprocess.check_output(cmd, encoding='utf-8')
# write lintian report file # write lintian report file
lintian_file = open(lintian_filename, "w") lintian_file = open(lintian_filename, "w")
@ -430,17 +448,25 @@ class SourcePackage(object):
"""Does a sync of the source package.""" """Does a sync of the source package."""
if upload == "ubuntu": if upload == "ubuntu":
cmd = ["syncpackage", self._package, "-b", str(bug_number), "-f", cmd = [
"-s", requester, "-V", str(self._version), "syncpackage",
"-d", series] self._package,
Logger.debug(' '.join(cmd)) "-b",
str(bug_number),
"-f",
"-s",
requester,
"-V",
str(self._version),
"-d",
series,
]
Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Syncing of %s %s failed.", self._package, Logger.error("Syncing of %s %s failed.", self._package, str(self._version))
str(self._version))
sys.exit(1) sys.exit(1)
else: else:
# FIXME: Support this use case! # FIXME: Support this use case!
Logger.error("Uploading a synced package other than to Ubuntu " Logger.error("Uploading a synced package other than to Ubuntu is not supported yet!")
"is not supported yet!")
sys.exit(1) sys.exit(1)
return True return True

View File

@ -25,8 +25,7 @@ from distro_info import UbuntuDistroInfo
from launchpadlib.launchpad import Launchpad from launchpadlib.launchpad import Launchpad
from ubuntutools.update_maintainer import (update_maintainer, from ubuntutools.update_maintainer import update_maintainer, MaintainerUpdateException
MaintainerUpdateException)
from ubuntutools.question import input_number from ubuntutools.question import input_number
from ubuntutools.sponsor_patch.bugtask import BugTask, is_sync from ubuntutools.sponsor_patch.bugtask import BugTask, is_sync
@ -35,34 +34,35 @@ from ubuntutools.sponsor_patch.question import ask_for_manual_fixing
from ubuntutools.sponsor_patch.source_package import SourcePackage from ubuntutools.sponsor_patch.source_package import SourcePackage
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
def is_command_available(command, check_sbin=False): def is_command_available(command, check_sbin=False):
"Is command in $PATH?" "Is command in $PATH?"
path = os.environ.get('PATH', '/usr/bin:/bin').split(':') path = os.environ.get("PATH", "/usr/bin:/bin").split(":")
if check_sbin: if check_sbin:
path += [directory[:-3] + 'sbin' path += [directory[:-3] + "sbin" for directory in path if directory.endswith("/bin")]
for directory in path if directory.endswith('/bin')] return any(os.access(os.path.join(directory, command), os.X_OK) for directory in path)
return any(os.access(os.path.join(directory, command), os.X_OK)
for directory in path)
def check_dependencies(): def check_dependencies():
"Do we have all the commands we need for full functionality?" "Do we have all the commands we need for full functionality?"
missing = [] missing = []
for cmd in ('patch', 'bzr', 'quilt', 'dput', 'lintian'): for cmd in ("patch", "bzr", "quilt", "dput", "lintian"):
if not is_command_available(cmd): if not is_command_available(cmd):
missing.append(cmd) missing.append(cmd)
if not is_command_available('bzr-buildpackage'): if not is_command_available("bzr-buildpackage"):
missing.append('bzr-builddeb') missing.append("bzr-builddeb")
if not any(is_command_available(cmd, check_sbin=True) if not any(
for cmd in ('pbuilder', 'sbuild', 'cowbuilder')): is_command_available(cmd, check_sbin=True) for cmd in ("pbuilder", "sbuild", "cowbuilder")
missing.append('pbuilder/cowbuilder/sbuild') ):
missing.append("pbuilder/cowbuilder/sbuild")
if missing: if missing:
Logger.warning("sponsor-patch requires %s to be installed for full " Logger.warning(
"functionality", ', '.join(missing)) "sponsor-patch requires %s to be installed for full functionality", ", ".join(missing)
)
def get_source_package_name(bug_task): def get_source_package_name(bug_task):
@ -84,12 +84,16 @@ def get_user_shell():
def edit_source(): def edit_source():
# Spawn shell to allow modifications # Spawn shell to allow modifications
cmd = [get_user_shell()] cmd = [get_user_shell()]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
print("""An interactive shell was launched in print(
"""An interactive shell was launched in
file://%s file://%s
Edit your files. When you are done, exit the shell. If you wish to abort the Edit your files. When you are done, exit the shell. If you wish to abort the
process, exit the shell such that it returns an exit code other than zero. process, exit the shell such that it returns an exit code other than zero.
""" % (os.getcwd()), end=' ') """
% (os.getcwd()),
end=" ",
)
returncode = subprocess.call(cmd) returncode = subprocess.call(cmd)
if returncode != 0: if returncode != 0:
Logger.error("Shell exited with exit value %i." % (returncode)) Logger.error("Shell exited with exit value %i." % (returncode))
@ -100,11 +104,15 @@ def ask_for_patch_or_branch(bug, attached_patches, linked_branches):
patch = None patch = None
branch = None branch = None
if len(attached_patches) == 0: if len(attached_patches) == 0:
msg = "https://launchpad.net/bugs/%i has %i branches linked:" % \ msg = "https://launchpad.net/bugs/%i has %i branches linked:" % (
(bug.id, len(linked_branches)) bug.id,
len(linked_branches),
)
elif len(linked_branches) == 0: elif len(linked_branches) == 0:
msg = "https://launchpad.net/bugs/%i has %i patches attached:" % \ msg = "https://launchpad.net/bugs/%i has %i patches attached:" % (
(bug.id, len(attached_patches)) bug.id,
len(attached_patches),
)
else: else:
branches = "%i branch" % len(linked_branches) branches = "%i branch" % len(linked_branches)
if len(linked_branches) > 1: if len(linked_branches) > 1:
@ -112,8 +120,11 @@ def ask_for_patch_or_branch(bug, attached_patches, linked_branches):
patches = "%i patch" % len(attached_patches) patches = "%i patch" % len(attached_patches)
if len(attached_patches) > 1: if len(attached_patches) > 1:
patches += "es" patches += "es"
msg = "https://launchpad.net/bugs/%i has %s linked and %s attached:" % \ msg = "https://launchpad.net/bugs/%i has %s linked and %s attached:" % (
(bug.id, branches, patches) bug.id,
branches,
patches,
)
Logger.info(msg) Logger.info(msg)
i = 0 i = 0
for linked_branch in linked_branches: for linked_branch in linked_branches:
@ -122,8 +133,7 @@ def ask_for_patch_or_branch(bug, attached_patches, linked_branches):
for attached_patch in attached_patches: for attached_patch in attached_patches:
i += 1 i += 1
print("%i) %s" % (i, attached_patch.title)) print("%i) %s" % (i, attached_patch.title))
selected = input_number("Which branch or patch do you want to download", selected = input_number("Which branch or patch do you want to download", 1, i, i)
1, i, i)
if selected <= len(linked_branches): if selected <= len(linked_branches):
branch = linked_branches[selected - 1].bzr_identity branch = linked_branches[selected - 1].bzr_identity
else: else:
@ -139,21 +149,26 @@ def get_patch_or_branch(bug):
linked_branches = [b.branch for b in bug.linked_branches] linked_branches = [b.branch for b in bug.linked_branches]
if len(attached_patches) == 0 and len(linked_branches) == 0: if len(attached_patches) == 0 and len(linked_branches) == 0:
if len(bug.attachments) == 0: if len(bug.attachments) == 0:
Logger.error("No attachment and no linked branch found on " Logger.error(
"bug #%i. Add the tag sync to the bug if it is " "No attachment and no linked branch found on "
"a sync request.", bug.id) "bug #%i. Add the tag sync to the bug if it is "
"a sync request.",
bug.id,
)
else: else:
Logger.error("No attached patch and no linked branch found. " Logger.error(
"Go to https://launchpad.net/bugs/%i and mark an " "No attached patch and no linked branch found. "
"attachment as patch.", bug.id) "Go to https://launchpad.net/bugs/%i and mark an "
"attachment as patch.",
bug.id,
)
sys.exit(1) sys.exit(1)
elif len(attached_patches) == 1 and len(linked_branches) == 0: elif len(attached_patches) == 1 and len(linked_branches) == 0:
patch = Patch(attached_patches[0]) patch = Patch(attached_patches[0])
elif len(attached_patches) == 0 and len(linked_branches) == 1: elif len(attached_patches) == 0 and len(linked_branches) == 1:
branch = linked_branches[0].bzr_identity branch = linked_branches[0].bzr_identity
else: else:
patch, branch = ask_for_patch_or_branch(bug, attached_patches, patch, branch = ask_for_patch_or_branch(bug, attached_patches, linked_branches)
linked_branches)
return (patch, branch) return (patch, branch)
@ -162,7 +177,7 @@ def download_branch(branch):
if os.path.isdir(dir_name): if os.path.isdir(dir_name):
shutil.rmtree(dir_name) shutil.rmtree(dir_name)
cmd = ["bzr", "branch", branch] cmd = ["bzr", "branch", branch]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Failed to download branch %s." % (branch)) Logger.error("Failed to download branch %s." % (branch))
sys.exit(1) sys.exit(1)
@ -172,7 +187,7 @@ def download_branch(branch):
def merge_branch(branch): def merge_branch(branch):
edit = False edit = False
cmd = ["bzr", "merge", branch] cmd = ["bzr", "merge", branch]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Failed to merge branch %s." % (branch)) Logger.error("Failed to merge branch %s." % (branch))
ask_for_manual_fixing() ask_for_manual_fixing()
@ -184,7 +199,7 @@ def extract_source(dsc_file, verbose=False):
cmd = ["dpkg-source", "--skip-patches", "-x", dsc_file] cmd = ["dpkg-source", "--skip-patches", "-x", dsc_file]
if not verbose: if not verbose:
cmd.insert(1, "-q") cmd.insert(1, "-q")
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.error("Extraction of %s failed." % (os.path.basename(dsc_file))) Logger.error("Extraction of %s failed." % (os.path.basename(dsc_file)))
sys.exit(1) sys.exit(1)
@ -201,7 +216,7 @@ def get_open_ubuntu_bug_task(launchpad, bug, branch=None):
ubuntu_tasks = [x for x in bug_tasks if x.is_ubuntu_task()] ubuntu_tasks = [x for x in bug_tasks if x.is_ubuntu_task()]
bug_id = bug.id bug_id = bug.id
if branch: if branch:
branch = branch.split('/') branch = branch.split("/")
# Non-production LP? # Non-production LP?
if len(branch) > 5: if len(branch) > 5:
branch = branch[3:] branch = branch[3:]
@ -211,9 +226,8 @@ def get_open_ubuntu_bug_task(launchpad, bug, branch=None):
sys.exit(1) sys.exit(1)
elif len(ubuntu_tasks) == 1: elif len(ubuntu_tasks) == 1:
task = ubuntu_tasks[0] task = ubuntu_tasks[0]
if len(ubuntu_tasks) > 1 and branch and branch[1] == 'ubuntu': if len(ubuntu_tasks) > 1 and branch and branch[1] == "ubuntu":
tasks = [t for t in ubuntu_tasks if tasks = [t for t in ubuntu_tasks if t.get_series() == branch[2] and t.package == branch[3]]
t.get_series() == branch[2] and t.package == branch[3]]
if len(tasks) > 1: if len(tasks) > 1:
# A bug targeted to the development series? # A bug targeted to the development series?
tasks = [t for t in tasks if t.series is not None] tasks = [t for t in tasks if t.series is not None]
@ -221,19 +235,24 @@ def get_open_ubuntu_bug_task(launchpad, bug, branch=None):
task = tasks[0] task = tasks[0]
elif len(ubuntu_tasks) > 1: elif len(ubuntu_tasks) > 1:
task_list = [t.get_short_info() for t in ubuntu_tasks] task_list = [t.get_short_info() for t in ubuntu_tasks]
Logger.debug("%i Ubuntu tasks exist for bug #%i.\n%s", len(ubuntu_tasks), Logger.debug(
bug_id, "\n".join(task_list)) "%i Ubuntu tasks exist for bug #%i.\n%s",
len(ubuntu_tasks),
bug_id,
"\n".join(task_list),
)
open_ubuntu_tasks = [x for x in ubuntu_tasks if not x.is_complete()] open_ubuntu_tasks = [x for x in ubuntu_tasks if not x.is_complete()]
if len(open_ubuntu_tasks) == 1: if len(open_ubuntu_tasks) == 1:
task = open_ubuntu_tasks[0] task = open_ubuntu_tasks[0]
else: else:
Logger.info("https://launchpad.net/bugs/%i has %i Ubuntu tasks:" % Logger.info(
(bug_id, len(ubuntu_tasks))) "https://launchpad.net/bugs/%i has %i Ubuntu tasks:" % (bug_id, len(ubuntu_tasks))
)
for i in range(len(ubuntu_tasks)): for i in range(len(ubuntu_tasks)):
print("%i) %s" % (i + 1, print("%i) %s" % (i + 1, ubuntu_tasks[i].get_package_and_series()))
ubuntu_tasks[i].get_package_and_series())) selected = input_number(
selected = input_number("To which Ubuntu task does the patch belong", "To which Ubuntu task does the patch belong", 1, len(ubuntu_tasks)
1, len(ubuntu_tasks)) )
task = ubuntu_tasks[selected - 1] task = ubuntu_tasks[selected - 1]
Logger.debug("Selected Ubuntu task: %s" % (task.get_short_info())) Logger.debug("Selected Ubuntu task: %s" % (task.get_short_info()))
return task return task
@ -246,8 +265,10 @@ def _create_and_change_into(workdir):
try: try:
os.makedirs(workdir) os.makedirs(workdir)
except os.error as error: except os.error as error:
Logger.error("Failed to create the working directory %s [Errno %i]: %s." % Logger.error(
(workdir, error.errno, error.strerror)) "Failed to create the working directory %s [Errno %i]: %s."
% (workdir, error.errno, error.strerror)
)
sys.exit(1) sys.exit(1)
if workdir != os.getcwd(): if workdir != os.getcwd():
Logger.debug("cd " + workdir) Logger.debug("cd " + workdir)
@ -267,7 +288,7 @@ def _update_maintainer_field():
def _update_timestamp(): def _update_timestamp():
"""Run dch to update the timestamp of debian/changelog.""" """Run dch to update the timestamp of debian/changelog."""
cmd = ["dch", "--maintmaint", "--release", ""] cmd = ["dch", "--maintmaint", "--release", ""]
Logger.debug(' '.join(cmd)) Logger.debug(" ".join(cmd))
if subprocess.call(cmd) != 0: if subprocess.call(cmd) != 0:
Logger.debug("Failed to update timestamp in debian/changelog.") Logger.debug("Failed to update timestamp in debian/changelog.")
@ -294,13 +315,12 @@ def _download_and_change_into(task, dsc_file, patch, branch):
extract_source(dsc_file, Logger.isEnabledFor(logging.DEBUG)) extract_source(dsc_file, Logger.isEnabledFor(logging.DEBUG))
# change directory # change directory
directory = task.package + '-' + task.get_version().upstream_version directory = task.package + "-" + task.get_version().upstream_version
Logger.debug("cd " + directory) Logger.debug("cd " + directory)
os.chdir(directory) os.chdir(directory)
def sponsor_patch(bug_number, build, builder, edit, keyid, lpinstance, update, def sponsor_patch(bug_number, build, builder, edit, keyid, lpinstance, update, upload, workdir):
upload, workdir):
workdir = os.path.realpath(os.path.expanduser(workdir)) workdir = os.path.realpath(os.path.expanduser(workdir))
_create_and_change_into(workdir) _create_and_change_into(workdir)
@ -331,8 +351,7 @@ def sponsor_patch(bug_number, build, builder, edit, keyid, lpinstance, update,
update = False update = False
else: else:
# We are going to run lintian, so we need a source package # We are going to run lintian, so we need a source package
successful = source_package.build_source(None, upload, successful = source_package.build_source(None, upload, previous_version)
previous_version)
if successful: if successful:
series = task.get_debian_source_series() series = task.get_debian_source_series()
@ -363,8 +382,7 @@ def sponsor_patch(bug_number, build, builder, edit, keyid, lpinstance, update,
_update_timestamp() _update_timestamp()
if not source_package.build_source(keyid, upload, if not source_package.build_source(keyid, upload, task.get_previous_version()):
task.get_previous_version()):
continue continue
source_package.generate_debdiff(dsc_file) source_package.generate_debdiff(dsc_file)

View File

@ -23,38 +23,38 @@ from ubuntutools.version import Version
class ExamplePackage(object): class ExamplePackage(object):
def __init__(self, source='example', version='1.0-1', destdir='test-data'): def __init__(self, source="example", version="1.0-1", destdir="test-data"):
self.source = source self.source = source
self.version = Version(version) self.version = Version(version)
self.destdir = Path(destdir) self.destdir = Path(destdir)
self.env = dict(os.environ) self.env = dict(os.environ)
self.env['DEBFULLNAME'] = 'Example' self.env["DEBFULLNAME"] = "Example"
self.env['DEBEMAIL'] = 'example@example.net' self.env["DEBEMAIL"] = "example@example.net"
@property @property
def orig(self): def orig(self):
return self.destdir / f'{self.source}_{self.version.upstream_version}.orig.tar.xz' return self.destdir / f"{self.source}_{self.version.upstream_version}.orig.tar.xz"
@property @property
def debian(self): def debian(self):
return self.destdir / f'{self.source}_{self.version}.debian.tar.xz' return self.destdir / f"{self.source}_{self.version}.debian.tar.xz"
@property @property
def dsc(self): def dsc(self):
return self.destdir / f'{self.source}_{self.version}.dsc' return self.destdir / f"{self.source}_{self.version}.dsc"
@property @property
def dirname(self): def dirname(self):
return f'{self.source}-{self.version.upstream_version}' return f"{self.source}-{self.version.upstream_version}"
@property @property
def content_filename(self): def content_filename(self):
return 'content' return "content"
@property @property
def content_text(self): def content_text(self):
return 'my content' return "my content"
def create(self): def create(self):
with tempfile.TemporaryDirectory() as d: with tempfile.TemporaryDirectory() as d:
@ -66,14 +66,24 @@ class ExamplePackage(object):
(pkgdir / self.content_filename).write_text(self.content_text) (pkgdir / self.content_filename).write_text(self.content_text)
# run dh_make to create orig tarball # run dh_make to create orig tarball
subprocess.run('dh_make -sy --createorig'.split(), subprocess.run(
check=True, env=self.env, cwd=str(pkgdir), "dh_make -sy --createorig".split(),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) check=True,
env=self.env,
cwd=str(pkgdir),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# run dpkg-source -b to create debian tar and dsc # run dpkg-source -b to create debian tar and dsc
subprocess.run(f'dpkg-source -b {self.dirname}'.split(), subprocess.run(
check=True, env=self.env, cwd=str(d), f"dpkg-source -b {self.dirname}".split(),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) check=True,
env=self.env,
cwd=str(d),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# move tarballs and dsc to destdir # move tarballs and dsc to destdir
self.destdir.mkdir(parents=True, exist_ok=True) self.destdir.mkdir(parents=True, exist_ok=True)

View File

@ -41,7 +41,7 @@ class DscVerificationTestCase(BaseVerificationTestCase):
self.assertTrue(self.dsc.verify_file(self.pkg.debian)) self.assertTrue(self.dsc.verify_file(self.pkg.debian))
def test_missing(self): def test_missing(self):
self.assertFalse(self.dsc.verify_file(self.pkg.destdir / 'does.not.exist')) self.assertFalse(self.dsc.verify_file(self.pkg.destdir / "does.not.exist"))
def test_bad(self): def test_bad(self):
data = self.pkg.orig.read_bytes() data = self.pkg.orig.read_bytes()
@ -51,13 +51,13 @@ class DscVerificationTestCase(BaseVerificationTestCase):
self.assertFalse(self.dsc.verify_file(self.pkg.orig)) self.assertFalse(self.dsc.verify_file(self.pkg.orig))
def test_sha1(self): def test_sha1(self):
del self.dsc['Checksums-Sha256'] del self.dsc["Checksums-Sha256"]
self.test_good() self.test_good()
self.test_bad() self.test_bad()
def test_md5(self): def test_md5(self):
del self.dsc['Checksums-Sha256'] del self.dsc["Checksums-Sha256"]
del self.dsc['Checksums-Sha1'] del self.dsc["Checksums-Sha1"]
self.test_good() self.test_good()
self.test_bad() self.test_bad()
@ -72,7 +72,7 @@ class LocalSourcePackageTestCase(BaseVerificationTestCase):
self.workdir = Path(d.name) self.workdir = Path(d.name)
def pull(self, **kwargs): def pull(self, **kwargs):
''' Do the pull from pkg dir to the workdir, return the SourcePackage ''' """Do the pull from pkg dir to the workdir, return the SourcePackage"""
srcpkg = self.SourcePackage(dscfile=self.pkg.dsc, workdir=self.workdir, **kwargs) srcpkg = self.SourcePackage(dscfile=self.pkg.dsc, workdir=self.workdir, **kwargs)
srcpkg.pull() srcpkg.pull()
return srcpkg return srcpkg
@ -85,11 +85,11 @@ class LocalSourcePackageTestCase(BaseVerificationTestCase):
return srcpkg return srcpkg
def test_unpack(self, **kwargs): def test_unpack(self, **kwargs):
srcpkg = kwargs.get('srcpkg', self.pull(**kwargs)) srcpkg = kwargs.get("srcpkg", self.pull(**kwargs))
srcpkg.unpack() srcpkg.unpack()
content = self.workdir / self.pkg.dirname / self.pkg.content_filename content = self.workdir / self.pkg.dirname / self.pkg.content_filename
self.assertEqual(self.pkg.content_text, content.read_text()) self.assertEqual(self.pkg.content_text, content.read_text())
debian = self.workdir / self.pkg.dirname / 'debian' debian = self.workdir / self.pkg.dirname / "debian"
self.assertTrue(debian.exists()) self.assertTrue(debian.exists())
self.assertTrue(debian.is_dir()) self.assertTrue(debian.is_dir())
@ -103,12 +103,12 @@ class LocalSourcePackageTestCase(BaseVerificationTestCase):
self.test_pull_and_unpack(package=self.pkg.source, version=self.pkg.version) self.test_pull_and_unpack(package=self.pkg.source, version=self.pkg.version)
def test_with_package_version_component(self): def test_with_package_version_component(self):
self.test_pull_and_unpack(package=self.pkg.source, self.test_pull_and_unpack(
version=self.pkg.version, package=self.pkg.source, version=self.pkg.version, componet="main"
componet='main') )
def test_verification(self): def test_verification(self):
corruption = b'CORRUPTION' corruption = b"CORRUPTION"
self.pull() self.pull()

View File

@ -17,7 +17,6 @@
import locale import locale
import os import os
# import sys
import unittest import unittest
from io import StringIO from io import StringIO
@ -27,17 +26,14 @@ from ubuntutools.config import UDTConfig, ubu_email
class ConfigTestCase(unittest.TestCase): class ConfigTestCase(unittest.TestCase):
_config_files = { _config_files = {"system": "", "user": ""}
'system': '',
'user': '',
}
def _fake_open(self, filename, mode='r'): def _fake_open(self, filename, mode="r"):
if mode != 'r': if mode != "r":
raise IOError("Read only fake-file") raise IOError("Read only fake-file")
files = { files = {
'/etc/devscripts.conf': self._config_files['system'], "/etc/devscripts.conf": self._config_files["system"],
os.path.expanduser('~/.devscripts'): self._config_files['user'], os.path.expanduser("~/.devscripts"): self._config_files["user"],
} }
if filename not in files: if filename not in files:
raise IOError("No such file or directory: '%s'" % filename) raise IOError("No such file or directory: '%s'" % filename)
@ -47,7 +43,7 @@ class ConfigTestCase(unittest.TestCase):
super(ConfigTestCase, self).setUp() super(ConfigTestCase, self).setUp()
m = mock.mock_open() m = mock.mock_open()
m.side_effect = self._fake_open m.side_effect = self._fake_open
patcher = mock.patch('builtins.open', m) patcher = mock.patch("builtins.open", m)
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
patcher.start() patcher.start()
@ -65,14 +61,16 @@ class ConfigTestCase(unittest.TestCase):
self.clean_environment() self.clean_environment()
def clean_environment(self): def clean_environment(self):
self._config_files['system'] = '' self._config_files["system"] = ""
self._config_files['user'] = '' self._config_files["user"] = ""
for k in list(os.environ.keys()): for k in list(os.environ.keys()):
if k.startswith(('UBUNTUTOOLS_', 'TEST_')): if k.startswith(("UBUNTUTOOLS_", "TEST_")):
del os.environ[k] del os.environ[k]
def test_config_parsing(self): def test_config_parsing(self):
self._config_files['user'] = """#COMMENT=yes self._config_files[
"user"
] = """#COMMENT=yes
\tTAB_INDENTED=yes \tTAB_INDENTED=yes
SPACE_INDENTED=yes SPACE_INDENTED=yes
SPACE_SUFFIX=yes SPACE_SUFFIX=yes
@ -85,19 +83,22 @@ INHERIT=user
REPEAT=no REPEAT=no
REPEAT=yes REPEAT=yes
""" """
self._config_files['system'] = 'INHERIT=system' self._config_files["system"] = "INHERIT=system"
self.assertEqual(UDTConfig(prefix='TEST').config, { self.assertEqual(
'TAB_INDENTED': 'yes', UDTConfig(prefix="TEST").config,
'SPACE_INDENTED': 'yes', {
'SPACE_SUFFIX': 'yes', "TAB_INDENTED": "yes",
'SINGLE_QUOTE': 'yes no', "SPACE_INDENTED": "yes",
'DOUBLE_QUOTE': 'yes no', "SPACE_SUFFIX": "yes",
'QUOTED_QUOTE': "it's", "SINGLE_QUOTE": "yes no",
'PAIR_QUOTES': 'yes a no', "DOUBLE_QUOTE": "yes no",
'COMMAND_EXECUTION': 'a', "QUOTED_QUOTE": "it's",
'INHERIT': 'user', "PAIR_QUOTES": "yes a no",
'REPEAT': 'yes', "COMMAND_EXECUTION": "a",
}) "INHERIT": "user",
"REPEAT": "yes",
},
)
# errs = Logger.stderr.getvalue().strip() # errs = Logger.stderr.getvalue().strip()
# Logger.stderr = StringIO() # Logger.stderr = StringIO()
# self.assertEqual(len(errs.splitlines()), 1) # self.assertEqual(len(errs.splitlines()), 1)
@ -105,39 +106,40 @@ REPEAT=yes
# r'Warning: Cannot parse.*\bCOMMAND_EXECUTION=a') # r'Warning: Cannot parse.*\bCOMMAND_EXECUTION=a')
def get_value(self, *args, **kwargs): def get_value(self, *args, **kwargs):
config = UDTConfig(prefix='TEST') config = UDTConfig(prefix="TEST")
return config.get_value(*args, **kwargs) return config.get_value(*args, **kwargs)
def test_defaults(self): def test_defaults(self):
self.assertEqual(self.get_value('BUILDER'), 'pbuilder') self.assertEqual(self.get_value("BUILDER"), "pbuilder")
def test_provided_default(self): def test_provided_default(self):
self.assertEqual(self.get_value('BUILDER', default='foo'), 'foo') self.assertEqual(self.get_value("BUILDER", default="foo"), "foo")
def test_scriptname_precedence(self): def test_scriptname_precedence(self):
self._config_files['user'] = """TEST_BUILDER=foo self._config_files[
"user"
] = """TEST_BUILDER=foo
UBUNTUTOOLS_BUILDER=bar""" UBUNTUTOOLS_BUILDER=bar"""
self.assertEqual(self.get_value('BUILDER'), 'foo') self.assertEqual(self.get_value("BUILDER"), "foo")
def test_configfile_precedence(self): def test_configfile_precedence(self):
self._config_files['system'] = "UBUNTUTOOLS_BUILDER=foo" self._config_files["system"] = "UBUNTUTOOLS_BUILDER=foo"
self._config_files['user'] = "UBUNTUTOOLS_BUILDER=bar" self._config_files["user"] = "UBUNTUTOOLS_BUILDER=bar"
self.assertEqual(self.get_value('BUILDER'), 'bar') self.assertEqual(self.get_value("BUILDER"), "bar")
def test_environment_precedence(self): def test_environment_precedence(self):
self._config_files['user'] = "UBUNTUTOOLS_BUILDER=bar" self._config_files["user"] = "UBUNTUTOOLS_BUILDER=bar"
os.environ['UBUNTUTOOLS_BUILDER'] = 'baz' os.environ["UBUNTUTOOLS_BUILDER"] = "baz"
self.assertEqual(self.get_value('BUILDER'), 'baz') self.assertEqual(self.get_value("BUILDER"), "baz")
def test_general_environment_specific_config_precedence(self): def test_general_environment_specific_config_precedence(self):
self._config_files['user'] = "TEST_BUILDER=bar" self._config_files["user"] = "TEST_BUILDER=bar"
os.environ['UBUNTUTOOLS_BUILDER'] = 'foo' os.environ["UBUNTUTOOLS_BUILDER"] = "foo"
self.assertEqual(self.get_value('BUILDER'), 'bar') self.assertEqual(self.get_value("BUILDER"), "bar")
def test_compat_keys(self): def test_compat_keys(self):
self._config_files['user'] = 'COMPATFOOBAR=bar' self._config_files["user"] = "COMPATFOOBAR=bar"
self.assertEqual(self.get_value('QUX', compat_keys=['COMPATFOOBAR']), self.assertEqual(self.get_value("QUX", compat_keys=["COMPATFOOBAR"]), "bar")
'bar')
# errs = Logger.stderr.getvalue().strip() # errs = Logger.stderr.getvalue().strip()
# Logger.stderr = StringIO() # Logger.stderr = StringIO()
# self.assertEqual(len(errs.splitlines()), 1) # self.assertEqual(len(errs.splitlines()), 1)
@ -145,16 +147,16 @@ REPEAT=yes
# r'deprecated.*\bCOMPATFOOBAR\b.*\bTEST_QUX\b') # r'deprecated.*\bCOMPATFOOBAR\b.*\bTEST_QUX\b')
def test_boolean(self): def test_boolean(self):
self._config_files['user'] = "TEST_BOOLEAN=yes" self._config_files["user"] = "TEST_BOOLEAN=yes"
self.assertEqual(self.get_value('BOOLEAN', boolean=True), True) self.assertEqual(self.get_value("BOOLEAN", boolean=True), True)
self._config_files['user'] = "TEST_BOOLEAN=no" self._config_files["user"] = "TEST_BOOLEAN=no"
self.assertEqual(self.get_value('BOOLEAN', boolean=True), False) self.assertEqual(self.get_value("BOOLEAN", boolean=True), False)
self._config_files['user'] = "TEST_BOOLEAN=true" self._config_files["user"] = "TEST_BOOLEAN=true"
self.assertEqual(self.get_value('BOOLEAN', boolean=True), None) self.assertEqual(self.get_value("BOOLEAN", boolean=True), None)
def test_nonpackagewide(self): def test_nonpackagewide(self):
self._config_files['user'] = 'UBUNTUTOOLS_FOOBAR=a' self._config_files["user"] = "UBUNTUTOOLS_FOOBAR=a"
self.assertEqual(self.get_value('FOOBAR'), None) self.assertEqual(self.get_value("FOOBAR"), None)
class UbuEmailTestCase(unittest.TestCase): class UbuEmailTestCase(unittest.TestCase):
@ -165,71 +167,72 @@ class UbuEmailTestCase(unittest.TestCase):
self.clean_environment() self.clean_environment()
def clean_environment(self): def clean_environment(self):
for k in ('UBUMAIL', 'DEBEMAIL', 'DEBFULLNAME'): for k in ("UBUMAIL", "DEBEMAIL", "DEBFULLNAME"):
if k in os.environ: if k in os.environ:
del os.environ[k] del os.environ[k]
def test_pristine(self): def test_pristine(self):
os.environ['DEBFULLNAME'] = name = 'Joe Developer' os.environ["DEBFULLNAME"] = name = "Joe Developer"
os.environ['DEBEMAIL'] = email = 'joe@example.net' os.environ["DEBEMAIL"] = email = "joe@example.net"
self.assertEqual(ubu_email(), (name, email)) self.assertEqual(ubu_email(), (name, email))
def test_two_hat(self): def test_two_hat(self):
os.environ['DEBFULLNAME'] = name = 'Joe Developer' os.environ["DEBFULLNAME"] = name = "Joe Developer"
os.environ['DEBEMAIL'] = 'joe@debian.org' os.environ["DEBEMAIL"] = "joe@debian.org"
os.environ['UBUMAIL'] = email = 'joe@ubuntu.com' os.environ["UBUMAIL"] = email = "joe@ubuntu.com"
self.assertEqual(ubu_email(), (name, email)) self.assertEqual(ubu_email(), (name, email))
self.assertEqual(os.environ['DEBFULLNAME'], name) self.assertEqual(os.environ["DEBFULLNAME"], name)
self.assertEqual(os.environ['DEBEMAIL'], email) self.assertEqual(os.environ["DEBEMAIL"], email)
def test_two_hat_cmdlineoverride(self): def test_two_hat_cmdlineoverride(self):
os.environ['DEBFULLNAME'] = 'Joe Developer' os.environ["DEBFULLNAME"] = "Joe Developer"
os.environ['DEBEMAIL'] = 'joe@debian.org' os.environ["DEBEMAIL"] = "joe@debian.org"
os.environ['UBUMAIL'] = 'joe@ubuntu.com' os.environ["UBUMAIL"] = "joe@ubuntu.com"
name = 'Foo Bar' name = "Foo Bar"
email = 'joe@example.net' email = "joe@example.net"
self.assertEqual(ubu_email(name, email), (name, email)) self.assertEqual(ubu_email(name, email), (name, email))
self.assertEqual(os.environ['DEBFULLNAME'], name) self.assertEqual(os.environ["DEBFULLNAME"], name)
self.assertEqual(os.environ['DEBEMAIL'], email) self.assertEqual(os.environ["DEBEMAIL"], email)
def test_two_hat_noexport(self): def test_two_hat_noexport(self):
os.environ['DEBFULLNAME'] = name = 'Joe Developer' os.environ["DEBFULLNAME"] = name = "Joe Developer"
os.environ['DEBEMAIL'] = demail = 'joe@debian.org' os.environ["DEBEMAIL"] = demail = "joe@debian.org"
os.environ['UBUMAIL'] = uemail = 'joe@ubuntu.com' os.environ["UBUMAIL"] = uemail = "joe@ubuntu.com"
self.assertEqual(ubu_email(export=False), (name, uemail)) self.assertEqual(ubu_email(export=False), (name, uemail))
self.assertEqual(os.environ['DEBFULLNAME'], name) self.assertEqual(os.environ["DEBFULLNAME"], name)
self.assertEqual(os.environ['DEBEMAIL'], demail) self.assertEqual(os.environ["DEBEMAIL"], demail)
def test_two_hat_with_name(self): def test_two_hat_with_name(self):
os.environ['DEBFULLNAME'] = 'Joe Developer' os.environ["DEBFULLNAME"] = "Joe Developer"
os.environ['DEBEMAIL'] = 'joe@debian.org' os.environ["DEBEMAIL"] = "joe@debian.org"
name = 'Joe Ubuntunista' name = "Joe Ubuntunista"
email = 'joe@ubuntu.com' email = "joe@ubuntu.com"
os.environ['UBUMAIL'] = '%s <%s>' % (name, email) os.environ["UBUMAIL"] = "%s <%s>" % (name, email)
self.assertEqual(ubu_email(), (name, email)) self.assertEqual(ubu_email(), (name, email))
self.assertEqual(os.environ['DEBFULLNAME'], name) self.assertEqual(os.environ["DEBFULLNAME"], name)
self.assertEqual(os.environ['DEBEMAIL'], email) self.assertEqual(os.environ["DEBEMAIL"], email)
def test_debemail_with_name(self): def test_debemail_with_name(self):
name = 'Joe Developer' name = "Joe Developer"
email = 'joe@example.net' email = "joe@example.net"
os.environ['DEBEMAIL'] = orig = '%s <%s>' % (name, email) os.environ["DEBEMAIL"] = orig = "%s <%s>" % (name, email)
self.assertEqual(ubu_email(), (name, email)) self.assertEqual(ubu_email(), (name, email))
self.assertEqual(os.environ['DEBEMAIL'], orig) self.assertEqual(os.environ["DEBEMAIL"], orig)
def test_unicode_name(self): def test_unicode_name(self):
encoding = locale.getdefaultlocale()[1] encoding = locale.getdefaultlocale()[1]
if not encoding: if not encoding:
encoding = 'utf-8' encoding = "utf-8"
name = 'Jöe Déveloper' name = "Jöe Déveloper"
env_name = name env_name = name
if isinstance(name, bytes): if isinstance(name, bytes):
name = 'Jöe Déveloper'.decode('utf-8') name = "Jöe Déveloper".decode("utf-8")
env_name = name.encode(encoding) env_name = name.encode(encoding)
try: try:
os.environ['DEBFULLNAME'] = env_name os.environ["DEBFULLNAME"] = env_name
except UnicodeEncodeError: except UnicodeEncodeError:
raise unittest.SkipTest("python interpreter is not running in an " raise unittest.SkipTest(
"unicode capable locale") "python interpreter is not running in an unicode capable locale"
os.environ['DEBEMAIL'] = email = 'joe@example.net' )
os.environ["DEBEMAIL"] = email = "joe@example.net"
self.assertEqual(ubu_email(), (name, email)) self.assertEqual(ubu_email(), (name, email))

View File

@ -27,10 +27,12 @@ class HelpTestCase(unittest.TestCase):
def test_script(self): def test_script(self):
for script in scripts: for script in scripts:
with self.subTest(script=script): with self.subTest(script=script):
result = subprocess.run([f'./{script}', '--help'], result = subprocess.run(
encoding='UTF-8', [f"./{script}", "--help"],
timeout=10, encoding="UTF-8",
check=True, timeout=10,
stdout=subprocess.PIPE, check=True,
stderr=subprocess.PIPE) stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
self.assertFalse(result.stderr.strip()) self.assertFalse(result.stderr.strip())

View File

@ -17,7 +17,6 @@
"""Test suite for ubuntutools.update_maintainer""" """Test suite for ubuntutools.update_maintainer"""
import os import os
# import sys
import unittest import unittest
from io import StringIO from io import StringIO
@ -200,24 +199,23 @@ class UpdateMaintainerTestCase(unittest.TestCase):
"""TestCase object for ubuntutools.update_maintainer""" """TestCase object for ubuntutools.update_maintainer"""
_directory = "/" _directory = "/"
_files = { _files = {"changelog": None, "control": None, "control.in": None, "rules": None}
"changelog": None,
"control": None,
"control.in": None,
"rules": None,
}
def _fake_isfile(self, filename): def _fake_isfile(self, filename):
"""Check only for existing fake files.""" """Check only for existing fake files."""
directory, base = os.path.split(filename) directory, base = os.path.split(filename)
return (directory == self._directory and base in self._files and return (
self._files[base] is not None) directory == self._directory and base in self._files and self._files[base] is not None
)
def _fake_open(self, filename, mode='r'): def _fake_open(self, filename, mode="r"):
"""Provide StringIO objects instead of real files.""" """Provide StringIO objects instead of real files."""
directory, base = os.path.split(filename) directory, base = os.path.split(filename)
if (directory != self._directory or base not in self._files or if (
(mode == "r" and self._files[base] is None)): directory != self._directory
or base not in self._files
or (mode == "r" and self._files[base] is None)
):
raise IOError("No such file or directory: '%s'" % filename) raise IOError("No such file or directory: '%s'" % filename)
if mode == "w": if mode == "w":
self._files[base] = StringIO() self._files[base] = StringIO()
@ -228,11 +226,11 @@ class UpdateMaintainerTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
m = mock.mock_open() m = mock.mock_open()
m.side_effect = self._fake_open m.side_effect = self._fake_open
patcher = mock.patch('builtins.open', m) patcher = mock.patch("builtins.open", m)
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
patcher.start() patcher.start()
m = mock.MagicMock(side_effect=self._fake_isfile) m = mock.MagicMock(side_effect=self._fake_isfile)
patcher = mock.patch('os.path.isfile', m) patcher = mock.patch("os.path.isfile", m)
self.addCleanup(patcher.stop) self.addCleanup(patcher.stop)
patcher.start() patcher.start()
self._files["rules"] = StringIO(_SIMPLE_RULES) self._files["rules"] = StringIO(_SIMPLE_RULES)
@ -260,8 +258,8 @@ class UpdateMaintainerTestCase(unittest.TestCase):
def test_original_ubuntu_maintainer(self): def test_original_ubuntu_maintainer(self):
"""Test: Original maintainer is Ubuntu developer. """Test: Original maintainer is Ubuntu developer.
The Maintainer field needs to be update even if The Maintainer field needs to be update even if
XSBC-Original-Maintainer has an @ubuntu.com address.""" XSBC-Original-Maintainer has an @ubuntu.com address."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG) self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_AXIS2C_CONTROL) self._files["control"] = StringIO(_AXIS2C_CONTROL)
update_maintainer(self._directory) update_maintainer(self._directory)
@ -288,12 +286,11 @@ class UpdateMaintainerTestCase(unittest.TestCase):
def test_comments_in_control(self): def test_comments_in_control(self):
"""Test: Update Maintainer field in a control file containing """Test: Update Maintainer field in a control file containing
comments.""" comments."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG) self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_SEAHORSE_PLUGINS_CONTROL) self._files["control"] = StringIO(_SEAHORSE_PLUGINS_CONTROL)
update_maintainer(self._directory) update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), self.assertEqual(self._files["control"].getvalue(), _SEAHORSE_PLUGINS_UPDATED)
_SEAHORSE_PLUGINS_UPDATED)
def test_skip_smart_rules(self): def test_skip_smart_rules(self):
"""Test: Skip update when XSBC-Original in debian/rules.""" """Test: Skip update when XSBC-Original in debian/rules."""

View File

@ -22,6 +22,7 @@ import re
import debian.changelog import debian.changelog
import logging import logging
Logger = logging.getLogger(__name__) Logger = logging.getLogger(__name__)
# Prior May 2009 these Maintainers were used: # Prior May 2009 these Maintainers were used:
@ -47,16 +48,16 @@ class Control(object):
def get_maintainer(self): def get_maintainer(self):
"""Returns the value of the Maintainer field.""" """Returns the value of the Maintainer field."""
maintainer = re.search("^Maintainer: ?(.*)$", self._content, maintainer = re.search("^Maintainer: ?(.*)$", self._content, re.MULTILINE)
re.MULTILINE)
if maintainer: if maintainer:
maintainer = maintainer.group(1) maintainer = maintainer.group(1)
return maintainer return maintainer
def get_original_maintainer(self): def get_original_maintainer(self):
"""Returns the value of the XSBC-Original-Maintainer field.""" """Returns the value of the XSBC-Original-Maintainer field."""
orig_maintainer = re.search("^(?:[XSBC]*-)?Original-Maintainer: ?(.*)$", orig_maintainer = re.search(
self._content, re.MULTILINE) "^(?:[XSBC]*-)?Original-Maintainer: ?(.*)$", self._content, re.MULTILINE
)
if orig_maintainer: if orig_maintainer:
orig_maintainer = orig_maintainer.group(1) orig_maintainer = orig_maintainer.group(1)
return orig_maintainer return orig_maintainer
@ -78,25 +79,23 @@ class Control(object):
"""Sets the value of the XSBC-Original-Maintainer field.""" """Sets the value of the XSBC-Original-Maintainer field."""
original_maintainer = "XSBC-Original-Maintainer: " + original_maintainer original_maintainer = "XSBC-Original-Maintainer: " + original_maintainer
if self.get_original_maintainer(): if self.get_original_maintainer():
pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*$", pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*$", re.MULTILINE)
re.MULTILINE)
self._content = pattern.sub(original_maintainer, self._content) self._content = pattern.sub(original_maintainer, self._content)
else: else:
pattern = re.compile("^(Maintainer:.*)$", re.MULTILINE) pattern = re.compile("^(Maintainer:.*)$", re.MULTILINE)
self._content = pattern.sub(r"\1\n" + original_maintainer, self._content = pattern.sub(r"\1\n" + original_maintainer, self._content)
self._content)
def remove_original_maintainer(self): def remove_original_maintainer(self):
"""Strip out out the XSBC-Original-Maintainer line""" """Strip out out the XSBC-Original-Maintainer line"""
pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^", pattern = re.compile(
re.MULTILINE | re.DOTALL) "^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^", re.MULTILINE | re.DOTALL
self._content = pattern.sub('', self._content) )
self._content = pattern.sub("", self._content)
def _get_distribution(changelog_file): def _get_distribution(changelog_file):
"""get distribution of latest changelog entry""" """get distribution of latest changelog entry"""
changelog = debian.changelog.Changelog(open(changelog_file), strict=False, changelog = debian.changelog.Changelog(open(changelog_file), strict=False, max_blocks=1)
max_blocks=1)
distribution = changelog.distributions.split()[0] distribution = changelog.distributions.split()[0]
# Strip things like "-proposed-updates" or "-security" from distribution # Strip things like "-proposed-updates" or "-security" from distribution
return distribution.split("-", 1)[0] return distribution.split("-", 1)[0]
@ -107,25 +106,21 @@ def _find_files(debian_directory, verbose):
Returns (changelog, control files list) Returns (changelog, control files list)
Raises an exception if none can be found. Raises an exception if none can be found.
""" """
possible_contol_files = [os.path.join(debian_directory, f) for possible_contol_files = [os.path.join(debian_directory, f) for f in ["control.in", "control"]]
f in ["control.in", "control"]]
changelog_file = os.path.join(debian_directory, "changelog") changelog_file = os.path.join(debian_directory, "changelog")
control_files = [f for f in possible_contol_files if os.path.isfile(f)] control_files = [f for f in possible_contol_files if os.path.isfile(f)]
# Make sure that a changelog and control file is available # Make sure that a changelog and control file is available
if len(control_files) == 0: if len(control_files) == 0:
raise MaintainerUpdateException( raise MaintainerUpdateException("No control file found in %s." % debian_directory)
"No control file found in %s." % debian_directory)
if not os.path.isfile(changelog_file): if not os.path.isfile(changelog_file):
raise MaintainerUpdateException( raise MaintainerUpdateException("No changelog file found in %s." % debian_directory)
"No changelog file found in %s." % debian_directory)
# If the rules file accounts for XSBC-Original-Maintainer, we should not # If the rules file accounts for XSBC-Original-Maintainer, we should not
# touch it in this package (e.g. the python package). # touch it in this package (e.g. the python package).
rules_file = os.path.join(debian_directory, "rules") rules_file = os.path.join(debian_directory, "rules")
if os.path.isfile(rules_file) and \ if os.path.isfile(rules_file) and "XSBC-Original-" in open(rules_file).read():
'XSBC-Original-' in open(rules_file).read():
if verbose: if verbose:
print("XSBC-Original is managed by 'rules' file. Doing nothing.") print("XSBC-Original is managed by 'rules' file. Doing nothing.")
control_files = [] control_files = []
@ -178,8 +173,9 @@ def update_maintainer(debian_directory, verbose=False):
return return
if control.get_original_maintainer() is not None: if control.get_original_maintainer() is not None:
Logger.warning("Overwriting original maintainer: %s", Logger.warning(
control.get_original_maintainer()) "Overwriting original maintainer: %s", control.get_original_maintainer()
)
if verbose: if verbose:
print("The original maintainer is: %s" % original_maintainer) print("The original maintainer is: %s" % original_maintainer)

View File

@ -17,28 +17,28 @@ import debian.debian_support
class Version(debian.debian_support.Version): class Version(debian.debian_support.Version):
def strip_epoch(self): def strip_epoch(self):
'''Removes the epoch from a Debian version string. """Removes the epoch from a Debian version string.
strip_epoch(1:1.52-1) will return "1.52-1" and strip_epoch(1.1.3-1) strip_epoch(1:1.52-1) will return "1.52-1" and strip_epoch(1.1.3-1)
will return "1.1.3-1". will return "1.1.3-1".
''' """
parts = self.full_version.split(':') parts = self.full_version.split(":")
if len(parts) > 1: if len(parts) > 1:
del parts[0] del parts[0]
version_without_epoch = ':'.join(parts) version_without_epoch = ":".join(parts)
return version_without_epoch return version_without_epoch
def get_related_debian_version(self): def get_related_debian_version(self):
'''Strip the ubuntu-specific bits off the version''' """Strip the ubuntu-specific bits off the version"""
related_debian_version = self.full_version related_debian_version = self.full_version
uidx = related_debian_version.find('ubuntu') uidx = related_debian_version.find("ubuntu")
if uidx > 0: if uidx > 0:
related_debian_version = related_debian_version[:uidx] related_debian_version = related_debian_version[:uidx]
uidx = related_debian_version.find('build') uidx = related_debian_version.find("build")
if uidx > 0: if uidx > 0:
related_debian_version = related_debian_version[:uidx] related_debian_version = related_debian_version[:uidx]
return Version(related_debian_version) return Version(related_debian_version)
def is_modified_in_ubuntu(self): def is_modified_in_ubuntu(self):
'''Did Ubuntu modify this (and mark the version appropriately)?''' """Did Ubuntu modify this (and mark the version appropriately)?"""
return 'ubuntu' in self.full_version return "ubuntu" in self.full_version

View File

@ -18,9 +18,11 @@ import optparse
import os import os
import sys import sys
from ubuntutools.update_maintainer import (update_maintainer, from ubuntutools.update_maintainer import (
restore_maintainer, update_maintainer,
MaintainerUpdateException) restore_maintainer,
MaintainerUpdateException,
)
def find_debian_dir(depth=6): def find_debian_dir(depth=6):
@ -30,10 +32,11 @@ def find_debian_dir(depth=6):
:rtype: str :rtype: str
:returns: a path to an existing debian/ directory, or None :returns: a path to an existing debian/ directory, or None
""" """
for path in ['../'*n or './' for n in list(range(0, depth+1))]: for path in ["../" * n or "./" for n in list(range(0, depth + 1))]:
debian_path = '{}debian'.format(path) debian_path = "{}debian".format(path)
if os.path.exists(os.path.join(debian_path, 'control')) \ if os.path.exists(os.path.join(debian_path, "control")) and os.path.exists(
and os.path.exists(os.path.join(debian_path, 'changelog')): os.path.join(debian_path, "changelog")
):
return debian_path return debian_path
return None return None
@ -43,20 +46,37 @@ def main():
usage = "%s [options]" % (script_name) usage = "%s [options]" % (script_name)
epilog = "See %s(1) for more info." % (script_name) epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog) parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-d", "--debian-directory", dest="debian_directory", parser.add_option(
help="location of the 'debian' directory (default: " "-d",
"%default).", metavar="PATH", "--debian-directory",
default=find_debian_dir() or './debian') dest="debian_directory",
parser.add_option("-r", "--restore", help="location of the 'debian' directory (default: %default).",
help="Restore the original maintainer", metavar="PATH",
action='store_true', default=False) default=find_debian_dir() or "./debian",
parser.add_option("-q", "--quiet", help="print no informational messages", )
dest="quiet", action="store_true", default=False) parser.add_option(
"-r",
"--restore",
help="Restore the original maintainer",
action="store_true",
default=False,
)
parser.add_option(
"-q",
"--quiet",
help="print no informational messages",
dest="quiet",
action="store_true",
default=False,
)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) != 0: if len(args) != 0:
print("%s: Error: Unsupported additional parameters specified: %s" print(
% (script_name, ", ".join(args)), file=sys.stderr) "%s: Error: Unsupported additional parameters specified: %s"
% (script_name, ", ".join(args)),
file=sys.stderr,
)
sys.exit(1) sys.exit(1)
if not options.restore: if not options.restore: