]> git.decadent.org.uk Git - dak.git/blobdiff - charisma
Add new top level directories
[dak.git] / charisma
index 6a23ab9cd7c181c5217341ad4118e32c450e025b..b9eae14704e14783a07bb08a835b8e5e58abb3a1 100755 (executable)
--- a/charisma
+++ b/charisma
@@ -1,8 +1,8 @@
 #!/usr/bin/env python
 
 # Generate Maintainers file used by e.g. the Debian Bug Tracking System
-# Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
-# $Id: charisma,v 1.9 2001-09-13 23:51:51 troup Exp $
+# Copyright (C) 2000, 2001, 2002, 2003, 2004  James Troup <james@nocrew.org>
+# $Id: charisma,v 1.18 2004-06-17 15:02:02 troup Exp $
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-####################################################################################################################################
+################################################################################
 
 # ``As opposed to "Linux sucks. Respect my academic authoritah, damn
 #   you!" or whatever all this hot air amounts to.''
 #                             -- ajt@ in _that_ thread on debian-devel@
 
-####################################################################################################################################
+################################################################################
 
-import os, pg, re, string, sys
-import db_access, utils
-import apt_pkg
+import pg, sys;
+import db_access, utils;
+import apt_pkg;
 
-####################################################################################################################################
+################################################################################
 
 projectB = None
 Cnf = None
@@ -38,9 +38,17 @@ maintainer_from_source_cache = {}
 packages = {}
 fixed_maintainer_cache = {}
 
-re_split = re.compile(r"(\S+)\s+(\S+.*)")
+################################################################################
 
-####################################################################################################################################
+def usage (exit_code=0):
+    print """Usage: charisma [OPTION] EXTRA_FILE[...]
+Generate an index of packages <=> Maintainers.
+
+  -h, --help                 show this help and exit
+"""
+    sys.exit(exit_code)
+
+################################################################################
 
 def fix_maintainer (maintainer):
     global fixed_maintainer_cache;
@@ -63,23 +71,28 @@ def get_maintainer_from_source (source_id):
 
     return maintainer_from_source_cache[source_id]
 
-####################################################################################################################################
+################################################################################
 
 def main():
     global Cnf, projectB;
 
-    apt_pkg.init();
+    Cnf = utils.get_conf()
+
+    Arguments = [('h',"help","Charisma::Options::Help")];
+    if not Cnf.has_key("Charisma::Options::Help"):
+       Cnf["Charisma::Options::Help"] = "";
 
-    Cnf = apt_pkg.newConfiguration();
-    apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
+    extra_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
+    Options = Cnf.SubTree("Charisma::Options");
 
-    extra_files = apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
+    if Options["Help"]:
+        usage();
 
     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
     db_access.init(Cnf, projectB);
 
     for suite in Cnf.SubTree("Suite").List():
-        suite = string.lower(suite);
+        suite = suite.lower();
         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)]);
 
         # Source packages
@@ -91,7 +104,7 @@ def main():
             maintainer = fix_maintainer(source[2]);
             if packages.has_key(package):
                 if packages[package]["priority"] <= suite_priority:
-                    if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
+                    if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
             else:
                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
@@ -104,32 +117,45 @@ def main():
             source_id = binary[1];
             version = binary[3];
             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
-            if source_id != 0 and source_id != None:
+            if source_id:
                 maintainer = get_maintainer_from_source(source_id);
             else:
                 maintainer = get_maintainer(binary[2]);
             if packages.has_key(package):
                 if packages[package]["priority"] <= suite_priority:
-                    if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
+                    if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
             else:
                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
 
     # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
     for filename in extra_files:
-        file = utils.open_file(filename, 'r')
+        file = utils.open_file(filename);
         for line in file.readlines():
-            m = re_split.match(line[:-1])
-            package = m.group(1)
-            maintainer = fix_maintainer(m.group(2))
-            if not packages.has_key(package):
-                packages[package] = { "maintainer": maintainer, "priority": 0 }
-        file.close()
+            line = utils.re_comments.sub('', line).strip();
+            if line == "":
+                continue;
+            split = line.split();
+            lhs = split[0];
+            maintainer = fix_maintainer(" ".join(split[1:]));
+            if lhs.find('~') != -1:
+                (package, version) = lhs.split('~');
+            else:
+                package = lhs;
+                version = '*';
+            # A version of '*' overwhelms all real version numbers
+            if not packages.has_key(package) or version == '*' \
+               or apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
+                packages[package] = { "maintainer": maintainer, "version": version };
+        file.close();
 
     package_keys = packages.keys()
     package_keys.sort()
     for package in package_keys:
-        print "%-20s %s" % (package, packages[package]["maintainer"])
+        lhs = "~".join([package, packages[package]["version"]]);
+        print "%-30s %s" % (lhs, packages[package]["maintainer"]);
+
+################################################################################
 
 if __name__ == '__main__':
     main()