Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from paver.tasks import BuildFailure, environment
- class ShortcutTaskFinder(object):
- """Find tasks by command name initials.
- This allows the execution of a task specifying a unique `shortcut`
- made up with the first character of each word that compose the
- task name, assuming the usual ``_`` as separator.
- For example, assuming there are the following tasks:
- 1. current_user_name
- 2. current_project_name
- 3. last_message
- 4. last_login
- The first task could be executed with ``current_user_name`` as
- usual, but also with ``cun``, but not with ``cu`` since that's
- ambiguous; the second with its full name, or with ``cpn``, or even
- ``cp`` since there's no ambiguity. The latter two respectively
- with ``lm`` and ``ll``.
- """
- def get_task(self, taskname):
- all_tasks = environment.get_tasks()
- matches = [t for t in all_tasks
- if ''.join(w[0]
- for w in t.shortname.split('_')
- ).startswith(taskname)]
- if len(matches) > 1:
- matched_names = [t.name for t in matches]
- raise BuildFailure("Ambiguous task name %s (%s)" %
- (taskname, matched_names))
- elif matches:
- return matches[0]
- def get_tasks(self):
- return []
- # Install the additional finder
- environment.task_finders.append(ShortcutTaskFinder())
Add Comment
Please, Sign In to add comment