+################################################################################
+
+def main ():
+ global Cnf, projectB;
+
+ Cnf = utils.get_conf()
+
+ for i in ["help", "limit", "no-action", "verbose" ]:
+ if not Cnf.has_key("Catherine::Options::%s" % (i)):
+ Cnf["Catherine::Options::%s" % (i)] = "";
+
+
+ Arguments = [('h',"help","Catherine::Options::Help"),
+ ('l',"limit", "Catherine::Options::Limit", "HasArg"),
+ ('n',"no-action","Catherine::Options::No-Action"),
+ ('v',"verbose","Catherine::Options::Verbose")];
+
+ apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
+ Options = Cnf.SubTree("Catherine::Options")
+
+ if Options["Help"]:
+ usage();
+
+ projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
+ db_access.init(Cnf, projectB);
+
+ if not Options["Limit"]:
+ limit = -1;
+ else:
+ limit = int(Options["Limit"]) * 1024;
+
+ # -n/--no-action implies -v/--verbose
+ if Options["No-Action"]:
+ Options["Verbose"] = "true";
+
+ # Sanity check the limit argument
+ if limit > 0 and limit < 1024:
+ utils.fubar("-l/--limit takes an argument with a value in kilobytes.");
+
+ # Grab a list of all files not already in the pool
+ q = projectB.query("""
+SELECT l.path, f.filename, f.id as files_id, c.name as component
+ FROM files f, location l, component c WHERE
+ NOT EXISTS (SELECT * FROM location l WHERE l.type = 'pool' AND f.location = l.id)
+ AND NOT (f.filename ~ '^potato') AND f.location = l.id AND l.component = c.id
+UNION SELECT l.path, f.filename, f.id as files_id, null as component
+ FROM files f, location l WHERE
+ NOT EXISTS (SELECT * FROM location l WHERE l.type = 'pool' AND f.location = l.id)
+ AND NOT (f.filename ~ '^potato') AND f.location = l.id AND NOT EXISTS
+ (SELECT l.path FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);""");
+
+ poolize(q, limit, Options["Verbose"], Options["No-Action"]);
+