summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <pochu@debian.org>2020-08-13 11:47:12 +0200
committerEmilio Pozuelo Monfort <pochu@debian.org>2020-08-13 11:49:08 +0200
commita51f0ac2888bb7da475af291f77a79fb7f7cd5e0 (patch)
treea967b015199565bf5c8738cc940e936ef1494059 /bin
parentc741ea438ed32b771bc176bafd9db7af98a55c5e (diff)
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.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/apt-update-file17
-rwxr-xr-xbin/check-syntax17
-rwxr-xr-xbin/lts-bts7
-rwxr-xr-xbin/lts-cve-triage.py8
-rwxr-xr-xbin/lts-needs-forward-port.py8
-rwxr-xr-xbin/report-vuln7
-rw-r--r--bin/setup_paths.py11
-rwxr-xr-xbin/update-db17
-rwxr-xr-xbin/update-nvd16
9 files changed, 19 insertions, 89 deletions
diff --git a/bin/apt-update-file b/bin/apt-update-file
index 617eed2d99..505d23f602 100755
--- a/bin/apt-update-file
+++ b/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:
diff --git a/bin/check-syntax b/bin/check-syntax
index 6f7eadd831..529f378550 100755
--- a/bin/check-syntax
+++ b/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
diff --git a/bin/lts-bts b/bin/lts-bts
index da9365721c..d1a70b63c2 100755
--- a/bin/lts-bts
+++ b/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
diff --git a/bin/lts-cve-triage.py b/bin/lts-cve-triage.py
index 7f106ab8e6..9a90fcd816 100755
--- a/bin/lts-cve-triage.py
+++ b/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 = {
diff --git a/bin/lts-needs-forward-port.py b/bin/lts-needs-forward-port.py
index ee29ef5486..06a5630f8f 100755
--- a/bin/lts-needs-forward-port.py
+++ b/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]
diff --git a/bin/report-vuln b/bin/report-vuln
index ffa3ecc12f..d0dead6895 100755
--- a/bin/report-vuln
+++ b/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)
diff --git a/bin/setup_paths.py b/bin/setup_paths.py
new file mode 100644
index 0000000000..d2f8194662
--- /dev/null
+++ b/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()
diff --git a/bin/update-db b/bin/update-db
index 71603d9ee1..e6da4322ed 100755
--- a/bin/update-db
+++ b/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
diff --git a/bin/update-nvd b/bin/update-nvd
index 19b1cbfcda..6573b9139f 100755
--- a/bin/update-nvd
+++ b/bin/update-nvd
@@ -1,23 +1,9 @@
#!/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]
-setup_paths()
-
+import setup_paths
import nvd
import security_db

© 2014-2024 Faster IT GmbH | imprint | privacy policy