Ejemplo n.º 1
0
def main(args):
    ''' Main() function '''

    try:
        options, arguments = getopt.getopt(args[1:], '')
    except getopt.error:
        sys.exit('usage: neubot background_win32')
    if options or arguments:
        sys.exit('usage: neubot background_win32')

    # Read settings from database
    CONFIG.merge_database(DATABASE.connection())

    #
    # Save logs into the database, to easily access
    # and show them via the web user interface.
    #
    LOG.use_database()

    # Complain if privacy settings are not OK
    privacy.complain_if_needed()

    background_api.start('127.0.0.1 ::1', '9774')
    BACKGROUND_RENDEZVOUS.start()

    __start_updater()

    POLLER.loop()
Ejemplo n.º 2
0
def main(args):
    ''' Main function '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:nv')
    except getopt.error:
        sys.exit(USAGE)

    database_path = system.get_default_database_path()
    auto_discover = True
    for name, value in options:
        if name == '-f':
            database_path = value
        elif name == '-n':
            auto_discover = False
        elif name == '-v':
            CONFIG['verbose'] = 1

    if len(arguments) != 1 and len(arguments) != 2:
        sys.exit(USAGE)

    DATABASE.set_path(database_path)
    CONFIG.merge_database(DATABASE.connection())

    if len(arguments) == 2:
        RUNNER_TESTS.update({arguments[0]: [arguments[1]]})
        ctx = {'uri': arguments[1]}
    else:
        ctx = None

    deferred = Deferred()
    deferred.add_callback(lambda param: None)
    RUNNER_CORE.run(arguments[0], deferred, auto_discover, ctx)
    POLLER.loop()
Ejemplo n.º 3
0
def main(args):
    ''' Main function '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:n')
    except getopt.error:
        sys.exit('Usage: %s [-n] [-f database] test [negotiate_uri]' % args[0])
    if len(arguments) != 1 and len(arguments) != 2:
        sys.exit('Usage: %s [-n] [-f database] test [negotiate_uri]' % args[0])

    database_path = system.get_default_database_path()
    auto_rendezvous = True
    for name, value in options:
        if name == '-f':
            database_path = value
        elif name == '-n':
            auto_rendezvous = False

    DATABASE.set_path(database_path)
    CONFIG.merge_database(DATABASE.connection())

    if len(arguments) == 2:
        RUNNER_TESTS.update({arguments[0]: [arguments[1]]})
        ctx = {'uri': arguments[1]}
    else:
        ctx = None

    RUNNER_CORE.run(arguments[0], lambda *args: None, auto_rendezvous, ctx)
    POLLER.loop()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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)
    client.connect_uri()
    POLLER.loop()
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
def main(args):
    ''' Main() function '''

    try:
        options, arguments = getopt.getopt(args[1:], '')
    except getopt.error:
        sys.exit('usage: neubot background_win32')
    if options or arguments:
        sys.exit('usage: neubot background_win32')

    # Read settings from database
    CONFIG.merge_database(DATABASE.connection())

    BACKEND.use_backend("neubot")
    BACKEND.datadir_init()

    #
    # Save logs into the database, to easily access
    # and show them via the web user interface.
    #
    LOG.use_database()

    logging.info('%s for Windows: starting up', utils_version.PRODUCT)

    # Complain if privacy settings are not OK
    privacy.complain_if_needed()

    background_api.start_api()
    BACKGROUND_RENDEZVOUS.start()

    __start_updater()

    POLLER.loop()

    logging.info('%s for Windows: shutting down', utils_version.PRODUCT)
    LOG.writeback()

    #
    # Make sure that we do not leave the database
    # in an inconsistent state.
    #
    DATABASE.close()
Ejemplo n.º 9
0
def main(args):
    ''' Main function '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f')
    except getopt.error:
        sys.exit('Usage: %s [-f database] test negotiate_uri' % args[0])
    if len(arguments) != 2:
        sys.exit('Usage: %s [-f database] test negotiate_uri' % args[0])

    database_path = system.get_default_database_path()
    for name, value in options:
        if name == '-f':
            database_path = value

    DATABASE.set_path(database_path)
    CONFIG.merge_database(DATABASE.connection())

    run(arguments[0], arguments[1], lambda: None)
    POLLER.loop()
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
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()