Package turbogears :: Package command :: Module info

Source Code for Module turbogears.command.info

 1  """Commands for listing TurboGears default and extension packages info""" 
 2   
 3  try: 
 4      from email.parser import Parser 
 5  except ImportError: # Python < 2.5 
 6      from email.Parser import Parser 
 7   
 8  import pkg_resources 
 9   
10  entrypoints = {"tg-admin Commands" : "turbogears.command", 
11      "Template Engines" : "python.templating.engines", 
12      "Widget Packages" : "turbogears.widgets", 
13      "TurboGears Extensions" : "turbogears.extensions", 
14      "Identity Providers" : "turbogears.identity.provider", 
15      "Visit Managers" : "turbogears.visit.manager", 
16      "Toolbox Gadgets" : "turbogears.toolboxcommand"} 
17   
18  parsestr = Parser().parsestr 
19   
20 -def retrieve_pkg_info(distribution):
21 """Retrieve parsed package info from distribution.""" 22 return parsestr(distribution.get_metadata('PKG-INFO'))
23 24
25 -def retrieve_url(distribution):
26 """Retrieve URL from distribution.""" 27 try: 28 info = retrieve_pkg_info(distribution) 29 except Exception: 30 url = None 31 else: 32 url = info['Home-page'] or info['Url'] or info['Download-Url'] 33 return url
34 35 45 46
47 -def retrieve_info(with_links=False):
48 """Retrieve default and extension packages info.""" 49 format = with_links and add_link or str 50 # get default packages 51 packages = [format(pkg) for pkg in pkg_resources.require("Turbogears")] 52 # get extension packages 53 plugins = {} 54 for name, pointname in entrypoints.items(): 55 plugins[name] = ["%s (%s)" % (entrypoint.name, format(entrypoint.dist)) 56 for entrypoint in pkg_resources.iter_entry_points(pointname)] 57 return packages, plugins
58 59
60 -class InfoCommand:
61 """Shows version info for debugging.""" 62 63 desc = "Show version info" 64
65 - def __init__(self,*args, **kwargs):
66 pass
67
68 - def run(self):
69 print """TurboGears Complete Version Information 70 71 TurboGears requires: 72 """ 73 packages, plugins = retrieve_info() 74 for p in packages: 75 print '*', p 76 for name, pluginlist in plugins.items(): 77 print "\n", name, "\n" 78 for plugin in pluginlist: 79 print '*', plugin
80