[Git][security-tracker-team/security-tracker][master] 5 commits: sources: add name and path info

Salvatore Bonaccorso carnil at debian.org
Sat Jun 16 12:49:20 BST 2018


Salvatore Bonaccorso pushed to branch master at Debian Security Tracker / security-tracker


Commits:
ebe67846 by Emilio Pozuelo Monfort at 2018-06-15T10:59:20+02:00
sources: add name and path info

This avoids having to guess the name from the path.

- - - - -
f9362fec by Emilio Pozuelo Monfort at 2018-06-15T11:05:52+02:00
Makefile: merge stamps/*-syntax rules

We can use a wildcard here as they are all similar.

- - - - -
b95b70ea by Emilio Pozuelo Monfort at 2018-06-15T11:13:24+02:00
Makefile: don't hardcode the syntax stamps

- - - - -
a38e6da6 by Emilio Pozuelo Monfort at 2018-06-15T11:16:22+02:00
check-syntax: don't hardcode sources

Get them from config.json instead. This also simplifies the
parse_* functions as there's just a generic one now.

- - - - -
6afe5c6c by Salvatore Bonaccorso at 2018-06-16T13:48:32+02:00
Merge branch 'pochu/security-tracker-syntax-stamps'

- - - - -


4 changed files:

- Makefile
- bin/check-syntax
- data/config.json
- lib/python/security_db.py


Changes:

=====================================
Makefile
=====================================
--- a/Makefile
+++ b/Makefile
@@ -42,23 +42,10 @@ clean:
 
 test check: check-syntax
 
-check-syntax: stamps/CVE-syntax \
-	stamps/DSA-syntax stamps/DTSA-syntax stamps/DLA-syntax
-
-stamps/CVE-syntax: data/CVE/list bin/check-syntax $(PYTHON_MODULES)
-	$(PYTHON) bin/check-syntax CVE data/CVE/list
-	touch $@
-
-stamps/DSA-syntax: data/DSA/list bin/check-syntax $(PYTHON_MODULES)
-	$(PYTHON) bin/check-syntax DSA data/DSA/list
-	touch $@
-
-stamps/DTSA-syntax: data/DTSA/list bin/check-syntax $(PYTHON_MODULES)
-	$(PYTHON) bin/check-syntax DTSA data/DTSA/list
-	touch $@
-
-stamps/DLA-syntax: data/DLA/list bin/check-syntax $(PYTHON_MODULES)
-	$(PYTHON) bin/check-syntax DLA data/DLA/list
+SYNTAX_STAMPS = $(patsubst %,stamps/%-syntax,$(shell bin/check-syntax --get))
+check-syntax: $(SYNTAX_STAMPS)
+stamps/%-syntax: data/%/list bin/check-syntax $(PYTHON_MODULES)
+	$(PYTHON) bin/check-syntax $* data/$*/list
 	touch $@
 
 .PHONY: serve


=====================================
bin/check-syntax
=====================================
--- a/bin/check-syntax
+++ b/bin/check-syntax
@@ -51,30 +51,38 @@ def construct(c, name):
     else:
         f  = file(name)
     return c(name, f)
-    
 
-def parse_CVE(name):
-    f = construct(bugs.CVEFile, name)
-    # Relax syntax checking a bit.
-    f.no_version_needs_note = False
-    do_parse(f)
+sources = debian_support.getconfig()["sources"]
+
+def find_source(name):
+    for source in sources:
+        if source["name"] == name:
+            return source
+
+    return None
 
-def parse_DSA(name):
-    do_parse(construct(bugs.DSAFile, name))
+def parse_file(name, filename):
+    source = find_source(name)
+    cls = source["class"]
+    cls = getattr(bugs, cls)
+    f = construct(cls, filename)
 
-def parse_DTSA(name):
-    do_parse(construct(bugs.DTSAFile, name))
+    if cls == bugs.CVEFile:
+        # Relax syntax checking a bit.
+        f.no_version_needs_note = False
+
+    do_parse(f)
 
-file_types = {'CVE' : parse_CVE,
-              'DSA' : parse_DSA,
-              'DTSA' : parse_DTSA,
-              'DLA' : parse_DSA}
+if len(sys.argv) == 2 and sys.argv[1] == "--get":
+    l = [src["name"] for src in sources]
+    print ' '.join(l)
+    sys.exit(0)
 
-if len(sys.argv) <> 3 or not file_types.has_key(sys.argv[1]):
-    l = file_types.keys()
+if len(sys.argv) <> 3 or find_source(sys.argv[1]) == None:
+    l = [src["name"] for src in sources]
     l.sort()
     sys.stderr.write("usage: check-syntax {%s} file-name\n"
                      % '|'.join(l))
     sys.exit(1)
 
-file_types[sys.argv[1]](sys.argv[2])
+parse_file(sys.argv[1], sys.argv[2])


=====================================
data/config.json
=====================================
--- a/data/config.json
+++ b/data/config.json
@@ -83,10 +83,10 @@
       "release": "unstable"
     }
   },
-  "sources": {
-    "/CVE/list": "CVEFile",
-    "/DSA/list": "DSAFile",
-    "/DTSA/list": "DTSAFile",
-    "/DLA/list": "DSAFile"
-  }
+  "sources": [
+    {"name": "CVE", "path": "/CVE/list", "class": "CVEFile"},
+    {"name": "DSA", "path": "/DSA/list", "class": "DSAFile"},
+    {"name": "DTSA", "path": "/DTSA/list", "class": "DTSAFile"},
+    {"name": "DLA", "path": "/DLA/list", "class": "DSAFile"}
+  ]
 }


=====================================
lib/python/security_db.py
=====================================
--- a/lib/python/security_db.py
+++ b/lib/python/security_db.py
@@ -866,9 +866,9 @@ class DB:
         sources = self.getSources()
         advs = []
 
-        for path, cls in sources.iteritems():
-            name = path.split('/')[1]
-
+        for src in sources:
+            name = src["name"]
+            cls = src["class"]
             if cls == 'DSAFile':
                 advs.append(name)
 
@@ -936,9 +936,10 @@ class DB:
 
         source_removed_packages = '/packages/removed-packages'
         sources = self.getSources()
+        source_paths = [src["path"] for src in sources]
 
         unchanged = True
-        for filename in sources.keys() + [source_removed_packages]:
+        for filename in source_paths + [source_removed_packages]:
             if has_changed(path + filename):
                 unchanged = False
                 break
@@ -958,9 +959,11 @@ class DB:
                 """INSERT OR REPLACE INTO inodeprints (inodeprint, file)
                 VALUES (?, ?)""", (current_print, filename))
 
-        for name, cls in sources.iteritems():
+        for src in sources:
+            srcpath = src["path"]
+            cls = src["class"]
             cls = getattr(bugs, cls)
-            read_one(cls(path + name))
+            read_one(cls(path + srcpath))
 
         if self.verbose:
             print "  update removed packages"



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/6fb0bbf8f3e514567685e2c90ae147e5eee0a072...6afe5c6cc0de13f45e34a1c80156fd70e2b602a5

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/6fb0bbf8f3e514567685e2c90ae147e5eee0a072...6afe5c6cc0de13f45e34a1c80156fd70e2b602a5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20180616/3595ccbf/attachment-0001.html>


More information about the debian-security-tracker-commits mailing list