launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29094
[Merge] ~andrey-fedoseev/launchpad:uct-import-directory into launchpad:master
Andrey Fedoseev has proposed merging ~andrey-fedoseev/launchpad:uct-import-directory into launchpad:master.
Commit message:
UCT import: allow importing from a directory
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~andrey-fedoseev/launchpad/+git/launchpad/+merge/429130
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~andrey-fedoseev/launchpad:uct-import-directory into launchpad:master.
diff --git a/scripts/uct-import.py b/scripts/uct-import.py
index 5a37c77..946c484 100755
--- a/scripts/uct-import.py
+++ b/scripts/uct-import.py
@@ -5,17 +5,25 @@
import _pythonpath # noqa: F401
import logging
+import re
from pathlib import Path
from lp.bugs.scripts.uct import UCTImporter
from lp.services.scripts.base import LaunchpadScript
+CVE_RE = re.compile(r"^CVE-\d\d\d\d-[N\d]{4,7}$")
+
+
+logger = logging.getLogger(__name__)
+
class UCTImportScript(LaunchpadScript):
- usage = "usage: %prog [options] CVE_FILE_PATH"
+ usage = "usage: %prog [options] PATH"
description = (
- "Import bugs into Launchpad from CVE entries in ubuntu-cve-tracker."
+ "Import bugs into Launchpad from CVE entries in ubuntu-cve-tracker. "
+ "PATH is either path to a CVE file, or path to a directory "
+ "containing the CVE files"
)
loglevel = logging.INFO
@@ -30,12 +38,27 @@ class UCTImportScript(LaunchpadScript):
def main(self):
if len(self.args) != 1:
- self.parser.error("Please specify a CVE file to import")
+ self.parser.error("Please specify a path to import")
- importer = UCTImporter(dry_run=self.options.dry_run)
+ path = Path(self.args[0])
+ if path.is_dir():
+ logger.info(
+ "Importing CVE files from directory: %s", path.resolve()
+ )
+ cve_paths = [
+ p
+ for p in path.rglob("CVE-*")
+ if p.is_file() and CVE_RE.match(p.name)
+ ]
+ if not cve_paths:
+ logger.warning("Could not find CVE files in %s", path)
+ return
+ else:
+ cve_paths = [path]
- cve_path = Path(self.args[0])
- importer.import_cve_from_file(cve_path)
+ importer = UCTImporter(dry_run=self.options.dry_run)
+ for cve_path in cve_paths:
+ importer.import_cve_from_file(cve_path)
if __name__ == "__main__":