def main(argv): global localtasks options = docopt.docopt(__doc__, argv, help=False) # need to set this before doing task-description or help if options['--deploydir']: tasklib.env['deploy_dir'] = options['--deploydir'] else: tasklib.env['deploy_dir'] = os.path.dirname(__file__) # first we need to find and load the project settings sys.path.append(tasklib.env['deploy_dir']) # now see if we can find localtasks # We deliberately don't surround the import by try/except. If there # is an error in localfab, you want it to blow up immediately, rather # than silently fail. if os.path.isfile(os.path.join(tasklib.env['deploy_dir'], 'localtasks.py')): import localtasks if options['--help']: print_help_text() return 0 if options['--task-description']: describe_task(options['<tasks>']) return 0 if options['--verbose'] and options['--quiet']: print "Cannot set both verbose and quiet" return 2 tasklib.env['verbose'] = options['--verbose'] tasklib.env['quiet'] = options['--quiet'] tasklib.env['noinput'] = options['--noinput'] try: import project_settings except ImportError: print >>sys.stderr, \ "Could not import project_settings - check your --deploydir argument" return 1 if localtasks is not None: if (hasattr(localtasks, '_setup_paths')): localtasks._setup_paths() # now set up the various paths required tasklib._setup_paths(project_settings, localtasks) # process arguments - just call the function with that name for arg in options['<tasks>']: fname, pos_args, kwargs = convert_task_bits(arg) # work out which function to call - localtasks have priority f = None if fname in localtasks_list(): f = getattr(localtasks, fname) elif fname in tasklib_list(): f = getattr(tasklib, fname) else: invalid_command(fname) return 2 # call the function try: f(*pos_args, **kwargs) except TasksError as e: print >>sys.stderr, e.msg return e.exit_code
except getopt.error, msg: print msg print "for help use --help" sys.exit(2) # process options for o, a in opts: if o in ("-h", "--help"): print_help_text() if o in ("-v", "--verbose"): verbose = True if o in ("-d", "--description"): describe_task(args) # process arguments - just call the function with that name tasklib._setup_paths() if (hasattr(localtasks, '_setup_paths')): localtasks._setup_paths() tasklib.env['verbose'] = verbose if len(args) == 0: print_help_text() for arg in args: task_bits = arg.split(':', 1) fname = task_bits[0] # work out which function to call - localtasks have priority f = None if fname in localtasks_list(): f = getattr(localtasks, fname) elif fname in tasklib_list(): f = getattr(tasklib, fname) else: invalid_command(fname)
def main(argv): global localtasks options = docopt.docopt(__doc__, argv, help=False) # need to set this before doing task-description or help if options['--deploydir']: tasklib.env['deploy_dir'] = options['--deploydir'] else: tasklib.env['deploy_dir'] = os.path.dirname(__file__) # first we need to find and load the project settings sys.path.append(tasklib.env['deploy_dir']) # now see if we can find localtasks # We deliberately don't surround the import by try/except. If there # is an error in localfab, you want it to blow up immediately, rather # than silently fail. if os.path.isfile(os.path.join(tasklib.env['deploy_dir'], 'localtasks.py')): import localtasks if options['--help']: print_help_text() return 0 if options['--task-description']: describe_task(options['<tasks>']) return 0 if options['--verbose'] and options['--quiet']: print "Cannot set both verbose and quiet" return 2 tasklib.env['verbose'] = options['--verbose'] tasklib.env['quiet'] = options['--quiet'] try: import project_settings except ImportError: print >>sys.stderr, \ "Could not import project_settings - check your --deploydir argument" return 1 if localtasks is not None: if (hasattr(localtasks, '_setup_paths')): localtasks._setup_paths() # now set up the various paths required tasklib._setup_paths(project_settings, localtasks) # process arguments - just call the function with that name for arg in options['<tasks>']: fname, pos_args, kwargs = convert_task_bits(arg) # work out which function to call - localtasks have priority f = None if fname in localtasks_list(): f = getattr(localtasks, fname) elif fname in tasklib_list(): f = getattr(tasklib, fname) else: invalid_command(fname) return 2 # call the function try: f(*pos_args, **kwargs) except TasksError as e: print >> sys.stderr, e.msg return e.exit_code