mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 15:41:09 +00:00
pylint complains about W1201: Use lazy % formatting in logging functions (logging-not-lazy) and W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation). Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
206 lines
5.6 KiB
Python
Executable File
206 lines
5.6 KiB
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# Copyright (C) 2010-2011, Benjamin Drung <bdrung@ubuntu.com>
|
|
#
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# copyright notice and this permission notice appear in all copies.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
# pylint: disable=invalid-name
|
|
# pylint: enable=invalid-name
|
|
|
|
import logging
|
|
import optparse
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
|
|
from ubuntutools import getLogger
|
|
from ubuntutools.builder import get_builder
|
|
from ubuntutools.config import UDTConfig
|
|
from ubuntutools.sponsor_patch.sponsor_patch import check_dependencies, sponsor_patch
|
|
|
|
Logger = getLogger()
|
|
|
|
|
|
def parse(script_name):
|
|
"""Parse the command line parameters."""
|
|
usage = (
|
|
"%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)
|
|
parser = optparse.OptionParser(usage=usage, epilog=epilog)
|
|
|
|
parser.add_option(
|
|
"-b",
|
|
"--build",
|
|
dest="build",
|
|
help="Build the package with the specified builder.",
|
|
action="store_true",
|
|
default=False,
|
|
)
|
|
parser.add_option(
|
|
"-B",
|
|
"--builder",
|
|
dest="builder",
|
|
default=None,
|
|
help="Specify the package builder (default pbuilder)",
|
|
)
|
|
parser.add_option(
|
|
"-e",
|
|
"--edit",
|
|
help="launch sub-shell to allow editing of the patch",
|
|
dest="edit",
|
|
action="store_true",
|
|
default=False,
|
|
)
|
|
parser.add_option(
|
|
"-k",
|
|
"--key",
|
|
dest="keyid",
|
|
default=None,
|
|
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()
|
|
if options.verbose:
|
|
Logger.setLevel(logging.DEBUG)
|
|
check_dependencies()
|
|
|
|
if len(args) == 0:
|
|
Logger.error("No bug number specified.")
|
|
sys.exit(1)
|
|
elif len(args) > 1:
|
|
Logger.error("Multiple bug numbers specified: %s", ", ".join(args))
|
|
sys.exit(1)
|
|
|
|
bug_number = args[0]
|
|
if bug_number.isdigit():
|
|
bug_number = int(bug_number)
|
|
else:
|
|
Logger.error("Invalid bug number specified: %s", bug_number)
|
|
sys.exit(1)
|
|
|
|
config = UDTConfig(options.no_conf)
|
|
if options.builder is None:
|
|
options.builder = config.get_value("BUILDER")
|
|
if options.lpinstance is None:
|
|
options.lpinstance = config.get_value("LPINSTANCE")
|
|
if not options.update:
|
|
options.update = config.get_value("UPDATE_BUILDER", boolean=True)
|
|
if options.workdir is None:
|
|
options.workdir = config.get_value("WORKDIR")
|
|
if options.keyid is None:
|
|
options.keyid = config.get_value("KEYID")
|
|
|
|
if options.sponsoring:
|
|
options.build = True
|
|
options.upload = "ubuntu"
|
|
|
|
return (options, bug_number)
|
|
|
|
|
|
def main():
|
|
script_name = os.path.basename(sys.argv[0])
|
|
(options, bug_number) = parse(script_name)
|
|
|
|
builder = get_builder(options.builder)
|
|
if not builder:
|
|
sys.exit(1)
|
|
|
|
if not options.upload and not options.workdir:
|
|
Logger.error("Please specify either a working directory or an upload target!")
|
|
sys.exit(1)
|
|
|
|
if options.workdir is None:
|
|
workdir = tempfile.mkdtemp(prefix=script_name + "-")
|
|
else:
|
|
workdir = options.workdir
|
|
|
|
try:
|
|
sponsor_patch(
|
|
bug_number,
|
|
options.build,
|
|
builder,
|
|
options.edit,
|
|
options.keyid,
|
|
options.lpinstance,
|
|
options.update,
|
|
options.upload,
|
|
workdir,
|
|
)
|
|
except KeyboardInterrupt:
|
|
Logger.error("User abort.")
|
|
sys.exit(2)
|
|
finally:
|
|
if options.workdir is None:
|
|
shutil.rmtree(workdir)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|