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

Required fields are also shown as optional fields #78

Closed
lrq3000 opened this issue Mar 17, 2015 · 5 comments
Closed

Required fields are also shown as optional fields #78

lrq3000 opened this issue Mar 17, 2015 · 5 comments

Comments

@lrq3000
Copy link
Contributor

lrq3000 commented Mar 17, 2015

I don't know why, but my required fields are also shown as optional fields. This is very weird as they are required, so they shouldn't be shown twice on the GUI.

Here is a screenshot:

gooey-bug-repeated-fields

And here is the code used for argparse:

#== Commandline arguments
#-- Constructing the parser
if len(sys.argv) > 1 and sys.argv[1] == '--gui_launched':
    main_parser = gooey.GooeyParser(add_help=True, description=desc, epilog=ep, formatter_class=argparse.RawTextHelpFormatter)
else:
    main_parser = argparse.ArgumentParser(add_help=True, description=desc, epilog=ep, formatter_class=argparse.RawTextHelpFormatter)
# Required arguments
main_parser.add_argument('-i', '--input', metavar='/path/to/root/folder', type=is_dir, nargs=1, required=True,
                    help='Path to the root folder from where the scanning will occur.')
main_parser.add_argument('-d', '--database', metavar='/some/folder/ecc.txt', type=str, nargs=1, required=True, #type=argparse.FileType('rt')
                    help='Path to the file containing the ECC informations.')


# Optional general arguments
main_parser.add_argument('--max_block_size', type=int, default=255, required=False,
                    help='Reed-Solomon max block size (maximum = 255). It is advised to keep it at the maximum for more resilience (see comments at the top of the script for more info).')
main_parser.add_argument('-s', '--size', type=int, default=1024, required=False,
                    help='Headers block size to protect with ecc.')
main_parser.add_argument('-r', '--resilience_rate', type=float, default=0.3, required=False,
                    help='Resilience rate for files headers (eg: 0.3 = 30% of errors can be recovered but size of codeword will be 60% of the data block, thus the ecc file will be about 60% the size of your data).')
main_parser.add_argument('--replication_rate', type=int, default=1, required=False,
                    help='Replication rate, if you want to duplicate each ecc entry. This is better than just duplicating your ecc file: with a replication_rate >= 3, in case of a tampering of the ecc file, a majority vote can try to disambiguate and restore correct ecc entries (if 2 entries agree on a character, then it\'s probably correct).')
main_parser.add_argument('-l', '--log', metavar='/some/folder/filename.log', type=str, nargs=1, required=False,
                    help='Path to the log file. (Output will be piped to both the stdout and the log file)')
main_parser.add_argument('--stats_only', action='store_true', required=False, default=False,
                    help='Only show the predicted total size of the ECC file given the parameters.')

# Correction mode arguments
main_parser.add_argument('-c', '--correct', action='store_true', required=False, default=False,
                    help='Correct the files')
main_parser.add_argument('-o', '--output', metavar='/path/to/output/folder', type=is_dir, nargs=1, required=False,
                    help='Path of the folder where the corrected files will be copied (only corrupted files will be copied there).')
main_parser.add_argument('-e', '--errors_file', metavar='/some/folder/errorsfile.csv', type=str, nargs=1, required=False, #type=argparse.FileType('rt')
                    help='Path to the error file generated by RFIGC.py (this specify in csv format the list of files to check, and only those files will be checked and repaired). Do not specify this argument if you want to check and repair all files.')
main_parser.add_argument('--ignore_size', action='store_true', required=False, default=False,
                    help='On correction, if the file size differs from when the ecc file was generated, ignore and try to correct anyway (this may work with file where data was appended without changing the rest. For compressed formats like zip, this will probably fail).')

# Generate mode arguments
main_parser.add_argument('-g', '--generate', action='store_true', required=False, default=False,
                    help='Generate the ecc file?')
main_parser.add_argument('-f', '--force', action='store_true', required=False, default=False,
                    help='Force overwriting the ecc file even if it already exists (if --generate).')
main_parser.add_argument('--skip_size_below', type=int, default=None, required=False,
                    help='Skip files below the specified size (in bytes).')
main_parser.add_argument('--always_include_ext', metavar='txt|jpg|png', type=str, default=None, required=False,
                    help='Always include files with the specified extensions, useful in combination with --skip_size_below to keep files of certain types even if they are below the size. Format: extensions separated by |.')

#== Parsing the arguments
args = main_parser.parse_args(argv) # Storing all arguments to args

The full code is available here, and you can try it by launching "python header_ecc.py --gui":

https://github.com/lrq3000/pyFileFixity/blob/master/header_ecc.py#L350

I couldn't find the culprit. Maybe the getter for optional fields also get the required fields?

@chriskiehl
Copy link
Owner

Thanks for the detailed issue! The culprit is most likely in my parser code -- just an errant filter or something.

I'll investigate tonight!

Edit: FYI, in the mean time, if you need it to work right now, you could probably change the first two argument to be positional ones (e.g. get rid of the '-' in the name). Either way, will fix in a couple of hours.

@lrq3000
Copy link
Contributor Author

lrq3000 commented Mar 17, 2015

Ok thank you very much, I will try the new commit as soon as it's pushed :)

This isn't a major issue for me, I tried the GUI and it's perfectly working, it's just that it may be a bit confusing to the end users.

chriskiehl added a commit that referenced this issue Mar 17, 2015
@chriskiehl
Copy link
Owner

Fixed! I missed a not required condition in one of the loops like an idiot.

@lrq3000
Copy link
Contributor Author

lrq3000 commented Mar 18, 2015

Thank you very much, it works perfectly well now!

@chriskiehl
Copy link
Owner

Huzzah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants