mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-10 16:31:28 +00:00
Use Python f-strings
``` flynt -ll 99 -tc -tj -a pbuilder-dist pm-helper running-autopkgtests ubuntu-build ubuntutools ```
This commit is contained in:
parent
c7a855ff20
commit
d7362d9ed8
22
pm-helper
22
pm-helper
@ -37,24 +37,24 @@ def get_proposed_version(excuses, package):
|
|||||||
|
|
||||||
|
|
||||||
def claim_excuses_bug(launchpad, bug, package):
|
def claim_excuses_bug(launchpad, bug, package):
|
||||||
print("LP: #%d: %s" % (bug.id, bug.title))
|
print(f"LP: #{bug.id}: {bug.title}")
|
||||||
ubuntu = launchpad.distributions["ubuntu"]
|
ubuntu = launchpad.distributions["ubuntu"]
|
||||||
series = ubuntu.current_series.fullseriesname
|
series = ubuntu.current_series.fullseriesname
|
||||||
|
|
||||||
for task in bug.bug_tasks:
|
for task in bug.bug_tasks:
|
||||||
# targeting to a series doesn't make the default task disappear,
|
# targeting to a series doesn't make the default task disappear,
|
||||||
# it just makes it useless
|
# it just makes it useless
|
||||||
if task.bug_target_name == "%s (%s)" % (package, series):
|
if task.bug_target_name == f"{package} ({series})":
|
||||||
our_task = task
|
our_task = task
|
||||||
break
|
break
|
||||||
elif task.bug_target_name == "%s (Ubuntu)" % package:
|
elif task.bug_target_name == f"{package} (Ubuntu)":
|
||||||
our_task = task
|
our_task = task
|
||||||
|
|
||||||
if our_task.assignee == launchpad.me:
|
if our_task.assignee == launchpad.me:
|
||||||
print("Bug already assigned to you.")
|
print("Bug already assigned to you.")
|
||||||
return True
|
return True
|
||||||
elif our_task.assignee:
|
elif our_task.assignee:
|
||||||
print("Currently assigned to %s" % our_task.assignee.name)
|
print(f"Currently assigned to {our_task.assignee.name}")
|
||||||
|
|
||||||
print("""Do you want to claim this bug? [yN] """, end="")
|
print("""Do you want to claim this bug? [yN] """, end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@ -70,17 +70,17 @@ def claim_excuses_bug(launchpad, bug, package):
|
|||||||
def create_excuses_bug(launchpad, package, version):
|
def create_excuses_bug(launchpad, package, version):
|
||||||
print("Will open a new bug")
|
print("Will open a new bug")
|
||||||
bug = launchpad.bugs.createBug(
|
bug = launchpad.bugs.createBug(
|
||||||
title="proposed-migration for %s %s" % (package, version),
|
title=f"proposed-migration for {package} {version}",
|
||||||
tags=("update-excuse"),
|
tags=("update-excuse"),
|
||||||
target="https://api.launchpad.net/devel/ubuntu/+source/%s" % package,
|
target=f"https://api.launchpad.net/devel/ubuntu/+source/{package}",
|
||||||
description="%s %s is stuck in -proposed." % (package, version),
|
description=f"{package} {version} is stuck in -proposed.",
|
||||||
)
|
)
|
||||||
|
|
||||||
task = bug.bug_tasks[0]
|
task = bug.bug_tasks[0]
|
||||||
task.assignee = launchpad.me
|
task.assignee = launchpad.me
|
||||||
task.lp_save()
|
task.lp_save()
|
||||||
|
|
||||||
print("Opening %s in browser" % bug.web_link)
|
print(f"Opening {bug.web_link} in browser")
|
||||||
webbrowser.open(bug.web_link)
|
webbrowser.open(bug.web_link)
|
||||||
return bug
|
return bug
|
||||||
|
|
||||||
@ -98,9 +98,9 @@ def has_excuses_bugs(launchpad, package):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if len(bugs) == 1:
|
if len(bugs) == 1:
|
||||||
print("There is 1 open update-excuse bug against %s" % package)
|
print(f"There is 1 open update-excuse bug against {package}")
|
||||||
else:
|
else:
|
||||||
print("There are %d open update-excuse bugs against %s" % (len(bugs), package))
|
print(f"There are {len(bugs)} open update-excuse bugs against {package}")
|
||||||
|
|
||||||
for bug in bugs:
|
for bug in bugs:
|
||||||
if claim_excuses_bug(launchpad, bug, package):
|
if claim_excuses_bug(launchpad, bug, package):
|
||||||
@ -129,7 +129,7 @@ def main():
|
|||||||
if not has_excuses_bugs(args.launchpad, args.package):
|
if not has_excuses_bugs(args.launchpad, args.package):
|
||||||
proposed_version = get_proposed_version(excuses, args.package)
|
proposed_version = get_proposed_version(excuses, args.package)
|
||||||
if not proposed_version:
|
if not proposed_version:
|
||||||
print("Package %s not found in -proposed." % args.package)
|
print(f"Package {args.package} not found in -proposed.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
create_excuses_bug(args.launchpad, args.package, proposed_version)
|
create_excuses_bug(args.launchpad, args.package, proposed_version)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -163,7 +163,7 @@ def main():
|
|||||||
# but for the main archive we default to -proposed
|
# but for the main archive we default to -proposed
|
||||||
release = ubuntu.getDevelopmentSeries()[0].name
|
release = ubuntu.getDevelopmentSeries()[0].name
|
||||||
if args.archive == "ubuntu":
|
if args.archive == "ubuntu":
|
||||||
release = release + "-proposed"
|
release = f"{release}-proposed"
|
||||||
try:
|
try:
|
||||||
(release, pocket) = split_release_pocket(release)
|
(release, pocket) = split_release_pocket(release)
|
||||||
except PocketDoesNotExistError as error:
|
except PocketDoesNotExistError as error:
|
||||||
|
@ -543,7 +543,7 @@ class SourcePackage(ABC):
|
|||||||
Return the debdiff filename.
|
Return the debdiff filename.
|
||||||
"""
|
"""
|
||||||
cmd = ["debdiff", self.dsc_name, newpkg.dsc_name]
|
cmd = ["debdiff", self.dsc_name, newpkg.dsc_name]
|
||||||
difffn = newpkg.dsc_name[:-3] + "debdiff"
|
difffn = f"{newpkg.dsc_name[:-3]}debdiff"
|
||||||
Logger.debug("%s > %s", " ".join(cmd), difffn)
|
Logger.debug("%s > %s", " ".join(cmd), difffn)
|
||||||
with open(difffn, "w", encoding="utf-8") as f:
|
with open(difffn, "w", encoding="utf-8") as f:
|
||||||
if subprocess.call(cmd, stdout=f, cwd=str(self.workdir)) > 2:
|
if subprocess.call(cmd, stdout=f, cwd=str(self.workdir)) > 2:
|
||||||
@ -1342,7 +1342,7 @@ class SnapshotSPPH:
|
|||||||
self.getComponent(),
|
self.getComponent(),
|
||||||
subdir,
|
subdir,
|
||||||
name,
|
name,
|
||||||
name + "_" + pkgversion,
|
f"{name}_{pkgversion}",
|
||||||
"changelog.txt",
|
"changelog.txt",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
@ -71,8 +71,8 @@ class Pbuilder(Builder):
|
|||||||
cmd = [
|
cmd = [
|
||||||
"sudo",
|
"sudo",
|
||||||
"-E",
|
"-E",
|
||||||
"ARCH=" + self.architecture,
|
f"ARCH={self.architecture}",
|
||||||
"DIST=" + dist,
|
f"DIST={dist}",
|
||||||
self.name,
|
self.name,
|
||||||
"--build",
|
"--build",
|
||||||
"--architecture",
|
"--architecture",
|
||||||
@ -91,8 +91,8 @@ class Pbuilder(Builder):
|
|||||||
cmd = [
|
cmd = [
|
||||||
"sudo",
|
"sudo",
|
||||||
"-E",
|
"-E",
|
||||||
"ARCH=" + self.architecture,
|
f"ARCH={self.architecture}",
|
||||||
"DIST=" + dist,
|
f"DIST={dist}",
|
||||||
self.name,
|
self.name,
|
||||||
"--update",
|
"--update",
|
||||||
"--architecture",
|
"--architecture",
|
||||||
@ -140,7 +140,7 @@ class Sbuild(Builder):
|
|||||||
workdir = os.getcwd()
|
workdir = os.getcwd()
|
||||||
Logger.debug("cd %s", result_directory)
|
Logger.debug("cd %s", result_directory)
|
||||||
os.chdir(result_directory)
|
os.chdir(result_directory)
|
||||||
cmd = ["sbuild", "--arch-all", "--dist=" + dist, "--arch=" + self.architecture, dsc_file]
|
cmd = ["sbuild", "--arch-all", f"--dist={dist}", f"--arch={self.architecture}", dsc_file]
|
||||||
Logger.debug(" ".join(cmd))
|
Logger.debug(" ".join(cmd))
|
||||||
returncode = subprocess.call(cmd)
|
returncode = subprocess.call(cmd)
|
||||||
Logger.debug("cd %s", workdir)
|
Logger.debug("cd %s", workdir)
|
||||||
|
@ -99,9 +99,9 @@ class UDTConfig:
|
|||||||
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 = [f"{self.prefix}_{key}"]
|
||||||
if key in self.defaults:
|
if key in self.defaults:
|
||||||
keys.append("UBUNTUTOOLS_" + key)
|
keys.append(f"UBUNTUTOOLS_{key}")
|
||||||
keys += compat_keys
|
keys += compat_keys
|
||||||
|
|
||||||
for k in keys:
|
for k in keys:
|
||||||
@ -114,9 +114,9 @@ class UDTConfig:
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if k in compat_keys:
|
if k in compat_keys:
|
||||||
replacements = self.prefix + "_" + key
|
replacements = f"{self.prefix}_{key}"
|
||||||
if key in self.defaults:
|
if key in self.defaults:
|
||||||
replacements += "or UBUNTUTOOLS_" + key
|
replacements += f"or UBUNTUTOOLS_{key}"
|
||||||
Logger.warning(
|
Logger.warning(
|
||||||
"Using deprecated configuration variable %s. You should use %s.",
|
"Using deprecated configuration variable %s. You should use %s.",
|
||||||
k,
|
k,
|
||||||
@ -180,7 +180,7 @@ def ubu_email(name=None, email=None, export=True):
|
|||||||
mailname = socket.getfqdn()
|
mailname = socket.getfqdn()
|
||||||
if os.path.isfile("/etc/mailname"):
|
if os.path.isfile("/etc/mailname"):
|
||||||
mailname = open("/etc/mailname", "r", encoding="utf-8").read().strip()
|
mailname = open("/etc/mailname", "r", encoding="utf-8").read().strip()
|
||||||
email = pwd.getpwuid(os.getuid()).pw_name + "@" + mailname
|
email = f"{pwd.getpwuid(os.getuid()).pw_name}@{mailname}"
|
||||||
|
|
||||||
if export:
|
if export:
|
||||||
os.environ["DEBFULLNAME"] = name
|
os.environ["DEBFULLNAME"] = name
|
||||||
|
@ -883,7 +883,7 @@ class SourcePackagePublishingHistory(BaseWrapper):
|
|||||||
"""
|
"""
|
||||||
release = self.getSeriesName()
|
release = self.getSeriesName()
|
||||||
if self.pocket != "Release":
|
if self.pocket != "Release":
|
||||||
release += "-" + self.pocket.lower()
|
release += f"-{self.pocket.lower()}"
|
||||||
return release
|
return release
|
||||||
|
|
||||||
def getArchive(self):
|
def getArchive(self):
|
||||||
|
@ -385,7 +385,7 @@ class _StderrProgressBar:
|
|||||||
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 = f"{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)
|
||||||
|
@ -31,9 +31,9 @@ class Question:
|
|||||||
|
|
||||||
def get_options(self):
|
def get_options(self):
|
||||||
if len(self.options) == 2:
|
if len(self.options) == 2:
|
||||||
options = self.options[0] + " or " + self.options[1]
|
options = f"{self.options[0]} or {self.options[1]}"
|
||||||
else:
|
else:
|
||||||
options = ", ".join(self.options[:-1]) + ", or " + self.options[-1]
|
options = f"{', '.join(self.options[:-1])}, or {self.options[-1]}"
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def ask(self, question, default=None):
|
def ask(self, question, default=None):
|
||||||
@ -67,7 +67,7 @@ class Question:
|
|||||||
if selected == option[0]:
|
if selected == option[0]:
|
||||||
selected = option
|
selected = option
|
||||||
if selected not in self.options:
|
if selected not in self.options:
|
||||||
print("Please answer the question with " + self.get_options() + ".")
|
print(f"Please answer the question with {self.get_options()}.")
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ class EditBugReport(EditFile):
|
|||||||
split_re = re.compile(r"^Summary.*?:\s+(.*?)\s+Description:\s+(.*)$", re.DOTALL | re.UNICODE)
|
split_re = re.compile(r"^Summary.*?:\s+(.*?)\s+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 = f"{os.path.basename(sys.argv[0])}_"
|
||||||
tmpfile = tempfile.NamedTemporaryFile(prefix=prefix, suffix=".txt", delete=False)
|
tmpfile = tempfile.NamedTemporaryFile(prefix=prefix, suffix=".txt", delete=False)
|
||||||
tmpfile.write((f"Summary (one line):\n{subject}\n\nDescription:\n{body}").encode("utf-8"))
|
tmpfile.write((f"Summary (one line):\n{subject}\n\nDescription:\n{body}").encode("utf-8"))
|
||||||
tmpfile.close()
|
tmpfile.close()
|
||||||
|
@ -183,7 +183,7 @@ Content-Type: text/plain; charset=UTF-8
|
|||||||
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=f"requestsync-{re.sub('[^a-zA-Z0-9_-]', '', bugtitle.replace(' ', '_'))}",
|
||||||
)
|
)
|
||||||
with backup:
|
with backup:
|
||||||
backup.write(mail)
|
backup.write(mail)
|
||||||
|
@ -255,7 +255,7 @@ class SourcePackage:
|
|||||||
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(
|
return os.path.join(
|
||||||
self._workdir, f"{self._package}_{ strip_epoch(self._version)}_source.changes"
|
self._workdir, f"{self._package}_{strip_epoch(self._version)}_source.changes"
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_target(self, upload, launchpad):
|
def check_target(self, upload, launchpad):
|
||||||
|
@ -39,7 +39,7 @@ 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" for directory in path if directory.endswith("/bin")]
|
path += [f"{directory[:-3]}sbin" 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)
|
||||||
|
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ 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 = f"{task.package}-{task.get_version().upstream_version}"
|
||||||
Logger.debug("cd %s", directory)
|
Logger.debug("cd %s", directory)
|
||||||
os.chdir(directory)
|
os.chdir(directory)
|
||||||
|
|
||||||
|
@ -72,17 +72,17 @@ class Control:
|
|||||||
def set_maintainer(self, maintainer):
|
def set_maintainer(self, maintainer):
|
||||||
"""Sets the value of the Maintainer field."""
|
"""Sets the value of the Maintainer field."""
|
||||||
pattern = re.compile("^Maintainer: ?.*$", re.MULTILINE)
|
pattern = re.compile("^Maintainer: ?.*$", re.MULTILINE)
|
||||||
self._content = pattern.sub("Maintainer: " + maintainer, self._content)
|
self._content = pattern.sub(f"Maintainer: {maintainer}", self._content)
|
||||||
|
|
||||||
def set_original_maintainer(self, original_maintainer):
|
def set_original_maintainer(self, original_maintainer):
|
||||||
"""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 = f"XSBC-Original-Maintainer: {original_maintainer}"
|
||||||
if self.get_original_maintainer():
|
if self.get_original_maintainer():
|
||||||
pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*$", re.MULTILINE)
|
pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*$", 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)
|
self._content = pattern.sub(f"\\1\\n{original_maintainer}", 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"""
|
||||||
|
@ -40,7 +40,7 @@ def get_url(url, force_cached):
|
|||||||
m = re.search("ubuntu-archive-team.ubuntu.com/proposed-migration/([^/]*)/([^/]*)", url)
|
m = re.search("ubuntu-archive-team.ubuntu.com/proposed-migration/([^/]*)/([^/]*)", url)
|
||||||
if m:
|
if m:
|
||||||
cache_dir = get_cache_dir()
|
cache_dir = get_cache_dir()
|
||||||
cache_file = os.path.join(cache_dir, "%s_%s" % (m.group(1), m.group(2)))
|
cache_file = os.path.join(cache_dir, f"{m.group(1)}_{m.group(2)}")
|
||||||
else:
|
else:
|
||||||
# test logs can be cached, too
|
# test logs can be cached, too
|
||||||
m = re.search(
|
m = re.search(
|
||||||
@ -51,7 +51,7 @@ def get_url(url, force_cached):
|
|||||||
if m:
|
if m:
|
||||||
cache_dir = get_cache_dir()
|
cache_dir = get_cache_dir()
|
||||||
cache_file = os.path.join(
|
cache_file = os.path.join(
|
||||||
cache_dir, "%s_%s_%s_%s.gz" % (m.group(1), m.group(2), m.group(3), m.group(4))
|
cache_dir, f"{m.group(1)}_{m.group(2)}_{m.group(3)}_{m.group(4)}.gz"
|
||||||
)
|
)
|
||||||
|
|
||||||
if cache_file:
|
if cache_file:
|
||||||
@ -69,10 +69,10 @@ def get_url(url, force_cached):
|
|||||||
if cache_file:
|
if cache_file:
|
||||||
remote_ts = dateutil.parser.parse(f.headers["last-modified"])
|
remote_ts = dateutil.parser.parse(f.headers["last-modified"])
|
||||||
if remote_ts > prev_timestamp:
|
if remote_ts > prev_timestamp:
|
||||||
with open("%s.new" % cache_file, "wb") as new_cache:
|
with open(f"{cache_file}.new", "wb") as new_cache:
|
||||||
for line in f:
|
for line in f:
|
||||||
new_cache.write(line)
|
new_cache.write(line)
|
||||||
os.rename("%s.new" % cache_file, cache_file)
|
os.rename(f"{cache_file}.new", cache_file)
|
||||||
os.utime(cache_file, times=(new_timestamp, new_timestamp))
|
os.utime(cache_file, times=(new_timestamp, new_timestamp))
|
||||||
f.close()
|
f.close()
|
||||||
f = open(cache_file, "rb")
|
f = open(cache_file, "rb")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user