X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=dak%2Fexamine_package.py;h=63ee8af5ce303d01fbe19afcbff0386d881b9666;hb=f01b13ab05dcfc8ccebb8eaba3362f70b3018809;hp=5cb1a77e9a6fb8dcbd3e62d511056d4dfe08edd8;hpb=50db22ea5f288daa39f81138a41a509d9a41cc3e;p=dak.git
diff --git a/dak/examine_package.py b/dak/examine_package.py
index 5cb1a77e..63ee8af5 100755
--- a/dak/examine_package.py
+++ b/dak/examine_package.py
@@ -56,15 +56,18 @@ import md5
import apt_pkg
import apt_inst
import shutil
-import commands
+import subprocess
import threading
from daklib import utils
+from daklib.config import Config
from daklib.dbconn import DBConn, get_component_by_package_suite
from daklib.gpg import SignedFile
from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \
re_contrib, re_nonfree, re_localhost, re_newlinespace, \
re_package, re_doc_directory
+from daklib.dak_exceptions import ChangesUnicodeError
+import daklib.daksubprocess
################################################################################
@@ -76,7 +79,7 @@ printed.copyrights = {}
package_relations = {} #: Store relations of packages for later output
# default is to not output html.
-use_html = 0
+use_html = False
################################################################################
@@ -106,7 +109,7 @@ def headline(s, level=2, bodyelement=None):
if bodyelement:
return """
%(title)s (click to toggle) |
- \n"""%{"bodyelement":bodyelement,"title":utils.html_escape(s)}
+ \n"""%{"bodyelement":bodyelement,"title":utils.html_escape(os.path.basename(s))}
else:
return "%s\n" % (level, utils.html_escape(s), level)
else:
@@ -230,6 +233,7 @@ def split_depends (d_str) :
def read_control (filename):
recommends = []
+ predepends = []
depends = []
section = ''
maintainer = ''
@@ -237,8 +241,8 @@ def read_control (filename):
deb_file = utils.open_file(filename)
try:
- extracts = apt_inst.debExtractControl(deb_file)
- control = apt_pkg.ParseSection(extracts)
+ extracts = utils.deb_extract_control(deb_file)
+ control = apt_pkg.TagSection(extracts)
except:
print formatted_text("can't parse control info")
deb_file.close()
@@ -248,17 +252,21 @@ def read_control (filename):
control_keys = control.keys()
- if control.has_key("Depends"):
- depends_str = control.Find("Depends")
+ if "Pre-Depends" in control:
+ predepends_str = control["Pre-Depends"]
+ predepends = split_depends(predepends_str)
+
+ if "Depends" in control:
+ depends_str = control["Depends"]
# create list of dependancy lists
depends = split_depends(depends_str)
- if control.has_key("Recommends"):
- recommends_str = control.Find("Recommends")
+ if "Recommends" in control:
+ recommends_str = control["Recommends"]
recommends = split_depends(recommends_str)
- if control.has_key("Section"):
- section_str = control.Find("Section")
+ if "Section" in control:
+ section_str = control["Section"]
c_match = re_contrib.search(section_str)
nf_match = re_nonfree.search(section_str)
@@ -271,12 +279,12 @@ def read_control (filename):
else :
# main
section = colour_output(section_str, 'main')
- if control.has_key("Architecture"):
- arch_str = control.Find("Architecture")
+ if "Architecture" in control:
+ arch_str = control["Architecture"]
arch = colour_output(arch_str, 'arch')
- if control.has_key("Maintainer"):
- maintainer = control.Find("Maintainer")
+ if "Maintainer" in control:
+ maintainer = control["Maintainer"]
localhost = re_localhost.search(maintainer)
if localhost:
#highlight bad email
@@ -284,7 +292,7 @@ def read_control (filename):
else:
maintainer = escape_if_needed(maintainer)
- return (control, control_keys, section, depends, recommends, arch, maintainer)
+ return (control, control_keys, section, predepends, depends, recommends, arch, maintainer)
def read_changes_or_dsc (suite, filename, session = None):
dsc = {}
@@ -413,7 +421,7 @@ def output_package_relations ():
return foldable_output("Package relations", "relations", to_print)
def output_deb_info(suite, filename, packagename, session = None):
- (control, control_keys, section, depends, recommends, arch, maintainer) = read_control(filename)
+ (control, control_keys, section, predepends, depends, recommends, arch, maintainer) = read_control(filename)
if control == '':
return formatted_text("no control info")
@@ -421,7 +429,10 @@ def output_deb_info(suite, filename, packagename, session = None):
if not package_relations.has_key(packagename):
package_relations[packagename] = {}
for key in control_keys :
- if key == 'Depends':
+ if key == 'Pre-Depends':
+ field_value = create_depends_string(suite, predepends, session)
+ package_relations[packagename][key] = field_value
+ elif key == 'Depends':
field_value = create_depends_string(suite, depends, session)
package_relations[packagename][key] = field_value
elif key == 'Recommends':
@@ -435,33 +446,47 @@ def output_deb_info(suite, filename, packagename, session = None):
field_value = maintainer
elif key == 'Description':
if use_html:
- field_value = formatted_text(control.Find(key), strip=True)
+ field_value = formatted_text(control.find(key), strip=True)
else:
- desc = control.Find(key)
+ desc = control.find(key)
desc = re_newlinespace.sub('\n ', desc)
field_value = escape_if_needed(desc)
else:
- field_value = escape_if_needed(control.Find(key))
+ field_value = escape_if_needed(control.find(key))
to_print += " "+format_field(key,field_value)+'\n'
return to_print
-def do_command (command, filename, escaped=0):
- o = os.popen("%s %s" % (command, filename))
- if escaped:
- return escaped_text(o.read())
- else:
- return formatted_text(o.read())
+def do_command (command, escaped=False):
+ process = daklib.daksubprocess.Popen(command, stdout=subprocess.PIPE)
+ o = process.stdout
+ try:
+ if escaped:
+ return escaped_text(o.read())
+ else:
+ return formatted_text(o.read())
+ finally:
+ process.wait()
def do_lintian (filename):
+ cnf = Config()
+ cmd = []
+
+ user = cnf.get('Dinstall::UnprivUser') or None
+ if user is not None:
+ cmd.extend(['sudo', '-H', '-u', user])
+
+ color = 'always'
if use_html:
- return do_command("lintian --show-overrides --color html", filename, 1)
- else:
- return do_command("lintian --show-overrides --color always", filename, 1)
+ color = 'html'
+
+ cmd.extend(['lintian', '--show-overrides', '--color', color, "--", filename])
+
+ return do_command(cmd, escaped=True)
def get_copyright (deb_filename):
global printed
- package = re_package.sub(r'\1', deb_filename)
+ package = re_package.sub(r'\1', os.path.basename(deb_filename))
o = os.popen("dpkg-deb -c %s | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{print $6}' | head -n 1" % (deb_filename))
cright = o.read()[:-1]
@@ -477,49 +502,51 @@ def get_copyright (deb_filename):
copyrightmd5 = md5.md5(cright).hexdigest()
res = ""
- if printed.copyrights.has_key(copyrightmd5) and printed.copyrights[copyrightmd5] != "%s (%s)" % (package, deb_filename):
+ if printed.copyrights.has_key(copyrightmd5) and printed.copyrights[copyrightmd5] != "%s (%s)" % (package, os.path.basename(deb_filename)):
res += formatted_text( "NOTE: Copyright is the same as %s.\n\n" % \
(printed.copyrights[copyrightmd5]))
else:
- printed.copyrights[copyrightmd5] = "%s (%s)" % (package, deb_filename)
+ printed.copyrights[copyrightmd5] = "%s (%s)" % (package, os.path.basename(deb_filename))
return res+formatted_text(cright)
def get_readme_source (dsc_filename):
tempdir = utils.temp_dirname()
os.rmdir(tempdir)
- cmd = "dpkg-source --no-check --no-copy -x %s %s" % (dsc_filename, tempdir)
- (result, output) = commands.getstatusoutput(cmd)
- if (result != 0):
+ cmd = ('dpkg-source', '--no-check', '--no-copy', '-x', dsc_filename, tempdir)
+ try:
+ daklib.daksubprocess.check_output(cmd, stderr=1)
+ except subprocess.CalledProcessError as e:
res = "How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some\n old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?\n"
res += "Error, couldn't extract source, WTF?\n"
- res += "'dpkg-source -x' failed. return code: %s.\n\n" % (result)
- res += output
+ res += "'dpkg-source -x' failed. return code: %s.\n\n" % (e.returncode)
+ res += e.output
return res
path = os.path.join(tempdir, 'debian/README.source')
res = ""
if os.path.exists(path):
- res += do_command("cat", path)
+ res += do_command(["cat", "--", path])
else:
res += "No README.source in this package\n\n"
try:
shutil.rmtree(tempdir)
- except OSError, e:
+ except OSError as e:
if errno.errorcode[e.errno] != 'EACCES':
res += "%s: couldn't remove tmp dir %s for source tree." % (dsc_filename, tempdir)
return res
def check_dsc (suite, dsc_filename, session = None):
- (dsc) = read_changes_or_dsc(suite, dsc_filename, session)
+ dsc = read_changes_or_dsc(suite, dsc_filename, session)
+ dsc_basename = os.path.basename(dsc_filename)
return foldable_output(dsc_filename, "dsc", dsc, norow=True) + \
"\n" + \
- foldable_output("lintian check for %s" % dsc_filename,
+ foldable_output("lintian check for %s" % dsc_basename,
"source-lintian", do_lintian(dsc_filename)) + \
"\n" + \
- foldable_output("README.source for %s" % dsc_filename,
+ foldable_output("README.source for %s" % dsc_basename,
"source-readmesource", get_readme_source(dsc_filename))
def check_deb (suite, deb_filename, session = None):
@@ -542,7 +569,7 @@ def check_deb (suite, deb_filename, session = None):
"binary-%s-lintian"%packagename, do_lintian(deb_filename)) + "\n"
result += foldable_output("contents of %s" % (filename), "binary-%s-contents"%packagename,
- do_command("dpkg -c", deb_filename)) + "\n"
+ do_command(["dpkg", "-c", deb_filename])) + "\n"
if is_a_udeb:
result += foldable_output("skipping copyright for udeb",
@@ -551,9 +578,6 @@ def check_deb (suite, deb_filename, session = None):
result += foldable_output("copyright of %s" % (filename),
"binary-%s-copyright"%packagename, get_copyright(deb_filename)) + "\n"
- result += foldable_output("file listing of %s" % (filename),
- "binary-%s-file-listing"%packagename, do_command("ls -l", deb_filename))
-
return result
# Read a file, strip the signature and return the modified contents as
@@ -597,15 +621,15 @@ def main ():
if not Cnf.has_key("Examine-Package::Options::%s" % (i)):
Cnf["Examine-Package::Options::%s" % (i)] = ""
- args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
- Options = Cnf.SubTree("Examine-Package::Options")
+ args = apt_pkg.parse_commandline(Cnf,Arguments,sys.argv)
+ Options = Cnf.subtree("Examine-Package::Options")
if Options["Help"]:
usage()
if Options["Html-Output"]:
global use_html
- use_html = 1
+ use_html = True
stdout_fd = sys.stdout
@@ -613,7 +637,9 @@ def main ():
try:
if not Options["Html-Output"]:
# Pipe output for each argument through less
- less_fd = os.popen("less -R -", 'w', 0)
+ less_cmd = ("less", "-R", "-")
+ less_process = daklib.daksubprocess.Popen(less_cmd, stdin=subprocess.PIPE, bufsize=0)
+ less_fd = less_process.stdin
# -R added to display raw control chars for colour
sys.stdout = less_fd
try:
@@ -632,8 +658,9 @@ def main ():
if not Options["Html-Output"]:
# Reset stdout here so future less invocations aren't FUBAR
less_fd.close()
+ less_process.wait()
sys.stdout = stdout_fd
- except IOError, e:
+ except IOError as e:
if errno.errorcode[e.errno] == 'EPIPE':
utils.warn("[examine-package] Caught EPIPE; skipping.")
pass