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