Ejemplo n.º 1
0
def main(argv):
    """The main function that will be called from command line.

    Args:
        argv (str list): A list of string arguments taken from command line. 
            Can have zero extra arguments or one (specifying a file path or a 
            directory).

    Returns:
        (void): Does not return.
    """
    if len(argv) < 2:
        # In this case, find all .json files in the current directory.
        for conf_file in [f for f in os.listdir('.') if f.endswith('.json')]:
            try:
                genie(Configuration.from_json_file(conf_file))
            except Exception, e:
                print(str(e))
            else:
                pass
Ejemplo n.º 2
0
    Returns:
        (void): Does not return.
    """
    if len(argv) < 2:
        # In this case, find all .json files in the current directory.
        for conf_file in [f for f in os.listdir('.') if f.endswith('.json')]:
            try:
                genie(Configuration.from_json_file(conf_file))
            except Exception, e:
                print(str(e))
            else:
                pass
    elif os.path.isfile(argv[1]):
        # In this case, read in the file and run genie.
        genie(Configuration.from_json_file(argv[1]))
    elif os.path.isdir(argv[1]):
        # In this case, find all .json files in the given directory.
        for conf_file in [
                f for f in os.listdir(argv[1]) if f.endswith('.json')
        ]:
            try:
                genie(Configuration.from_json_file(conf_file))
            except Exception, e:
                traceback.print_tb(sys.exc_info()[2])
                print(str(e))
            else:
                pass
    else:
        print('USAGE')
        sys.exit(1)