def main(args): try: options, arguments = getopt.getopt(args[1:], "f:") except getopt.GetoptError: sys.stderr.write(USAGE) sys.exit(1) for key, value in options: if key == "-f": DATABASE.set_path(value) DATABASE.connect() if not arguments: sys.stdout.write('%s\n' % DATABASE.path) elif arguments[0] == "regen_uuid": if DATABASE.readonly: sys.exit('ERROR: readonly database') table_config.update(DATABASE.connection(), {"uuid": utils.get_uuid()}.iteritems()) elif arguments[0] == "prune": if DATABASE.readonly: sys.exit('ERROR: readonly database') table_speedtest.prune(DATABASE.connection()) elif arguments[0] == "delete_all": if DATABASE.readonly: sys.exit('ERROR: readonly database') table_speedtest.prune(DATABASE.connection(), until=utils.timestamp()) DATABASE.connection().execute("VACUUM;") elif arguments[0] in ("show", "dump"): d = { "config": table_config.dictionarize(DATABASE.connection()), "speedtest": table_speedtest.listify(DATABASE.connection()) } if arguments[0] == "show": compat.json.dump(d, sys.stdout, indent=4) elif arguments[0] == "dump": compat.json.dump(d, sys.stdout) else: sys.stdout.write(USAGE) sys.exit(0)
def main(args): try: options, arguments = getopt.getopt(args[1:], "o:", ["sparse"]) except getopt.error: sys.stderr.write(USAGE) sys.exit(1) outfile = "__database__.sqlite3" sparse = False for key, value in options: if key == "-o": outfile = value elif key == "--sparse": sparse = True if not arguments: sys.stdout.write(USAGE) sys.exit(0) output_wrapper = OutputWrapper(outfile) sys.stderr.write("* Output database file: %s\n" % outfile) for path in arguments: input_dbm = open_dbm(path) if not sparse: # # When some parts of the database overlap remove the # overlapping part and make sure the database does not # wast disk space with garbage. # CAVEAT You must use --sparse if you collate databases # coming from different test servers! # sys.stderr.write("* Removing overlapping parts: %s... " % path) table_speedtest.prune(input_dbm.connection(), output_wrapper.since) input_dbm.connection().execute("VACUUM;") sys.stderr.write("done\n") sys.stderr.write("* Processing rows in file: %s... " % path) table_speedtest.walk(input_dbm.connection(), output_wrapper.insert) sys.stderr.write("done\n") sys.stderr.write("* Committing changes to: %s\n" % outfile) output_wrapper.commit()
def runTest(self): """Make sure speedtest table works as expected""" connection = sqlite3.connect(":memory:") connection.row_factory = sqlite3.Row table_speedtest.create(connection) table_speedtest.create(connection) v = map(None, ResultIterator()) for d in v: table_speedtest.insert(connection, d, override_timestamp=False) v1 = table_speedtest.listify(connection) self.assertEquals(sorted(v), sorted(v1)) since = utils.timestamp() - 7 * 24 * 60 * 60 until = utils.timestamp() - 3 * 24 * 60 * 60 v2 = table_speedtest.listify(connection, since=since, until=until) self.assertTrue(len(v2) < len(v)) table_speedtest.prune(connection, until) self.assertTrue(len(table_speedtest.listify(connection)) < len(v1))