def parse_args(args): goals = OrderedSet() specs = OrderedSet() help = False explicit_multi = False def is_spec(spec): return os.sep in spec or ':' in spec for i, arg in enumerate(args): help = help or 'help' == arg if not arg.startswith('-'): specs.add(arg) if is_spec(arg) else goals.add(arg) elif '--' == arg: if specs: raise GoalError( 'Cannot intermix targets with goals when using --. Targets should ' 'appear on the right') explicit_multi = True del args[i] break if explicit_multi: spec_offset = len(goals) + 1 if help else len(goals) specs.update(arg for arg in args[spec_offset:] if not arg.startswith('-')) return goals, specs
def remove(self, name): """Removes the named goal from this phase's list of goals to attempt.""" goals = self.goals() for goal in goals: if goal.name == name: goals.remove(goal) return self raise GoalError( 'Goal %s does not exist in this phase, members are: %s' % (name, goals))
def install(self, goal, first=False, replace=False, before=None, after=None): """ Installs the given goal in this phase. The placement of the goal in this phases' execution list defaults to the end but its position can be influence by specifying exactly one of the following arguments: first: Places the goal 1st in the execution list replace: Removes all existing goals in this phase and installs this goal before: Places the goal before the named goal in the execution list after: Places the goal after the named goal in the execution list """ if int(first) + int(replace) + int(bool(before)) + int( bool(after)) > 1: raise GoalError( 'Can only specify one of first, replace, before or after') Phase._phase_by_goal[goal] = self g = self.goals() if replace: del g[:] g_names = map(lambda goal: goal.name, g) if first: g.insert(0, goal) elif before in g_names: g.insert(g_names.index(before), goal) elif after in g_names: g.insert(g_names.index(after) + 1, goal) else: g.append(goal) return self