diff --git a/securedrop/upload-screenshots.py b/securedrop/upload-screenshots.py index d8baafecadb..72f0b31b5ad 100755 --- a/securedrop/upload-screenshots.py +++ b/securedrop/upload-screenshots.py @@ -24,7 +24,7 @@ # filename into the canonical title we give that screenshot in Weblate. # # Example conversion: "source-session_timeout.png" -> "source: session timeout" -CANONICALIZATION_RULES = [(r"\.png$", ""), (r"-", ": "), (r"_", " ")] +CANONICALIZATION_RULES = ((r"\.png$", ""), (r"-", ": "), (r"_", " ")) # Weblate organizes internationalization work into projects and components, # which are part of many URLs, and need to be referenced in some API requests. @@ -94,7 +94,7 @@ def __init__( component, files, request_limit, - canonicalization_rules=[], + canonicalization_rules=(), ): if len(token) != 40: @@ -169,7 +169,7 @@ def _canonicalize(self, filename): filename = re.sub(pattern, repl, filename) return filename - def upload(self, existing_screenshots=[]): + def upload(self, existing_screenshots=None): """ Uploads all files using the screenshots endpoint. Optionally, checks files against a list of existing screenshots and replaces them rather @@ -179,11 +179,14 @@ def upload(self, existing_screenshots=[]): basename = os.path.basename(file) canonical_name = self._canonicalize(basename) existing_screenshot_url = None - for screenshot in existing_screenshots: - if screenshot["name"] == canonical_name: - existing_screenshot_url = screenshot["file_url"] - break - image = {"image": open(file, "rb")} + + if existing_screenshots is not None: + for screenshot in existing_screenshots: + if screenshot["name"] == canonical_name: + existing_screenshot_url = screenshot["file_url"] + break + image = {"image": open(file, "rb")} + if existing_screenshot_url is not None: print("Replacing existing screenshot {}".format(basename)) response = self.session.post(existing_screenshot_url, files=image)