Ejemplo n.º 1
0
def fix_file_prompt(path, product_yaml, func, args):
    file_contents = open(path, 'r').read().split("\n")

    new_file_contents = _fixed_file_contents(path, file_contents, product_yaml,
                                             func)
    changes = file_contents != new_file_contents

    if not changes:
        return changes

    need_input = not args.assume_yes and not args.dry_run

    if need_input:
        print("====BEGIN BEFORE====")
        print_file(file_contents)
        print("====END BEFORE====")

    if need_input:
        print("====BEGIN AFTER====")
        print_file(new_file_contents)
        print("====END AFTER====")

    response = 'n'
    if need_input:
        response = input_func("Confirm writing output to %s: (y/n): " % path)

    if args.assume_yes or response.strip().lower() == 'y':
        changes = True
        with open(path, 'w') as f:
            for line in new_file_contents:
                print(line, file=f)
    else:
        changes = False
    return changes
Ejemplo n.º 2
0
def fix_file(path, product_yaml, func, args):
    file_contents = open(path, 'r').read().split("\n")
    if file_contents[-1] == '':
        file_contents = file_contents[:-1]

    yaml_contents = yaml.open_and_macro_expand(path, product_yaml)

    need_input = not args.assume_yes and not args.dry_run

    if need_input:
        print("====BEGIN BEFORE====")
        print_file(file_contents)
        print("====END BEFORE====")

    file_contents = func(file_contents, yaml_contents)

    if need_input:
        print("====BEGIN AFTER====")
        print_file(file_contents)
        print("====END AFTER====")

    response = 'n'
    if need_input:
        response = input_func("Confirm writing output to %s: (y/n): " % path)

    if args.assume_yes or response.strip().lower() == 'y':
        f = open(path, 'w')
        for line in file_contents:
            f.write(line)
            f.write("\n")
        f.flush()
        f.close()
Ejemplo n.º 3
0
def fix_file(path, product_yaml, func):
    file_contents = open(path, 'r').read().split("\n")
    if file_contents[-1] == '':
        file_contents = file_contents[:-1]

    yaml_contents = yaml.open_and_macro_expand(path, product_yaml)

    print("====BEGIN BEFORE====")
    print_file(file_contents)
    print("====END BEFORE====")

    file_contents = func(file_contents, yaml_contents)

    print("====BEGIN AFTER====")
    print_file(file_contents)
    print("====END AFTER====")
    response = input_func("Confirm writing output to %s: (y/n): " % path)
    if response.strip() == 'y':
        f = open(path, 'w')
        for line in file_contents:
            f.write(line)
            f.write("\n")
        f.flush()
        f.close()
Ejemplo n.º 4
0
def fix_file(path, product_yaml, func):
    file_contents = open(path, 'r').read().split("\n")
    if file_contents[-1] == '':
        file_contents = file_contents[:-1]

    yaml_contents = yaml.open_and_macro_expand(path, product_yaml)

    print("====BEGIN BEFORE====")
    print_file(file_contents)
    print("====END BEFORE====")

    file_contents = func(file_contents, yaml_contents)

    print("====BEGIN AFTER====")
    print_file(file_contents)
    print("====END AFTER====")
    response = input_func("Confirm writing output to %s: (y/n): " % path)
    if response.strip() == 'y':
        f = open(path, 'w')
        for line in file_contents:
            f.write(line)
            f.write("\n")
        f.flush()
        f.close()
Ejemplo n.º 5
0
 def _wait_for_continue(self):
     """ In case user requests to leave machine in failed state for hands
     on debugging, ask for keypress to continue."""
     input_func("Paused for manual debugging. Continue by pressing return.")