Menu for pictures average program I made a little script that takes images and averages / aligns them.

The script grew and now I have different options bound to the program, it can calculate the average for RGB or gray scale pictures and can create test data set to check if it works on different machines.

At the beginning I define the help message, yet isn't there a better way to store it?

def main(argv):
    help_message  = "---------------- HELP ----------------\n"
    help_message += "Usage:\n"
    help_message += "pythong main_avg.py -d path/to/folder/ -cd -cdrgb -avg -avgrgb -graph\n"
    help_message += "  -d | --directory: path to any directory, the program will generate the dataset, or calculate the average in the folder.\n"
    help_message += "  -cd: creates gray scale dataset.\n"
    help_message += "  -cdrgb: creates rgb scale dataset.\n"
    help_message += "  -avg: calculates the alignment and average of the picture in greyscale mode.\n"
    help_message += "  -avgrgb: calculates and outputs a rgb average, needs the data from -avg.\n"
    help_message += "  -graph: calculates and outputs the movement and angles graphs, needs the data from -avg.\n"
    help_message += "  -s: sound at the end of process.\n"    
    help_message += "  -h, --help: prints this.\n"


Then I print the starting script, just because

    path, name, ext = get_pathname(argv[0])
    print("Script:", name + ext, "started")


Then I process the arguments

    # get the arguments
    opts = argv[1:]

    folder = ""
    create_dataset = False
    create_rgb_dataset = False
    avgerage_gray = False
    average_rgb = False
    produce_graphs = False
    sound_of_silence = False


    if len(opts) == 1 and opts in ('-h', '--help'):
        print(help_message)
    else:
        nopt = 0
        while nopt &lt; len(opts):
            opt = opts[nopt]
            if opt in ("-d", "--directory"):
                try:
                    nopt += 1 
                    folder = opts[nopt]
                except IndexError:
                    pass
            if opt == "-cd":
                create_dataset = True
            if opt == "-cdrgb":
                create_rgb_dataset = True
            if opt == "-avg":
                avgerage_gray = True
            if opt == "-avgrgb":
                average_rgb = True
            if opt == "-graph":
                produce_graphs = True
            if opt == "-s":
                sound_of_silence = True
            nopt += 1


The program checks if one option is chosen, and if so it start the subroutine.

    inopt = [create_dataset, create_rgb_dataset, avgerage_gray, average_rgb, produce_graphs]

    if isdir(folder):
        if all(opt == False for opt in inopt):
            print("No options chosen")
            print("")
            print(help_message)
        if create_dataset:
            run_create_test_dataset(folder)

        if create_rgb_dataset:
            run_create_rgb_dataset(folder)

        if avgerage_gray:
            run_average_gray(folder)

        if average_rgb:
            run_average_rgb(folder)

        if produce_graphs:
            run_produce_graphs(folder)   

        if sound_of_silence:
            import winsound
            Freq = 2500 # Set Frequency To 2500 Hertz
            Dur = 1000 # Set Duration To 1000 ms == 1 second
            winsound.Beep(Freq,Dur)            
    else:
        print("-d option is not a folder")
        print("")
        print(help_message)


Is the first time I build a argumented main, so I would love any suggestions!
I personally would suggest using argparse.
To make a simple one would be fairly easy, and could only require add_argument.
You only really need to know:


The first to arguments store a single letter argument such as -d, and a long version such as --directory.
It takes an argument of action='store_true' to make the variable a flag.
It takes help as the help text.


And so you could use:

import argparse

parser = argparse.ArgumentParser(prog='main avg')
parser.add_argument('-d', '--directory',
                    help='path to any directory, the program will generate the dataset, or calculate the average in the folder.')
parser.add_argument('--cd', action='store_true',
                    help='creates gray scale dataset.')
parser.add_argument('--cdrgb', action='store_true',
                    help='creates rgb scale dataset.')
parser.add_argument('--avg', action='store_true',
                    help='calculates the alignment and average of the picture in greyscale mode.')
parser.add_argument('--avgrgb', action='store_true',
                    help='calculates and outputs a rgb average, needs the data from -avg.')
parser.add_argument('--graph', action='store_true',
                    help='calculates and outputs the movement and angles graphs, needs the data from -avg.')
parser.add_argument('-s', action='store_true',
                    help='sound at the end of process.')

args = parser.parse_args()
if args.cd:
    run_create_test_dataset(args.directory)
elif args.cdrgb:
    run_create_rgb_dataset(args.directory)
...
else:
    print('No options chosen')


After this, you may want to look into add_mutually_exclusive_group, if they're mutually exclusive.