设置参数进行启动的Python脚本模板

# coding:utf-8
from optparse import OptionParser



def migrate_func():
    print 'You give the migrate arg\n'

def show_func():
    print 'You give the show arg-s\n'

def grasp_func():
    print 'You give the grasp arg-g\n'

def parse_func():
    print 'You give the parse arg-p\n'

def version_func():
    print 'You give the versin arg-v\n'

if __name__ == '__main__':
    _cmd_parser = OptionParser()
    _opt = _cmd_parser.add_option
    _opt('-g','--grasp',action='store_true',default=False,help='grasp the html file')
    _opt('-p','--parse',action='store_true',default=False,help='parse the html have been scrapied')
    _opt('-m','--migrate',action='store_true',default=False,help='migrate the result to DB')
    _opt('-s','--show',action='store_true',default=False,help='show the introduction of this script')
    _opt('-v','--version',action='store_true',default=False,help='sow the version')

    _cmd_options,_cmd_args= _cmd_parser.parse_args()

    if _cmd_options.migrate:
        migrate_func()

    if _cmd_options.grasp:
        grasp_func()

    if _cmd_options.parse:
	parse_func()

    if _cmd_options.version:
        version_func()

    if _cmd_options.show:
	show_func()


posted @ 2016-06-30 09:58  Tacey Wong  阅读(462)  评论(0编辑  收藏  举报