def collectOptionsFromScript(script_name):
    '''collect options used in script *script_name*.'''

    # call other script
    prefix, suffix = os.path.splitext(script_name)

    dirname = os.path.dirname(script_name)
    basename = os.path.basename(script_name)[:-3]

    if os.path.exists(prefix + ".pyc"):
        os.remove(prefix + ".pyc")

    # check if script contains getopt
    with IOTools.openFile(script_name) as inf:
        if "getopt" in inf.read():
            E.warn("script %s uses getopt directly" % script_name)
            return []

    try:
        module = imp.load_source(basename, script_name)
    except ImportError, msg:
        E.warn('could not import %s - skipped: %s' % (basename, msg))
        return []

    E.Start = LocalStart

    try:
        module.main(argv=["--help"])
    except AttributeError:
        E.warn("no main method in %s" % script_name)
        return []
    except SystemExit:
        E.warn("script exits - possibly does not use E.Start()")
        return []
    except DummyError:
        pass

    result = []
    for option in PARSER.option_list:
        # ignore options added by optparse
        if option.dest is None:
            continue

        optstring = option.get_opt_string()
        if optstring.startswith("--"):
            optstring = optstring[2:]
        result.append(optstring)

    return result
dataset/ETHPy150Open CGATOxford/cgat/scripts/cgat_get_options.py/collectOptionsFromScript/original