[Git][security-tracker-team/security-tracker][master] 2 commits: update-nvd: don't chdir

Emilio Pozuelo Monfort pochu at debian.org
Thu Aug 13 10:53:31 BST 2020



Emilio Pozuelo Monfort pushed to branch master at Debian Security Tracker / security-tracker


Commits:
71313afc by Emilio Pozuelo Monfort at 2020-08-13T11:38:55+02:00
update-nvd: don't chdir

- - - - -
f815d203 by Emilio Pozuelo Monfort at 2020-08-13T11:49:08+02:00
De-duplicate setup_path

All the scripts in bin/ can share the definition. Also
setup_paths.py calls setup_path so one just has to import
that module before importing those from lib/python/.

Additionally this helps some scripts work better under Python 3,
as one variant of setup_paths that we had called string.rfind,
which is not present there.

- - - - -


9 changed files:

- bin/apt-update-file
- bin/check-syntax
- bin/lts-bts
- bin/lts-cve-triage.py
- bin/lts-needs-forward-port.py
- bin/report-vuln
- + bin/setup_paths.py
- bin/update-db
- bin/update-nvd


Changes:

=====================================
bin/apt-update-file
=====================================
@@ -2,24 +2,9 @@
 
 # This script is mainly used to demo the updateFile function.
 from __future__ import print_function
-import os
-import os.path
-import string
 import sys
 
-def setup_paths():
-    check_file = 'lib/python/debian_support.py'
-    path = os.getcwd()
-    while 1:
-        if os.path.exists("%s/%s" % (path, check_file)):
-            sys.path = [path + '/lib/python'] + sys.path
-            return path
-        idx = string.rfind(path, '/')
-        if idx == -1:
-            raise ImportError("could not setup paths")
-        path = path[0:idx]
-root_path = setup_paths()
-
+import setup_paths
 import debian_support
 
 if len(sys.argv) != 3:


=====================================
bin/check-syntax
=====================================
@@ -1,23 +1,8 @@
 #!/usr/bin/python3
 
-import os
-import os.path
-import string
 import sys
 
-def setup_paths():
-    check_file = 'lib/python/debian_support.py'
-    path = os.getcwd()
-    while 1:
-        if os.path.exists("%s/%s" % (path, check_file)):
-            sys.path = [path + '/lib/python'] + sys.path
-            return path
-        idx = string.rfind(path, '/')
-        if idx == -1:
-            raise ImportError("could not setup paths")
-        path = path[0:idx]
-root_path = setup_paths()
-
+import setup_paths
 import bugs
 import debian_support
 


=====================================
bin/lts-bts
=====================================
@@ -13,12 +13,7 @@ import warnings
 
 from tracker_data import TrackerData
 
-def setup_path():
-    dirname = os.path.dirname
-    base = dirname(dirname(os.path.realpath(sys.argv[0])))
-    sys.path.insert(0, os.path.join(base, "lib", "python"))
-
-setup_path()
+import setup_paths
 import config
 
 from jinja2 import Template


=====================================
bin/lts-cve-triage.py
=====================================
@@ -15,7 +15,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this file.  If not, see <https://www.gnu.org/licenses/>.
 
-import os
 import sys
 import argparse
 import collections
@@ -23,12 +22,7 @@ import collections
 from tracker_data import TrackerData
 from unsupported_packages import UnsupportedPackages, LimitedSupportPackages
 
-def setup_path():
-    dirname = os.path.dirname
-    base = dirname(dirname(os.path.realpath(sys.argv[0])))
-    sys.path.insert(0, os.path.join(base, "lib", "python"))
-
-setup_path()
+import setup_paths
 import config
 
 RELEASES = {


=====================================
bin/lts-needs-forward-port.py
=====================================
@@ -17,17 +17,11 @@
 
 import argparse
 import collections
-import os
 import sys
 
 from tracker_data import TrackerData
 
-def setup_path():
-    dirname = os.path.dirname
-    base = dirname(dirname(os.path.realpath(sys.argv[0])))
-    sys.path.insert(0, os.path.join(base, "lib", "python"))
-
-setup_path()
+import setup_paths
 import config
 
 lts = config.get_supported_releases()[0]


=====================================
bin/report-vuln
=====================================
@@ -20,13 +20,8 @@ from textwrap import wrap
 
 temp_id = re.compile('(?:CVE|cve)\-[0-9]{4}-XXXX')
 
-def setup_path():
-    dirname = os.path.dirname
-    base = dirname(dirname(os.path.realpath(sys.argv[0])))
-    sys.path.insert(0, os.path.join(base, "lib", "python"))
-
 def description_from_list(id, pkg='', skip_entries=0):
-    setup_path()
+    import setup_paths
     import bugs
     import debian_support
     is_temp = temp_id.match(id)


=====================================
bin/setup_paths.py
=====================================
@@ -0,0 +1,11 @@
+# inserts lib/python/ into sys.path
+
+import os
+import sys
+
+def setup_path():
+    dirname = os.path.dirname
+    base = dirname(dirname(os.path.realpath(__file__)))
+    sys.path.insert(0, os.path.join(base, "lib", "python"))
+
+setup_path()


=====================================
bin/update-db
=====================================
@@ -1,24 +1,9 @@
 #!/usr/bin/python3
 from __future__ import print_function
 
-import os
-import os.path
-import string
 import sys
 
-def setup_paths():
-    check_file = 'lib/python/debian_support.py'
-    path = os.getcwd()
-    while 1:
-        if os.path.exists("%s/%s" % (path, check_file)):
-            sys.path = [path + '/lib/python'] + sys.path
-            return path
-        idx = string.rfind(path, '/')
-        if idx == -1:
-            raise ImportError("could not setup paths")
-        path = path[0:idx]
-os.chdir(setup_paths())
-
+import setup_paths
 import bugs
 import debian_support
 import security_db


=====================================
bin/update-nvd
=====================================
@@ -1,27 +1,14 @@
 #!/usr/bin/python3
 
-import os
 import os.path
-import string
 import sys
 
-def setup_paths():
-    check_file = 'lib/python/debian_support.py'
-    path = os.getcwd()
-    while 1:
-        if os.path.exists("%s/%s" % (path, check_file)):
-            sys.path = [path + '/lib/python'] + sys.path
-            return path
-        idx = string.rfind(path, '/')
-        if idx == -1:
-            raise ImportError("could not setup paths")
-        path = path[0:idx]
-os.chdir(setup_paths())
-
+import setup_paths
 import nvd
 import security_db
 
-db_file = 'data/security.db'
+base = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+db_file = os.path.join(base, 'data/security.db')
 db = security_db.DB(db_file)
 
 incremental = False



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/a725d894a58344f422a5f8b004fab3b427506aec...f815d2033d464c3838f07188b8aa0ce773b6e57b

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/a725d894a58344f422a5f8b004fab3b427506aec...f815d2033d464c3838f07188b8aa0ce773b6e57b
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/20200813/0afbd93e/attachment-0001.html>


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