Exemple #1
0
def read_args(args):
    argdict = init_argdict()

    # If no arguments see if there is a YAML file
    if len(args) == 1:
        argdict = read_yaml_file("covid19.yaml")
        print("No arguments provided so using YAML")

    # If first argument is -h print help and return empty dict.
    elif args[1] == '-h':
        print_help()
        return {}

    # Check if first argument is a valid operation and carry on otherwise
    # first argument is invalid so return an empty dict.
    elif args[1] in valid_ops:
        argdict["operation"] = args[1]
    else:
        print(f"Invalid argument: {args[1]}")
        return {}

    # Read remaining arguments starting at second argument
    try:
        i = 2
        while i < len(args):
            if args[i] == '-c':
                argdict["countries"].append(args[i + 1])
                i += 1
            elif args[i] == '-p':
                argdict["province"] = args[i + 1]
                i += 1
            elif args[i] == '-d':
                argdict["fdate"] = args[i + 1]
                i += 1
            elif args[i] == '-f':
                argdict["fdate"] = args[i + 1]
                i += 1
            elif args[i] == '-t':
                argdict["tdate"] = args[i + 1]
                i += 1
            elif args[i] == '-g':
                argdict["graph"] = True
            elif args[i] == '-r':
                if args[i + 1] in valid_rates:
                    argdict["rate"] = args[i + 1]
                else:
                    print("Invalid rate: ", args[i + 1])
                i += 1
            elif args[i] == '-m':
                if args[i + 1] in valid_measures:
                    argdict["measure"] = args[i + 1]
                else:
                    print("Invalid measure: ", args[i + 1])
                i += 1
            else:
                print("Unknown argument", args[i])
            i += 1
    except IndexError:
        print("Invalid or missing argument")
    return argdict
Exemple #2
0
     elif '--log' == opt:
         bits = arg.split('=')
         assert len(bits) == 2
         name = bits[0]
         level = bits[1]
         if name=='ofexport':
             name = __name__
         logging.getLogger(name).setLevel (logging.__dict__[level])
     elif '--debug' == opt:
         bits = arg.split('=')
         assert len(bits) == 2
         name = bits[0]
         value = bits[1]
         set_debug_opt (name, value)
     elif opt in ('-?', '-h', '--help'):
         print_help ()
         sys.exit()
 
 if file_name == None:
     fmt = 'txt'
 else:
     assert file_name.find ('.') != -1, "filename has no suffix"
     dot = file_name.index ('.')
     fmt = file_name[dot+1:]
 
 if infile != None:
     root_project, root_context = read_json (infile)
 else:    
     root_project, root_context = build_model (find_database ())
 
 subject = root_project
Exemple #3
0
if __name__ == '__main__':
    argv, argc = sys.argv, len(sys.argv)
    assert argc >= 2, "githelper need at least 2 options"
    if argv[1] == 'find':
        if argv[2] == "-i":
            assert argc == 4, "input the commit id"
            assert len(argv[3]) >= 7, "the length of commit id at least 7"
            assert re.match(r"[a-f0-9]+", argv[3]), "incorrect commit id"
            search_commit_id(argv[3])
        else:
            assert argc == 3, "what to find?"
            search_content_in_commit_info(argv[2])
    elif argv[1] == 'applyconflict':
        assert argc == 2, "extra options are found"
        apply_solutions()
    elif argv[1] == 'readconflict':
        assert argc == 2, "extra options are found"
        show_conflicts()
    elif argv[1] == 'status':
        assert argc == 2, "extra options are found"
        collect_modifications()
    elif argv[1] == 'statistic':
        git_log_statistic(argv[2:])
    elif argv[1] == "blame":
        assert argc == 3, "need 2 parameters, but {} provided".format(argc-1)
        git_blame(argv[2])
    elif argv[1] == '--help':
        print_help()
    else:
        assert False, "unknow option for '{}'".format(argv[1])
Exemple #4
0
    with open("prefs.json", "w") as f:
        json.dump(prefs, f)
else:
    with open("prefs.json", "r") as f:
        prefs = json.load(f)

with open("data.json", "r") as f:
    data = json.load(f)

while True:
    full_input = input()
    inp = full_input.split()
    cmd = inp[0]

    if cmd == "help":
        if len(inp) == 2:
            help.print_cmd_help(inp[1])
        else:
            help.print_help()
    elif not cmd in help.get_cmd_list():
        print("Command not found: " + cmd)
    elif help.get_arg_count(cmd) + 1 != len(inp):
        print(help.get_usage(cmd))
    else:
        if cmd in significant_commands:
            prev_data = copy.deepcopy(data)
        success = use_command(inp)
        if cmd in significant_commands and success:
            with open("dump.txt", "a") as f:
                f.write(full_input + "\n")
            previous_data = prev_data
def run(args):
    options, remainder = getopt(args, '-h',
                                ['help',
                                 'where=',
                                 'select=',
                                 'from=',
                                 'fromdelimiter=',
                                 'sortedby=',
                                 'to=',
                                 'todelimiter=',
                                 'limit=',
                                 'discretize'])
    options = dict(options)
    print(options)
    source_delimiter = ','
    target_delimiter = ','
    rows = None
    if '--help' in options or '-h' in options and len(options) == 1:
        print_help()

    # Delimiters
    if '--fromdelimiter' in options:
        source_delimiter = options['--fromdelimiter']

    if '--todelimiter' in options:
        target_delimiter = options['--todelimiter']

    if '--from' in options:
        from_path = options['--from']
        rows = from_(path=from_path, delimiter=source_delimiter)
        columns = rows[0].keys()

    if '--where' in options:
        if '==' in options['--where']:
            operands = options['--where'].split('==')
            operator = equality
        elif '!=' in options['--where']:
            operands = options['--where'].split('!=')
            operator = inequality

        left_operand = operands[0]
        right_operand = operands[1]

        if (left_operand in columns and
                right_operand in columns):
            rows = [row
                    for row in rows
                    if operator(row[left_operand], row[right_operand])]
        elif left_operand in columns:
            rows = [row
                    for row in rows
                    if operator(row[left_operand], right_operand)]
        elif right_operand in columns:
            rows = [row
                    for row in rows
                    if operator(left_operand, row[right_operand])]

    if '--sortedby' in options:
        columns_to_sort_by = options['--sortedby'].split(',')
        rows = sort(rows, columns_to_sort_by)

    if '--limit' in options:
        limit = int(options['--limit'])
        rows = rows[:limit]

    assign_failure_cause(rows)
    if '--discretize' in options:
        discretize_no_places(rows)
        discretize_no_transitions(rows)

    if '--select' in options:
        columns_to_select = options['--select'].replace("'", "").split(',')
        print(columns_to_select)
        rows = select(rows, columns_to_select)

    if '--unique' in options:
        raise NotImplementedError('--unique not implemented')
        unique_rows = []
        for row in rows:
            if not any([urow['Error'] == row['Error'] for urow in new_rows]):
                new_rows.append(row)
        rows = unique_rows

    if '--to' in options:
        to_path = options['--to']
        to(rows, to_path, target_delimiter)

    #for row in rows:
    #    print(row)
    print_stats(rows)
    try:
        print_report(rows)
    except:
        print(
            'Unable to print report. '
            'Source may not contain log information.')

    print('--discretize' in options)
    return rows