summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Keen <keenerd@gmail.com>2016-06-18 07:44:19 -0400
committerKyle Keen <keenerd@gmail.com>2016-06-18 09:08:11 -0400
commitf8850453ef59305bba13b3c6e492a9e4ce00720e (patch)
treee595a9cf153db0ca438c86708dfdb84fe998974f
parent4424a23cf2cb3976d6ae7dc8d1161d6ddc1015b0 (diff)
downloadnamcap-f8850453ef59305bba13b3c6e492a9e4ce00720e.tar.gz
namcap-f8850453ef59305bba13b3c6e492a9e4ce00720e.zip
Clean some cruft
Signed-off-by: Kyle Keen <keenerd@gmail.com>
-rw-r--r--Namcap/rules/shebangdepends.py19
-rw-r--r--Namcap/tests/makepkg.py7
-rw-r--r--Namcap/util.py19
3 files changed, 16 insertions, 29 deletions
diff --git a/Namcap/rules/shebangdepends.py b/Namcap/rules/shebangdepends.py
index 567acf5..1af9139 100644
--- a/Namcap/rules/shebangdepends.py
+++ b/Namcap/rules/shebangdepends.py
@@ -24,7 +24,7 @@
import re
import os
import tempfile
-import subprocess
+import shutil
import pyalpm
import Namcap.package
from Namcap.util import script_type
@@ -37,6 +37,7 @@ def scanshebangs(fileobj, filename, scripts):
Stores
scripts -- a dictionary { program => set(scripts) }
"""
+ # todo: this function has no test coverage
# test magic bytes
magic = fileobj.read(2)
@@ -63,19 +64,18 @@ def findowners(scriptlist):
pkglist -- a dictionary { package => set(programs) }
orphans -- a set of scripts not found
"""
+ # todo: this function has no test coverage
pkglist = {}
scriptfound = set()
for s in scriptlist:
- p = subprocess.Popen(["which", s],
- stdout = subprocess.PIPE, stderr = subprocess.PIPE)
- out, _ = p.communicate()
- if p.returncode != 0:
+ out = shutil.which(s)
+ if not out:
continue
# strip leading slash
- scriptpath = out.strip()[1:].decode('utf-8', 'surrogateescape')
+ scriptpath = out.lstrip('/')
for pkg in Namcap.package.get_installed_packages():
pkg_files = [fname for fname, fsize, fmode in pkg.files]
if scriptpath in pkg_files:
@@ -85,13 +85,6 @@ def findowners(scriptlist):
orphans = list(set(scriptlist) - scriptfound)
return pkglist, orphans
-def getprovides(depends, provides):
- for i in depends.keys():
- pac = load(i)
-
- if pac != None and 'provides' in pac and pac["provides"] != None:
- provides[i] = pac["provides"]
-
class ShebangDependsRule(TarballRule):
name = "shebangdepends"
description = "Checks dependencies semi-smartly."
diff --git a/Namcap/tests/makepkg.py b/Namcap/tests/makepkg.py
index a32a477..b3b0725 100644
--- a/Namcap/tests/makepkg.py
+++ b/Namcap/tests/makepkg.py
@@ -80,13 +80,10 @@ class MakepkgTest(unittest.TestCase):
os.chdir(pwd)
def run_rule_on_tarball(self, filename, rule):
- ret = subprocess.call(["unxz", '-f', filename + ".xz"])
- self.assertEqual(ret, 0)
-
# process PKGINFO
- pkg = Namcap.package.load_from_tarball(filename)
+ pkg = Namcap.package.load_from_tarball(filename + ".xz")
- tar = tarfile.open(filename)
+ tar = tarfile.open(filename + ".xz")
r = rule()
r.analyze(pkg, tar)
tar.close()
diff --git a/Namcap/util.py b/Namcap/util.py
index 21d7163..a28784d 100644
--- a/Namcap/util.py
+++ b/Namcap/util.py
@@ -55,10 +55,7 @@ def is_elf(path):
if not magic:
return False
# magic elf header, present in binaries and libraries
- if magic == b"\x7FELF":
- return True
- else:
- return False
+ return magic == b"\x7FELF"
def script_type(path):
firstline = _read_carefully(path, lambda fd: fd.readline())
@@ -67,13 +64,13 @@ def script_type(path):
return None
script = re.compile('#!.*/(.*)')
m = script.match(firstline)
- if m != None:
- cmd = m.group(1).split()
- name = cmd[0]
- if name == 'env':
- name = cmd[1]
- return name
- return None
+ if m is None:
+ return None
+ cmd = m.group(1).split()
+ name = cmd[0]
+ if name == 'env':
+ name = cmd[1]
+ return name
clean_filename = lambda s: re.search(r"/tmp/namcap\.[0-9]*/(.*)", s).group(1)