예제 #1
0
def create(connection, commit=True):
    ''' Creates table_config if it does not exist '''
    connection.execute("""CREATE TABLE IF NOT EXISTS config(
      name TEXT PRIMARY KEY, value TEXT);""")
    connection.execute("""INSERT OR IGNORE INTO config VALUES(
      'version', %s);""" % SCHEMA_VERSION)
    connection.execute("""INSERT OR IGNORE INTO config VALUES(
      'uuid', ?);""", (get_uuid(),))
    if commit:
        connection.commit()
예제 #2
0
 def session_negotiate(self, identifier):
     if not identifier in self.identifiers:
         session = SessionState()
         # XXX collision is not impossible but very unlikely
         session.identifier = utils.get_uuid()
         session.timestamp = utils.timestamp()
         self._do_add(session)
     else:
         session = self.identifiers[identifier]
     session.negotiations += 1
     return session
예제 #3
0
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)
예제 #4
0
 def __init__(self):
     self.times = (get_time(START, DAYS) for _ in xrange(ROWS))
     self.uuids = [get_uuid() for _ in xrange(0, UUIDS)]
     self.addrs = {}
예제 #5
0
 def __init__(self):
     self.times = (get_time(START, DAYS) for _ in xrange(ROWS))
     self.uuids = [get_uuid() for _ in xrange(0, UUIDS)]
     self.addrs = {}