mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-12-08 08:33:29 +00:00
syncpackage: replace global by LRU cache
pylint complains: ``` syncpackage:459:4: W0603: Using the global statement (global-statement) ``` Replace the `global` statement by `functools.lru_cache`.
This commit is contained in:
parent
c8fe724560
commit
2e041ac1ff
18
syncpackage
18
syncpackage
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@ -49,7 +50,6 @@ from ubuntutools.requestsync.mail import get_debian_srcpkg as requestsync_mail_g
|
|||||||
from ubuntutools.version import Version
|
from ubuntutools.version import Version
|
||||||
|
|
||||||
Logger = getLogger()
|
Logger = getLogger()
|
||||||
cached_sync_blocklist = None
|
|
||||||
|
|
||||||
|
|
||||||
def remove_signature(dscname):
|
def remove_signature(dscname):
|
||||||
@ -436,6 +436,14 @@ def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False, ye
|
|||||||
close_bugs(bugs, src_pkg.source, src_pkg.version.full_version, changes, sponsoree)
|
close_bugs(bugs, src_pkg.source, src_pkg.version.full_version, changes, sponsoree)
|
||||||
|
|
||||||
|
|
||||||
|
@functools.lru_cache(maxsize=1)
|
||||||
|
def _fetch_sync_blocklist() -> str:
|
||||||
|
url = "https://ubuntu-archive-team.ubuntu.com/sync-blocklist.txt"
|
||||||
|
with urllib.request.urlopen(url) as f:
|
||||||
|
sync_blocklist = f.read().decode("utf-8")
|
||||||
|
return sync_blocklist
|
||||||
|
|
||||||
|
|
||||||
def is_blocklisted(query):
|
def is_blocklisted(query):
|
||||||
"""Determine if package "query" is in the sync blocklist
|
"""Determine if package "query" is in the sync blocklist
|
||||||
Returns tuple of (blocklisted, comments)
|
Returns tuple of (blocklisted, comments)
|
||||||
@ -456,18 +464,14 @@ def is_blocklisted(query):
|
|||||||
if diff.status == "Blacklisted always":
|
if diff.status == "Blacklisted always":
|
||||||
blocklisted = "ALWAYS"
|
blocklisted = "ALWAYS"
|
||||||
|
|
||||||
global cached_sync_blocklist
|
|
||||||
if not cached_sync_blocklist:
|
|
||||||
url = "https://ubuntu-archive-team.ubuntu.com/sync-blocklist.txt"
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(url) as f:
|
sync_blocklist = _fetch_sync_blocklist()
|
||||||
cached_sync_blocklist = f.read().decode("utf-8")
|
|
||||||
except OSError:
|
except OSError:
|
||||||
print("WARNING: unable to download the sync blocklist. Erring on the side of caution.")
|
print("WARNING: unable to download the sync blocklist. Erring on the side of caution.")
|
||||||
return ("ALWAYS", "INTERNAL ERROR: Unable to fetch sync blocklist")
|
return ("ALWAYS", "INTERNAL ERROR: Unable to fetch sync blocklist")
|
||||||
|
|
||||||
applicable_lines = []
|
applicable_lines = []
|
||||||
for line in cached_sync_blocklist.splitlines():
|
for line in sync_blocklist.splitlines():
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
applicable_lines = []
|
applicable_lines = []
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user