We Recommend

HTML: The Definitive Guide HTML: The Definitive Guide
They teach you that learning HTML is like learning any other language and that reading a book of rules can only take you so far. Readers begin writing what may be their first Web page just two pages into the book's second chapter. From there on, they provide a wide range of HTML coding to allow readers to learn from good examples. The book includes a handy "cheat sheet" of HTML codes for quick reference.


Posted By

rob_cowie on 03/09/08


Tagged

textmate plugin python fabric setuptools


Versions (?)


Fabric Plugin Diff


Published in: Other 


  1. diff --git a/fabric.py b/fabric.py
  2. index 5023d29..bd3cc1e 100644
  3. --- a/fabric.py
  4. +++ b/fabric.py
  5. @@ -28,6 +28,7 @@ import threading
  6. import time
  7. import types
  8. import datetime
  9. +import pkg_resources
  10.  
  11. try:
  12. import paramiko as ssh
  13. @@ -62,12 +63,46 @@ ENV = {
  14. 'fab_debug':False,
  15. }
  16.  
  17. +#TODO: find out why local eggs are not being loaded
  18. +#TODO: If they are, find out how to correctly define entry points in a module/package
  19. +#TODO: Think about how to 'inject' the current fabric context into operations without the user defining it
  20. +
  21. CONNECTIONS = []
  22. COMMANDS = {}
  23. OPERATIONS = {}
  24. STRATEGIES = {}
  25. _LAZY_FORMAT_SUBSTITUTER = re.compile(r'$((?P<var>w+?))')
  26.  
  27. +ENTRYPOINTS = {'fabric.commands': COMMANDS,
  28. + 'fabric.strategies': STRATEGIES,
  29. + 'fabric.operations': OPERATIONS}
  30. +
  31. +## Plugin discovery
  32. +def load_plugins(additional_paths=[]):
  33. + """Discover plugins registered to fabric entry points"""
  34. + ## 1. Create a pkg_resources environment in which to search for loadable 'distributions' (modules)
  35. + ## We always search the current working directory and sys.path
  36. + sys.path.append(os.getcwd())
  37. + cwd_environment = pkg_resources.Environment()
  38. + print os.getcwd()
  39. + cwd_environment.scan(os.getcwd())
  40. + for path in additional_paths:
  41. + cwd_environment.scan(os.path.abspath(os.path.expandvars(os.path.normpath(path))))
  42. + ## 2. Now search this environment for non-conflicting distributions and add to the working set (a global in pkg_resources module)
  43. + distributions, errors = pkg_resources.working_set.find_plugins(cwd_environment)
  44. + print len(distributions)
  45. + map(pkg_resources.working_set.add, distributions)
  46. + ## 3. Now iterate throught our entrypoints, looking for plugins registered in the working_set.
  47. + ## Load into our application registries if found
  48. + print list(pkg_resources.working_set.iter_entry_points(group='fabric.operations', name=None))
  49. + for entrypoint, registry in ENTRYPOINTS.items():
  50. + for obj in pkg_resources.working_set.iter_entry_points(group=entrypoint, name=None):
  51. + obj = obj.load()
  52. + print "===> ", obj.__name__
  53. + ## TODO: Is this correct? Adding operations to both OPERATIONS and __builtins__?
  54. + registry[obj.__name__] = obj
  55. + __builtins__[obj.__name__] = obj
  56. +
  57. #
  58. # Helper decorators:
  59. #
  60. @@ -166,6 +201,43 @@ def require(var, **kvargs):
  61. exit(1)
  62.  
  63. @operation
  64. +def prompt(varname, msg, validate=None, default=None):
  65. + """Display a prompt to the user. Input is set as an ENV variable.
  66. + If EOFError is raised, continue without setting the variable.
  67. +
  68. + validate is a callable that raises an exception on invalid inputs and returns
  69. + the input for storage in ENV. It may process the input.
  70. + i.e. lambda x: int(x) will ensure that the input is a valid integer and will cast it
  71. +
  72. + Example:
  73. + prompt('myvar', 'Please enter a value for myvar', default='SpamAndEggs')
  74. + """
  75. + if varname in ENV:
  76. + return
  77. +
  78. + ## Set the default value if default is callable or is not None
  79. + if callable(default):
  80. + default = default()
  81. + elif default:
  82. + default = default
  83. +
  84. + try:
  85. + input = raw_input('default: %sn%s: ' % (default, msg.strip()) )
  86. + if not input:
  87. + input = default
  88. +
  89. + ## Validate input
  90. + if callable(validate):
  91. + try:
  92. + input = validate(input)
  93. + except Exception:
  94. + raise
  95. +
  96. + set(**{varname: input})
  97. + except EOFError:
  98. + return
  99. +
  100. +@operation
  101. @run_per_host
  102. def put(host, client, env, localpath, remotepath, **kvargs):
  103. """Upload a file to the current hosts.
  104. @@ -936,6 +1008,7 @@ def _execute_commands(cmds):
  105.  
  106. def main(args):
  107. try:
  108. + load_plugins()
  109. print(__greeter__ % ENV)
  110. fabfile = _pick_fabfile()
  111. load(fabfile, fail='warn')
  112.  

Report this snippet 

You need to login to post a comment.