예제 #1
0
파일: app.py 프로젝트: hdeweirdt/imp
def app():
    """
        Run the compiler
    """
    parser = ArgumentParser()

    parser.add_argument("-p", action="store_true", dest="profile",
                      help='Profile this run of the program')
    parser.add_argument("--dbg", dest = "debugger", action = "store_true",
                        help="Connect to the pydev debugger at startup")
    parser.add_argument("-d", "--debug", dest = "debug", action = "store_true",
                        help="Enable debug logging")
    parser.add_argument("-c", "--config", dest = "config_file", help="Use this config file")

    subcommands = parser.add_subparsers()

    for cmd in Commander.get_commands():
        sub_cmd = subcommands.add_parser(cmd)
        sub_cmd.set_defaults(command = cmd)

        arguments = Commander.get_arguments(cmd)
        for argument in arguments:
            if len(argument) == 3:
                sub_cmd.add_argument(argument[0], help = argument[1],
                                     dest = argument[2])
            elif len(argument) == 2:
                sub_cmd.add_argument(argument[0], help = argument[1])
            else:
                sub_cmd.add_argument(argument[0], help = argument[1],
                                     dest = argument[3], action = argument[2])


    options, other = parser.parse_known_args()
    options.other = other

    if options.debug:
        # TODO: fix logging
        logging.basicConfig(level=logging.DEBUG)

    if options.debugger:
        try:
            import pydevd; pydevd.settrace()
        except:
            print("Unable to start pydev debugger")

    Config.load_config(options.config_file)
    config = Config.get()

    if not hasattr(options, "command"):
        # show help
        parser.print_usage()
        return

    Commander.run(options.command, options, config)
예제 #2
0
파일: facts.py 프로젝트: hdeweirdt/imp
def get_fact(res, fact_name):
    """
        Get the fact with the given name from the database
    """
    cfg = Config.get()
    resource_id = Exporter.get_id(res)

    fact_value = None
    if cfg["config"]["offline"] == "true":
        fact_value = Offline.get().get_fact(resource_id, fact_name, Unknown(source = res))

    else:
        url = cfg["config"]["server"] + "/fact/%s?id=%s" % (fact_name,  resource_id)
        try:
            with request.urlopen(url) as f:
                fact_value = f.read().decode('utf-8')
        except:
            fact_value = Unknown(source = res)

    if cfg["config"]["unknown-dummy"] == "true" and isinstance(fact_value, Unknown):
        return dummy_value

    Stats.get("get fact").increment()
    return fact_value