+def get_depends_parts(depend) :
+ v_match = re_version.match(depend)
+ if v_match:
+ d_parts = { 'name' : v_match.group(1), 'version' : v_match.group(2) }
+ else :
+ d_parts = { 'name' : depend , 'version' : '' }
+ return d_parts
+
+def get_or_list(depend) :
+ or_list = depend.split("|");
+ return or_list
+
+def get_comma_list(depend) :
+ dep_list = depend.split(",");
+ return dep_list
+
+def split_depends (d_str) :
+ # creates a list of lists of dictionaries of depends (package,version relation)
+
+ d_str = re_spacestrip.sub('',d_str);
+ depends_tree = [];
+ # first split depends string up amongs comma delimiter
+ dep_list = get_comma_list(d_str);
+ d = 0;
+ while d < len(dep_list):
+ # put depends into their own list
+ depends_tree.append([dep_list[d]]);
+ d += 1;
+ d = 0;
+ while d < len(depends_tree):
+ k = 0;
+ # split up Or'd depends into a multi-item list
+ depends_tree[d] = get_or_list(depends_tree[d][0]);
+ while k < len(depends_tree[d]):
+ # split depends into {package, version relation}
+ depends_tree[d][k] = get_depends_parts(depends_tree[d][k]);
+ k += 1;
+ d += 1;
+ return depends_tree;
+
+def read_control (filename):
+ recommends = [];
+ depends = [];
+ section = '';
+ maintainer = '';
+ arch = '';
+
+ deb_file = utils.open_file(filename);
+ try:
+ extracts = apt_inst.debExtractControl(deb_file);
+ control = apt_pkg.ParseSection(extracts);
+ except:
+ print "can't parse control info";
+ control = '';
+
+ deb_file.close();
+
+ control_keys = control.keys();
+
+ if control.has_key("Depends"):
+ depends_str = control.Find("Depends");
+ # create list of dependancy lists
+ depends = split_depends(depends_str);
+
+ if control.has_key("Recommends"):
+ recommends_str = control.Find("Recommends");
+ recommends = split_depends(recommends_str);
+
+ if control.has_key("Section"):
+ section_str = control.Find("Section");
+
+ c_match = re_contrib.search(section_str)
+ nf_match = re_nonfree.search(section_str)
+ if c_match :
+ # contrib colour
+ section = contrib_colour + section_str + end_colour
+ elif nf_match :
+ # non-free colour
+ section = nonfree_colour + section_str + end_colour
+ else :
+ # main
+ section = main_colour + section_str + end_colour
+ if control.has_key("Architecture"):
+ arch_str = control.Find("Architecture")
+ arch = arch_colour + arch_str + end_colour
+
+ if control.has_key("Maintainer"):
+ maintainer = control.Find("Maintainer")
+ localhost = re_localhost.search(maintainer)
+ if localhost:
+ #highlight bad email
+ maintainer = maintainer_colour + maintainer + end_colour;
+
+ return (control, control_keys, section, depends, recommends, arch, maintainer)
+
+def read_dsc (dsc_filename):
+ dsc = {};
+
+ dsc_file = utils.open_file(dsc_filename);
+ try:
+ dsc = utils.parse_changes(dsc_filename);
+ except:
+ print "can't parse control info"
+ dsc_file.close();
+
+ filecontents = strip_pgp_signature(dsc_filename);
+
+ if dsc.has_key("build-depends"):
+ builddep = split_depends(dsc["build-depends"]);
+ builddepstr = create_depends_string(builddep);
+ filecontents = re_builddep.sub("Build-Depends: "+builddepstr, filecontents);
+
+ if dsc.has_key("build-depends-indep"):
+ builddepindstr = create_depends_string(split_depends(dsc["build-depends-indep"]));
+ filecontents = re_builddepind.sub("Build-Depends-Indep: "+builddepindstr, filecontents);
+
+ if dsc.has_key("architecture") :
+ if (dsc["architecture"] != "any"):
+ newarch = arch_colour + dsc["architecture"] + end_colour;
+ filecontents = re_arch.sub("Architecture: " + newarch, filecontents);
+
+ return filecontents;
+
+def create_depends_string (depends_tree):
+ # just look up unstable for now. possibly pull from .changes later
+ suite = "unstable";
+ result = "";
+ comma_count = 1;
+ for l in depends_tree:
+ if (comma_count >= 2):
+ result += ", ";
+ or_count = 1
+ for d in l:
+ if (or_count >= 2 ):
+ result += " | "
+ # doesn't do version lookup yet.
+
+ q = projectB.query("SELECT DISTINCT(b.package), b.version, c.name, su.suite_name FROM binaries b, files fi, location l, component c, bin_associations ba, suite su WHERE b.package='%s' AND b.file = fi.id AND fi.location = l.id AND l.component = c.id AND ba.bin=b.id AND ba.suite = su.id AND su.suite_name='%s' ORDER BY b.version desc" % (d['name'], suite));
+ ql = q.getresult();
+ if ql:
+ i = ql[0];
+
+ if i[2] == "contrib":
+ result += contrib_colour + d['name'];
+ elif i[2] == "non-free":
+ result += nonfree_colour + d['name'];
+ else :
+ result += main_colour + d['name'];
+
+ if d['version'] != '' :
+ result += " (%s)" % (d['version']);
+ result += end_colour;
+ else:
+ result += bold_colour + d['name'];
+ if d['version'] != '' :
+ result += " (%s)" % (d['version']);
+ result += end_colour;
+ or_count += 1;
+ comma_count += 1;
+ return result;
+
+def output_deb_info(filename):
+ (control, control_keys, section, depends, recommends, arch, maintainer) = read_control(filename);
+
+ if control == '':
+ print "no control info"
+ else:
+ for key in control_keys :
+ output = " " + key + ": "
+ if key == 'Depends':
+ output += create_depends_string(depends);
+ elif key == 'Recommends':
+ output += create_depends_string(recommends);
+ elif key == 'Section':
+ output += section;
+ elif key == 'Architecture':
+ output += arch;
+ elif key == 'Maintainer':
+ output += maintainer;
+ elif key == 'Description':
+ desc = control.Find(key);
+ desc = re_newlinespace.sub('\n ', desc);
+ output += desc;
+ else:
+ output += control.Find(key);
+ print output;
+