Source

# -*- coding: utf-8 -*-""""""importsysimportosfrom.commandmentimportCommander,OrderError,QGVERSION=('0','3','1','beta')defget_version(command=''):version='.'.join(elementforelementinVERSION[:3])return'{0} {1}'.format(command,version)ifcommandelseversiondefsir_yes_sir(module='',doc='',options=(),version='',argv=None):"""Launches the right order or displaying the help for a command or an order directly from command line. """argv=argvifargvelsesys.argv[:]command=os.path.basename(argv[0])module=moduleifmoduleelsecommandcommander=Commander(module,doc=doc,command=command)# global options and app version made available for the ordersQG.options=optionsQG.version=versionno_arg=len(argv)==1needs_help=notno_argandargv[1]=='help'global_help=needs_helpandlen(argv)==2order_help=needs_helpandlen(argv)>2ifno_argorglobal_help:returncommander.explanations()else:order_name=argv[1]ifnotorder_helpelseargv[2]try:order=commander[order_name]exceptKeyErrorase:returncommander(argv[1:])else:iforder_help:returnorder.explanations()else:returnorder(argv[2:])defcall_order(module_name,order_name,*args,**kwargs):"""Calls an order from another python script directly """commander=Commander(module_name)order=commander[order_name]returnorder.execute(*args,**kwargs)