optparse [解析参数及标准提示]

    import os, sys
    import time
    import optparse
    # python aaa.py -t file -p /etc/opt -o aaaaa

    def do_fiotest( type, path, output,):
        print type, path, output,

    def main():
        parser = optparse.OptionParser()
        parser.add_option('-t', '--type', dest = 'type', default = None, help = 'test type[file, device]')
        parser.add_option('-p', '--path', dest = 'path', default = None, help = 'test file path or device path')
        parser.add_option('-o', '--output', dest = 'output', default = None, help = 'result dir path')

        (o, a) = parser.parse_args()

        if None == o.type or None == o.path or None == o.output:
            print "No device or file or output dir"
            return -1

        if 'file' != o.type and 'device' != o.type:
            print "You need specify test type ['file' or 'device']"
            return -1

        do_fiotest(o.type, o.path, o.output)
        print "Test done!"


    if __name__ == '__main__':
        main()
文档更新时间: 2018-11-21 17:28   作者:RuM