Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diff support for other files types and directories #10

Open
lowell80 opened this issue Apr 20, 2018 · 0 comments
Open

Add diff support for other files types and directories #10

lowell80 opened this issue Apr 20, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@lowell80
Copy link
Member

def do_diff(args):
    ''' Compare two configuration files. '''
    # Todo:  Allow fallback to text comparisons for non-conf files.
    # Todo:  Eventually support directory (or recursive?) diffs too.
    parse_args = dict(dup_stanza=args.duplicate_stanza, dup_key=args.duplicate_key,
                      keep_comments=args.comments, strict=True)
    # Parse all config files
    try:
        cfg1 = parse_conf(args.conf1, **parse_args)
        cfg2 = parse_conf(args.conf2, **parse_args)
    except IOError, e:
        sys.stderr.write("Unable to open conf file.  {}\n".format(e.message))
        return EXIT_CODE_NO_SUCH_FILE
    except ConfParserException, e:
        sys.stderr.write("Unable to parse conf file.  {}\n".format(e))
        # We don't distinguish between bad conf files and safety checks here.
        return EXIT_CODE_BAD_CONF_FILE
    diffs = compare_cfgs(cfg1, cfg2)
    rc = show_diff(args.output, diffs, headers=(args.conf1, args.conf2))
    if rc == EXIT_CODE_DIFF_EQUAL:
        sys.stderr.write("Files are the same.\n")
    elif rc == EXIT_CODE_DIFF_NO_COMMON:
        sys.stderr.write("No common stanzas between files.\n")
    return rc
@lowell80 lowell80 added the enhancement New feature or request label Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant