def _build_parser_arguments(parser):
    """Builds the parser argument list.

    Given a ArgumentParser object, this method will populate the standard
    list of arguments.

    :param ArgumentParser parser: instance of an ArgumentParser.
    :returns: ArgumentParser
    """
    # optional arguments
    parser.add_argument('-l',
                        '--list',
                        action='store_true',
                        default=False,
                        help="List available recipes.")
    parser.add_argument('-f',
                        '--format',
                        dest='fmt',
                        default='table',
                        choices=all_formatters.keys(),
                        help="Format to print data in, defaults to 'table'.")
    parser.add_argument(
        '-v',
        '--verbose',
        action='store_true',
        default=False,
        help="Print the query and other debugging information.")
    parser.add_argument('-u',
                        '--url',
                        default='http://activedata.allizom.org/query',
                        help="Endpoint URL")
    # positional arguments
    parser.add_argument('task', nargs='*')
    return parser
Exemple #2
0
def _build_parser_arguments(parser, config):
    """Builds the parser argument list.

    Given a ArgumentParser object, this method will populate the standard
    list of arguments.

    :param ArgumentParser parser: instance of an ArgumentParser.
    :param Configuration config: config object.
    :returns: ArgumentParser
    """
    # optional arguments
    parser.add_argument('-l', '--list', action='store_true', default=False,
                        help="List available recipes.")
    parser.add_argument('-f', '--format', dest='fmt', default=config.fmt,
                        choices=all_formatters.keys(),
                        help="Format to print data in, defaults to 'table'.")
    parser.add_argument('-v', '--verbose', action='store_true', default=config.verbose,
                        help="Print the query and other debugging information.")
    parser.add_argument('-u', '--url', default=config.url,
                        help="Endpoint URL")
    parser.add_argument('-d', '--debug', action='store_true', default=config.debug,
                        help="Open a query in ActiveData query tool.")
    # positional arguments
    parser.add_argument('task', nargs='*')
    return parser
Exemple #3
0
    def __init__(self, *args, **kwargs):
        ArgumentParser.__init__(self, *args, **kwargs)

        self.add_argument('recipe', nargs='?', help="Recipe to run.")
        self.add_argument('-l', '--list', action='store_true', default=False,
                          help="List available recipes.")
        self.add_argument('-f', '--format', dest='fmt', default='table',
                          choices=all_formatters.keys(),
                          help="Format to print data in, defaults to 'table'.")
        self.add_argument('-v', '--verbose', action='store_true', default=False,
                          help="Print the query and other debugging information.")
Exemple #4
0
 def add_common_args(parser):
     parser.add_argument('-l', '--list', action='store_true', default=False,
                         help="List available recipes.")
     parser.add_argument('-f', '--format', dest='fmt', choices=all_formatters.keys(),
                         help="Format to print data in, defaults to 'table'.")
     parser.add_argument('-v', '--verbose', action='store_true',
                         help="Print the query and other debugging information.")
     parser.add_argument('-u', '--url',  help="ActiveData endpoint URL.")
     parser.add_argument('-o', '--output-file', type=str,
                         help="Full path of the output file")
     parser.set_defaults(**config.DEFAULTS)
Exemple #5
0
 def add_common_args(parser):
     parser.add_argument(
         "-f",
         "--format",
         dest="fmt",
         choices=all_formatters.keys(),
         help="Format to print data in, defaults to 'table'.",
     )
     parser.add_argument(
         "-v",
         "--verbose",
         action="count",
         default=0,
         help="Increase verbosity (can be passed multiple times).")
     parser.add_argument("-u", "--url", help="ActiveData endpoint URL.")
     parser.add_argument("-o",
                         "--output-file",
                         type=str,
                         help="Full path of the output file")
     parser.set_defaults(**config.DEFAULTS)
Exemple #6
0
 def add_common_args(parser):
     parser.add_argument(
         "-f",
         "--format",
         dest="fmt",
         choices=all_formatters.keys(),
         help="Format to print data in, defaults to 'table'.",
     )
     parser.add_argument(
         "-v",
         "--verbose",
         action="store_true",
         help="Print the query and other debugging information.",
     )
     parser.add_argument("-u", "--url", help="ActiveData endpoint URL.")
     parser.add_argument("-o",
                         "--output-file",
                         type=str,
                         help="Full path of the output file")
     parser.set_defaults(**config.DEFAULTS)
def cli(args=sys.argv[1:]):
    parser = ArgumentParser()
    parser.add_argument('recipes', nargs='*', help="Recipe(s) to run.")
    parser.add_argument('-l',
                        '--list',
                        action='store_true',
                        default=False,
                        help="List available recipes.")
    parser.add_argument('-f',
                        '--format',
                        dest='fmt',
                        default='table',
                        choices=all_formatters.keys(),
                        help="Format to print data in, defaults to 'table'.")
    parser.add_argument(
        '-v',
        '--verbose',
        action='store_true',
        default=False,
        help="Print the query and other debugging information.")
    args, remainder = parser.parse_known_args(args)

    if args.verbose:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    all_recipes = [
        os.path.splitext(p)[0] for p in os.listdir(RECIPE_DIR)
        if p.endswith('.py') if p != '__init__.py'
    ]

    if args.list:
        log.info('\n'.join(sorted(all_recipes)))
        return

    for recipe in args.recipes:
        if recipe not in all_recipes:
            log.error("recipe '{}' not found!".format(recipe))
            continue
        print(run_recipe(recipe, remainder, fmt=args.fmt))