def compute_subset(config, include_pkgspecs, exclude_pkgspecs, sess = None): # argparse gives None if switch is absent if include_pkgspecs is None: include_pkgspecs = [] if exclude_pkgspecs is None: exclude_pkgspecs = [] # parse the pkgspecs include_tuples = [ parse_subset_spec(s) for s in include_pkgspecs ] exclude_tuples = [ parse_subset_spec(s) for s in exclude_pkgspecs ] if sess is None: (sess, engine) = init_orm(config["sqldb"]) sys.stderr.write("Collecting include files:\n") include_files = build_file_list(config, sess, include_tuples) sys.stderr.write("Collecting exclude files:\n") exclude_files = build_file_list(config, sess, exclude_tuples) sys.stderr.write("Performing subtract... ") subset = include_files - exclude_files sys.stderr.write("Done\n") sys.stderr.write("Sorting... ") subset = sorted(subset) sys.stderr.write("Done\n") sys.stderr.write("Writing %d filenames to '%s'... " % (len(subset), config["plist"])) with open(config["plist"], "w") as fh: for fl in subset: fh.write("%s%s\n" % (config["prefix_filenames"], fl)) sys.stderr.write("Done\n")
def initdb(config, return_sess = False): # Since we will only ever use sqlite, we can do this if os.path.exists(config["sqldb"]): os.unlink(config["sqldb"]) # Set up ORM (sess, engine) = orm.init_orm(config["sqldb"]) DeclarativeBase.metadata.create_all(engine) # Populate db parse(sess, config["tlpdb"]) sess.commit() # Done print_db_summary(sess) if not return_sess: sess.close() else: return sess