Guest User

Untitled

a guest
Nov 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. from paver.tasks import BuildFailure, environment
  2.  
  3. class ShortcutTaskFinder(object):
  4. """Find tasks by command name initials.
  5.  
  6. This allows the execution of a task specifying a unique `shortcut`
  7. made up with the first character of each word that compose the
  8. task name, assuming the usual ``_`` as separator.
  9.  
  10. For example, assuming there are the following tasks:
  11.  
  12. 1. current_user_name
  13. 2. current_project_name
  14. 3. last_message
  15. 4. last_login
  16.  
  17. The first task could be executed with ``current_user_name`` as
  18. usual, but also with ``cun``, but not with ``cu`` since that's
  19. ambiguous; the second with its full name, or with ``cpn``, or even
  20. ``cp`` since there's no ambiguity. The latter two respectively
  21. with ``lm`` and ``ll``.
  22. """
  23.  
  24. def get_task(self, taskname):
  25. all_tasks = environment.get_tasks()
  26. matches = [t for t in all_tasks
  27. if ''.join(w[0]
  28. for w in t.shortname.split('_')
  29. ).startswith(taskname)]
  30. if len(matches) > 1:
  31. matched_names = [t.name for t in matches]
  32. raise BuildFailure("Ambiguous task name %s (%s)" %
  33. (taskname, matched_names))
  34. elif matches:
  35. return matches[0]
  36.  
  37. def get_tasks(self):
  38. return []
  39.  
  40. # Install the additional finder
  41. environment.task_finders.append(ShortcutTaskFinder())
Add Comment
Please, Sign In to add comment