cedricbonhomme/Stegano

Need to use argparse module instead of optparse for handling command line options due to mutually exclusive options, etc.

Closed this issue · 2 comments

In lsb command, there are options which are mutually exclusive. Such as

  • --reveal and --hide
  • -b and -o
  • -f and -m

If I type:

lsb --reveal --hide -i somefile.png -b someotherfile.png -o ohthatfile.png -f muchfile.dat -m "suchmessage"

I think that will try to apply options.hide but it's not possible because -m and -b are given at the same time so secret variable is not defined.

Yes, it's a wrong usage of the command. But in that case, user should be informed in a better way. Because in this case, user does not know your variables. So (s)he won't understand what secret is.

Other than that, the default values for parser should be removed and your options should be tagged as required arguments. I think --hide and --reveal commands have their own sub-parsers.
(I don't know what Lenna.png is to be honest 😄)

Also, optparse is deprecated since 2.7. argparse is a better solution for the conflict handling I explained above.

I'll try to send a PR if I can get enough time.

EDIT: Just as we expected. -m and -b shouldn't be given at the same time.

Traceback (most recent call last):
  File "/usr/local/bin/lsb", line 71, in <module>
    img_encoded = lsb.hide(options.input_image_file, secret)
NameError: name 'secret' is not defined

Indeed I know that the management of arguments is awful.
I'll try to improved it because there are also a lot of redundancies between modules. This should also be improved.

I've began to implement the changes I wanted for lsb and lsb-set modules. For the moment, I am not exactly sure if this is what I want. Anyway, it's better now.

I will now harmonize for the other sub-modules of Stéganô. I'd like to factorize more the code.
The option '-b' has been replaced by '-o' for consistency.
I'll probably also remove the '-o' argument of the 'hide' sub-parser.