Example #1
0
def runWithDirector(global_options, create_input_store=True):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """
    from ooni.director import Director
    start_tor = False
    director = Director()
    if global_options['list']:
        net_tests = [net_test for net_test in director.getNetTests().items()]
        log.msg("")
        log.msg("Installed nettests")
        log.msg("==================")
        for net_test_id, net_test in net_tests:
            optList = []
            for name, details in net_test['arguments'].items():
                optList.append({'long': name, 'doc': details['description']})

            desc = ('\n' +
                    net_test['name'] +
                    '\n' +
                    '-'*len(net_test['name']) +
                    '\n' +
                    '\n'.join(textwrap.wrap(net_test['description'], 80)) +
                    '\n\n' +
                    '$ ooniprobe {}/{}'.format(net_test['category'],
                                                      net_test['id']) +
                    '\n\n' +
                    ''.join(usage.docMakeChunks(optList))
            )
            map(log.msg, desc.split("\n"))
            log.msg("Note: Third party tests require an external "
                    "application to run properly.")

        raise SystemExit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options.get('preferred-backend') is not None:
        config.advanced.preferred_backend = global_options['preferred-backend']

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    elif config.advanced.get("preferred_backend", "onion") == "onion":
        start_tor = True

    if (global_options['collector'] and
            config.advanced.get("preferred_backend", "onion") == "onion"):
        start_tor |= True

    return runTestWithDirector(
        director=director,
        start_tor=start_tor,
        global_options=global_options,
        create_input_store=create_input_store
    )
Example #2
0
def runWithDirector(global_options, create_input_store=True):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """
    from ooni.director import Director
    start_tor = False
    director = Director()
    if global_options['list']:
        net_tests = [net_test for net_test in director.getNetTests().items()]
        log.msg("")
        log.msg("Installed nettests")
        log.msg("==================")
        for net_test_id, net_test in net_tests:
            optList = []
            for name, details in net_test['arguments'].items():
                optList.append({'long': name, 'doc': details['description']})

            desc = ('\n' +
                    net_test['name'] +
                    '\n' +
                    '-'*len(net_test['name']) +
                    '\n' +
                    '\n'.join(textwrap.wrap(net_test['description'], 80)) +
                    '\n\n' +
                    '$ ooniprobe {}/{}'.format(net_test['category'],
                                                      net_test['id']) +
                    '\n\n' +
                    ''.join(usage.docMakeChunks(optList))
            )
            map(log.msg, desc.split("\n"))
            log.msg("Note: Third party tests require an external "
                    "application to run properly.")

        raise SystemExit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options.get('preferred-backend') is not None:
        config.advanced.preferred_backend = global_options['preferred-backend']

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    elif config.advanced.get("preferred_backend", "onion") == "onion":
        start_tor = True

    if (global_options['collector'] and
            config.advanced.get("preferred_backend", "onion") == "onion"):
        start_tor |= True

    return runTestWithDirector(
        director=director,
        start_tor=start_tor,
        global_options=global_options,
        create_input_store=create_input_store
    )
Example #3
0
 def getUsage(self, width=None):
     doc = usage.Options.getUsage(self, width=width)
     header = "Available tasks:"
     tasks = sorted(Task.task_types(), key=lambda t: t.name)
     tasks_doc = "".join(
         usage.docMakeChunks([{"long": task.name, "doc": task.__doc__} for task in tasks if not task.hidden])
     )
     return "\n".join([doc, header, tasks_doc])
Example #4
0
def runWithDirector(global_options):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """
    from ooni.director import Director
    director = Director()
    if global_options['list']:
        net_tests = [net_test for net_test in director.getNetTests().items()]
        print ""
        print "Installed nettests"
        print "=================="
        for net_test_id, net_test in net_tests:
            optList = []
            for name, details in net_test['arguments'].items():
                optList.append({'long': name, 'doc': details['description']})

            desc = ('\n' +
                    net_test['name'] +
                    '\n' +
                    '-'*len(net_test['name']) +
                    '\n' +
                    '\n'.join(textwrap.wrap(net_test['description'], 80)) +
                    '\n\n' +
                    '$ ooniprobe {}/{}'.format(net_test['category'],
                                                      net_test['id']) +
                    '\n\n' +
                    ''.join(usage.docMakeChunks(optList))
            )
            print desc
            print "Note: Third party tests require an external "\
                  "application to run properly."

        sys.exit(0)

    elif global_options['printdeck']:
        del global_options['printdeck']
        print "# Copy and paste the lines below into a test deck to run the specified test with the specified arguments"
        print yaml.safe_dump([{'options': global_options}]).strip()

        sys.exit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    else:
        start_tor = True

    if global_options['collector']:
        start_tor |= True

    return runTestWithDirector(director=director,
                               start_tor=start_tor,
                               global_options=global_options)
Example #5
0
def runWithDirector(global_options):
    """
    Instance the director, parse command line options and start an ooniprobe
    test!
    """
    from ooni.director import Director
    start_tor = False
    director = Director()
    if global_options['list']:
        net_tests = [net_test for net_test in director.getNetTests().items()]
        print ""
        print "Installed nettests"
        print "=================="
        for net_test_id, net_test in net_tests:
            optList = []
            for name, details in net_test['arguments'].items():
                optList.append({'long': name, 'doc': details['description']})

            desc = ('\n' + net_test['name'] + '\n' +
                    '-' * len(net_test['name']) + '\n' +
                    '\n'.join(textwrap.wrap(net_test['description'], 80)) +
                    '\n\n' + '$ ooniprobe {}/{}'.format(
                        net_test['category'], net_test['id']) + '\n\n' +
                    ''.join(usage.docMakeChunks(optList)))
            print desc
            print "Note: Third party tests require an external "\
                  "application to run properly."

        sys.exit(0)

    elif global_options['printdeck']:
        del global_options['printdeck']
        print "# Copy and paste the lines below into a test deck to run the specified test with the specified arguments"
        print yaml.safe_dump([{'options': global_options}]).strip()

        sys.exit(0)

    if global_options.get('annotations') is not None:
        global_options['annotations'] = setupAnnotations(global_options)

    if global_options.get('preferred-backend') is not None:
        config.advanced.preferred_backend = global_options['preferred-backend']

    if global_options['no-collector']:
        log.msg("Not reporting using a collector")
        global_options['collector'] = None
        start_tor = False
    elif config.advanced.get("preferred_backend", "onion") == "onion":
        start_tor = True

    if (global_options['collector']
            and config.advanced.get("preferred_backend", "onion") == "onion"):
        start_tor |= True

    return runTestWithDirector(director=director,
                               start_tor=start_tor,
                               global_options=global_options)
Example #6
0
 def getUsage(self, width=None):
     doc = usage.Options.getUsage(self, width=width)
     header = "Available tasks:"
     tasks = sorted(Task.task_types(), key=lambda t: t.name)
     tasks_doc = "".join(
         usage.docMakeChunks([{
             'long': task.name,
             'doc': task.__doc__,
         } for task in tasks if not task.hidden]))
     return "\n".join([doc, header, tasks_doc])