Merge ~andrey-fedoseev/launchpad:uct-import-directory into launchpad:master

Proposed by Andrey Fedoseev
Status: Merged
Approved by: Andrey Fedoseev
Approved revision: 010fe3092ed02f3274ec027ab2a21a79a76ff691
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~andrey-fedoseev/launchpad:uct-import-directory
Merge into: launchpad:master
Diff against target: 59 lines (+26/-6)
1 file modified
scripts/uct-import.py (+26/-6)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+429130@code.launchpad.net

Commit message

UCT import: allow importing from a directory

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/uct-import.py b/scripts/uct-import.py
2index 5a37c77..489d6ea 100755
3--- a/scripts/uct-import.py
4+++ b/scripts/uct-import.py
5@@ -7,15 +7,20 @@ import _pythonpath # noqa: F401
6 import logging
7 from pathlib import Path
8
9+from lp.app.validators.cve import CVEREF_PATTERN
10 from lp.bugs.scripts.uct import UCTImporter
11 from lp.services.scripts.base import LaunchpadScript
12
13+logger = logging.getLogger(__name__)
14+
15
16 class UCTImportScript(LaunchpadScript):
17
18- usage = "usage: %prog [options] CVE_FILE_PATH"
19+ usage = "usage: %prog [options] PATH"
20 description = (
21- "Import bugs into Launchpad from CVE entries in ubuntu-cve-tracker."
22+ "Import bugs into Launchpad from CVE entries in ubuntu-cve-tracker. "
23+ "PATH is either path to a CVE file, or path to a directory "
24+ "containing the CVE files"
25 )
26 loglevel = logging.INFO
27
28@@ -30,12 +35,27 @@ class UCTImportScript(LaunchpadScript):
29
30 def main(self):
31 if len(self.args) != 1:
32- self.parser.error("Please specify a CVE file to import")
33+ self.parser.error("Please specify a path to import")
34+
35+ path = Path(self.args[0])
36+ if path.is_dir():
37+ logger.info(
38+ "Importing CVE files from directory: %s", path.resolve()
39+ )
40+ cve_paths = sorted(
41+ p
42+ for p in path.rglob("CVE-*")
43+ if p.is_file() and CVEREF_PATTERN.match(p.name)
44+ )
45+ if not cve_paths:
46+ logger.warning("Could not find CVE files in %s", path)
47+ return
48+ else:
49+ cve_paths = [path]
50
51 importer = UCTImporter(dry_run=self.options.dry_run)
52-
53- cve_path = Path(self.args[0])
54- importer.import_cve_from_file(cve_path)
55+ for cve_path in cve_paths:
56+ importer.import_cve_from_file(cve_path)
57
58
59 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to status/vote changes: