当前位置: 首页>>代码示例>>Python>>正文


Python DATABASE.connect方法代码示例

本文整理汇总了Python中neubot.database.DATABASE.connect方法的典型用法代码示例。如果您正苦于以下问题:Python DATABASE.connect方法的具体用法?Python DATABASE.connect怎么用?Python DATABASE.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neubot.database.DATABASE的用法示例。


在下文中一共展示了DATABASE.connect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: speedtest_store

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
 def speedtest_store(self, message):
     ''' Saves the results of a speedtest test '''
     DATABASE.connect()
     if DATABASE.readonly:
         logging.warning('backend_neubot: readonly database')
         return
     table_speedtest.insert(DATABASE.connection(), message)
开发者ID:servetti-polito,项目名称:neubot-dash,代码行数:9,代码来源:backend_neubot.py

示例2: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], "6A:np:vy")
    except getopt.error:
        sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")
    if arguments:
        sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")

    prefer_ipv6 = 0
    # address = 'master.neubot.org'
    address = "localhost"
    runner = 1
    port = 8080
    noisy = 0
    fakeprivacy = 0
    for name, value in options:
        if name == "-6":
            prefer_ipv6 = 1
        elif name == "-A":
            address = value
        elif name == "-n":
            runner = 0
        elif name == "-p":
            port = int(value)
        elif name == "-v":
            noisy = 1
        elif name == "-y":
            fakeprivacy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning("skype: database file is missing: %s", DATABASE.path)
        BACKEND.use_backend("null")
    if noisy:
        log.set_verbose()
    if runner:
        result = runner_clnt.runner_client(
            CONFIG["agent.api.address"], CONFIG["agent.api.port"], CONFIG["verbose"], "skype"
        )
        if result:
            sys.exit(0)

    logging.info("skype: running the test in the local process context...")
    if not fakeprivacy and not privacy.allowed_to_run():
        privacy.complain()
        logging.info("skype: otherwise use -y option to temporarily provide " "privacy permissions")
        sys.exit(1)

    handler = SkypeNegotiate()
    handler.connect((address, port), prefer_ipv6, 0, {})
    POLLER.loop()
开发者ID:claudiuperta,项目名称:neubot,代码行数:56,代码来源:skype.py

示例3: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(name, descr, args):
    Eflag = False
    lflag = False

    try:
        options, arguments = getopt.getopt(args[1:], "D:Ef:lVv", ["help"])
    except getopt.GetoptError:
        write_help(sys.stderr, name, descr)
        sys.exit(1)

    if arguments:
        write_help(sys.stderr, name, descr)
        sys.exit(1)

    verbose = 0

    for key, value in options:
        if key == "-D":
            # No shortcuts because it grows too confusing
            CONFIG.register_property(value)
        elif key == "-E":
            Eflag = True
        elif key == "-f":
            DATABASE.set_path(value)
        elif key == "--help":
            write_help(sys.stdout, name, descr)
            sys.exit(0)
        elif key == "-l":
            lflag = True
        elif key == "-V":
            sys.stdout.write(VERSION + "\n")
            sys.exit(0)
        elif key == "-v":
            verbose = 1

    DATABASE.connect()

    CONFIG.merge_database(DATABASE.connection())
    if not Eflag:
        CONFIG.merge_environ()
    CONFIG.merge_properties()

    # Apply the setting after we've read database and environment
    if verbose:
        CONFIG['verbose'] = 1

    if lflag:
        CONFIG.print_descriptions(sys.stdout)
        sys.exit(0)
开发者ID:EverlastingFire,项目名称:neubot,代码行数:51,代码来源:common.py

示例4: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
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)
开发者ID:EverlastingFire,项目名称:neubot,代码行数:50,代码来源:main.py

示例5: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    ''' Main function '''
    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 8080
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('raw: database file is missing: %s', DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    if not force:
        result = runner_clnt.runner_client(CONFIG['agent.api.address'],
          CONFIG['agent.api.port'], CONFIG['verbose'], 'raw')
        if result:
            sys.exit(0)
        logging.warning('raw: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('raw: run the test in the local process context...')
    handler = RawNegotiate()
    handler.connect((address, port), prefer_ipv6, 0, {})
    POLLER.loop()
开发者ID:EverlastingFire,项目名称:neubot,代码行数:49,代码来源:raw.py

示例6: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main():
    Sflag = False

    options, arguments = getopt.getopt(sys.argv[1:], "S")
    for key, value in options:
        if key == "-S":
            Sflag = True

    # don't clobber my local database
    DATABASE.set_path(":memory:")
    DATABASE.connect()

    if Sflag:
        server = ServerSpeedtest(POLLER)
        server.configure({"speedtest.negotiate.daemonize": False})
        server.listen(("127.0.0.1", 8080))

    else:
        speedtest_again()

    POLLER.loop()
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:23,代码来源:xxx.py

示例7: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    """ Starts the server module """

    if not system.has_enough_privs():
        sys.exit('FATAL: you must be root')

    try:
        options, arguments = getopt.getopt(args[1:], 'A:b:D:dv')
    except getopt.error:
        sys.exit(USAGE)
    if arguments:
        sys.exit(USAGE)

    address = ':: 0.0.0.0'
    backend = 'mlab'
    for name, value in options:
        if name == '-A':
            address = value
        elif name == '-b':
            backend = value
        elif name == '-D':
            name, value = value.split('=', 1)
            if name not in VALID_MACROS:
                sys.exit(USAGE)
            if name != 'server.datadir':  # XXX
                value = int(value)
            SETTINGS[name] = value
        elif name == '-d':
            SETTINGS['server.daemonize'] = 0
        elif name == '-v':
            CONFIG['verbose'] = 1

    logging.debug('server: using backend: %s... in progress', backend)
    if backend == 'mlab':
        BACKEND.datadir_init(None, SETTINGS['server.datadir'])
        BACKEND.use_backend('mlab')
    elif backend == 'neubot':
        DATABASE.connect()
        BACKEND.use_backend('neubot')
    elif backend == 'volatile':
        BACKEND.use_backend('volatile')
    else:
        BACKEND.use_backend('null')
    logging.debug('server: using backend: %s... complete', backend)

    for name, value in SETTINGS.items():
        CONFIG[name] = value

    conf = CONFIG.copy()

    #
    # Configure our global HTTP server and make
    # sure that we don't provide filesystem access
    # even by mistake.
    #
    conf["http.server.rootdir"] = ""
    HTTP_SERVER.configure(conf)

    #
    # New-new style: don't bother with abstraction and start the fucking
    # server by invoking its listen() method.
    #
    if CONFIG['server.raw']:
        logging.debug('server: starting raw server... in progress')
        RAW_SERVER_EX.listen((address, 12345),
          CONFIG['prefer_ipv6'], 0, '')
        logging.debug('server: starting raw server... complete')

    if conf['server.skype']:
        logging.debug('server: starting skype server... in progress')
        SKYPE_SERVER_EX.listen((":: 0.0.0.0", 45678),
            CONFIG['prefer_ipv6'], 0, '')
        logging.debug('server: starting skype server... complete')

    #
    # New-style modules are started just setting a
    # bunch of conf[] variables and then invoking
    # their run() method in order to kick them off.
    # This is now depricated in favor of the new-
    # new style described above.
    #

    if conf["server.negotiate"]:
        negotiate.run(POLLER, conf)

    if conf["server.bittorrent"]:
        conf["bittorrent.address"] = address
        conf["bittorrent.listen"] = True
        conf["bittorrent.negotiate"] = True
        bittorrent.run(POLLER, conf)

    if conf['server.speedtest']:
        #conf['speedtest.listen'] = 1           # Not yet
        #conf['speedtest.negotiate'] = 1        # Not yet
        neubot.speedtest.wrapper.run(POLLER, conf)

    # Migrating from old style to new style
    if conf["server.rendezvous"]:
        #conf["rendezvous.listen"] = True       # Not yet
        neubot.rendezvous.server.run()
#.........这里部分代码省略.........
开发者ID:claudiuperta,项目名称:neubot,代码行数:103,代码来源:server.py

示例8: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 8080
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('speedtest: database file is missing: %s',
                        DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    conf = CONFIG.copy()
    conf["speedtest.client.uri"] = "http://%s:%d/" % (address, port)
    conf["prefer_ipv6"] = prefer_ipv6

    if not force:
        if runner_clnt.runner_client(conf["agent.api.address"],
                                     conf["agent.api.port"],
                                     CONFIG['verbose'],
                                     "speedtest"):
            sys.exit(0)
        logging.warning(
          'speedtest: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('speedtest: run the test in the local process context...')
    client = ClientSpeedtest(POLLER)
    client.configure(conf)

    #
    # XXX Quick and dirty fix such that `neubot speedtest` when
    # there is no daemon running considers both the master and
    # the backup master server.  At the same time, respect user
    # choices if she overrides the default URI.
    #
    if CONFIG['speedtest.client.uri'] == 'http://master.neubot.org/':
        client.connect(('localhost', 8080))
    else:
        client.connect_uri()

    POLLER.loop()
开发者ID:claudiuperta,项目名称:neubot,代码行数:68,代码来源:client.py

示例9: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    '''
     This function is invoked when the user wants
     to run precisely this module.
    '''

    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 6881
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('bittorrent: database file is missing: %s',
                        DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    config.register_descriptions()  # Needed?
    conf = CONFIG.copy()
    config.finalize_conf(conf)

    conf['bittorrent.address'] = address
    conf['bittorrent.port'] = port
    conf['prefer_ipv6'] = prefer_ipv6

    if not force:
        if runner_clnt.runner_client(conf["agent.api.address"],
                                     conf["agent.api.port"],
                                     CONFIG['verbose'],
                                     "bittorrent"):
            sys.exit(0)
        logging.warning(
          'bittorrent: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('bittorrent: run the test in the local process context...')

    #
    # When we're connecting to a remote host to perform a test
    # we want Neubot to quit at the end of the test.  When this
    # happens the test code publishes the "testdone" event, so
    # here we prepare to intercept the event and break our main
    # loop.
    #
    NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop())
    run(POLLER, conf)
    POLLER.loop()
开发者ID:EverlastingFire,项目名称:neubot,代码行数:72,代码来源:__init__.py

示例10: main

# 需要导入模块: from neubot.database import DATABASE [as 别名]
# 或者: from neubot.database.DATABASE import connect [as 别名]
def main(args):
    """ Starts the server module """

    if not system.has_enough_privs():
        sys.exit("FATAL: you must be root")

    try:
        options, arguments = getopt.getopt(args[1:], "b:D:dv")
    except getopt.error:
        sys.exit(USAGE)
    if arguments:
        sys.exit(USAGE)

    backend = "mlab"
    for name, value in options:
        if name == "-b":
            backend = value
        elif name == "-D":
            name, value = value.split("=", 1)
            if name not in VALID_MACROS:
                sys.exit(USAGE)
            SETTINGS[name] = int(value)
        elif name == "-d":
            SETTINGS["server.daemonize"] = 0
        elif name == "-v":
            CONFIG["verbose"] = 1

    logging.debug("server: using backend: %s... in progress", backend)
    if backend == "mlab":
        FILESYS.datadir_init()
        BACKEND.use_backend("mlab")
    elif backend == "neubot":
        DATABASE.connect()
        BACKEND.use_backend("neubot")
    else:
        BACKEND.use_backend("null")
    logging.debug("server: using backend: %s... complete", backend)

    for name, value in SETTINGS.items():
        CONFIG[name] = value

    conf = CONFIG.copy()

    #
    # Configure our global HTTP server and make
    # sure that we don't provide filesystem access
    # even by mistake.
    #
    conf["http.server.rootdir"] = ""
    HTTP_SERVER.configure(conf)

    #
    # New-new style: don't bother with abstraction and start the fucking
    # server by invoking its listen() method.
    #
    if CONFIG["server.raw"]:
        logging.debug("server: starting raw server... in progress")
        RAW_SERVER_EX.listen((":: 0.0.0.0", 12345), CONFIG["prefer_ipv6"], 0, "")
        logging.debug("server: starting raw server... complete")

    #
    # New-style modules are started just setting a
    # bunch of conf[] variables and then invoking
    # their run() method in order to kick them off.
    #
    if conf["server.negotiate"]:
        negotiate.run(POLLER, conf)

    if conf["server.bittorrent"]:
        conf["bittorrent.listen"] = True
        conf["bittorrent.negotiate"] = True
        bittorrent.run(POLLER, conf)

    if conf["server.speedtest"]:
        # conf['speedtest.listen'] = 1           # Not yet
        # conf['speedtest.negotiate'] = 1        # Not yet
        neubot.speedtest.wrapper.run(POLLER, conf)

    # Migrating from old style to new style
    if conf["server.rendezvous"]:
        # conf["rendezvous.listen"] = True       # Not yet
        neubot.rendezvous.server.run()

    #
    # Historically Neubot runs on port 9773 and
    # 8080 but we would like to switch to port 80
    # in the long term period, because it's rare
    # that they filter it.
    # OTOH it looks like it's not possible to
    # do that easily w/ M-Lab because the port
    # is already taken.
    #
    address = ":: 0.0.0.0"
    ports = (80, 8080, 9773)
    for port in ports:
        HTTP_SERVER.listen((address, port))

    #
    # Start server-side API for Nagios plugin
    # to query the state of the server.
#.........这里部分代码省略.........
开发者ID:servetti-polito,项目名称:neubot-dash,代码行数:103,代码来源:server.py


注:本文中的neubot.database.DATABASE.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。