Author: DerekRhodes
Date: 2008-02-28 09:54:13 -0500 (Thu, 28 Feb 2008)
New Revision: 1008

Added:
   trunk/pysoy/scripts/api_sherlock.py
Log:
a script that prints the hierarchy of modules

Copied: trunk/pysoy/scripts/api_sherlock.py (from rev 1002, 
trunk/pysoy/scripts/exceptions.py)
===================================================================
--- trunk/pysoy/scripts/api_sherlock.py                         (rev 0)
+++ trunk/pysoy/scripts/api_sherlock.py 2008-02-28 14:54:13 UTC (rev 1008)
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+''' api_sherlock.py
+    prints a decent overview of the projects structure.
+'''
+__credits__ = '''Copyright (C) 2006,2007,2008 PySoy Group
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, see http://www.gnu.org/licenses
+'''
+__author__  = 'PySoy Group'
+__date__    = 'Last change on '+ \
+              '$Date$'[7:-20]+ \
+              'by '+'$Author$'[9:-2]
+__version__ = 'Trunk (r'+'$Rev$'[6:-2]+')'
+
+import sys
+
+def get_attributes(aModule, shortList):
+  attributes  = [att for att in dir(aModule) if '_' not in att]
+  if '.' not in aModule.__name__: print '\t',
+  print aModule.__name__
+  
+  for att in attributes:
+    try:
+      attType = type(aModule.__getattribute__(att)).__name__
+    except:
+      continue
+    
+    if attType == 'module' or attType == 'type':
+      if (aModule,att) not in shortList:
+        shortList.append((aModule,att))
+        get_attributes(aModule.__getattribute__(att), shortList)
+        
+if __name__=="__main__":
+  shortList = []
+  try:
+    rootModule  = __import__(sys.argv[1])
+  except:
+    print "*\n*\n*\n\nYou'll need to supply an importable module name"
+    print "example: $ python sherlock.py soy"
+    print "or     : $ python sherlock.py soy | less\n\n*\n*"
+  get_attributes(rootModule, shortList)
+  

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to