def main():
    '''If run from the command line, get command line option and arguments.'''
    from optparse import OptionParser

    logging.basicConfig(format="%(levelname)s: %(message)s")

    parser = OptionParser(usage="%prog [options] image1 [,image2...]")
    parser.set_defaults(overwrite=False, extension=None, color="alpha",
                        verbose=False)
    parser.add_option("-o", "--overwrite", action="store_true",
                      help="Overwrite all files.  Default is to not overwrite "+
                           "any files and instead generate new files with a "+
                           "'POT' extension.  This option cannot be combined "+
                           "with the 'extension' option.")
    parser.add_option("-e", "--extension", 
                      help="Set the extension added before the filetype.  The "+
                           "default is to add the 'pot' extension, ie. "+
                           "'image1.png' becomes 'image1.pot.png'.  This "+
                           "cannot be combined with the 'overwrite' option.")
    parser.add_option("-c", "--color", type="choice", 
                      choices=("alpha", "black", "white"),
                      help="Choose the padding color.  Default is 'alpha'.")
    parser.add_option("-v", "--verbose", action="store_true",
                      help="Show extra information.")
    (opts, args) = parser.parse_args()

    if opts.verbose:
        logging.root.setLevel(logging.INFO)

    # ---Translate color string to RGBA tuple---
    assert opts.color.lower() in ("alpha", "black", "white")
    if opts.color.lower() == "alpha":
        color = (0,) * 4
    elif opts.color.lower() == "black":
        color = (0, 0, 0, 255)
    else:
        color = (255,) * 4

    # ---Decide between overwriting or adding an extension and run convert---
    if opts.overwrite and opts.extension:
        logging.error("You must specify ONLY an extension or overwrite.")
        parser.print_help()
        sys.exit(1)
    if not args:
        parser.print_usage()
        return 0
    if opts.overwrite:
        return convert(args, True, None, color)
    else:
        if opts.extension:
            if not isinstance(opts.extension, basestring):
                logging.error("'extension' must be a string.")
                parser.print_help()
                return 1
            return convert(args, False, opts.extension, color)
        else:
            return convert(args, False, "pot", color)
If run from the command line, get command line option and arguments.
recipes/Python/576416_Pad_images_poweroftwo/recipe-576416.py