Package teamwork :: Package doc :: Module gendoc
[hide private]
[frames] | no frames]

Source Code for Module teamwork.doc.gendoc

  1  import os 
  2  import string 
  3  import time 
  4   
  5  pydoc = "/usr/ucb/pydoc" 
  6  webroot = os.path.expanduser('~pynadath')+'/public_html' 
7 -def execute(cmd,dir=None):
8 """Executes the specified command (in a particular working 9 directory, if specified) and return the result""" 10 if dir: 11 oldDir = os.getcwd() 12 os.chdir(dir) 13 output = os.popen(cmd,'r') 14 data = output.read() 15 output.close() 16 if dir: 17 os.chdir(oldDir) 18 return data
19 20 21 ignore = ['CVS','gendoc.py','original','doc','old','images','examples', 22 'mei','data','pulp'] 23
24 -def generateJSTree(dir,depth=1):
25 defaultLnk = "/~pynadath%smain.html" % (webpath) 26 if depth == 1: 27 parent = 'foldersTree' 28 print '%s = gFld("Multiagent Python Classes","%s")' \ 29 % (parent,defaultLnk) 30 else: 31 parent = 'aux%d' % (depth-1) 32 cmd = pydoc + " -w "+ dir 33 execute(cmd) 34 cmd = 'mv '+dir+'.html '+webroot+webpath 35 execute(cmd) 36 dir = dir + '.' 37 files = os.listdir('.') 38 files.sort() 39 for f in files: 40 if f in ignore: 41 continue 42 name = string.split(f,'.') 43 if len(name) == 2: 44 root = name[0] 45 if name[1] == 'py' and root != '__init__': 46 link = '/~pynadath' + webpath + dir + root+'.html' 47 print 'insDoc(%s,gLnk("R","%s","%s"))' \ 48 % (parent,root,link) 49 cmd = pydoc+" -w "+ dir + root 50 execute(cmd) 51 cmd = 'mv '+dir+root+'.html '+webroot+webpath 52 execute(cmd) 53 else: 54 olddir = os.getcwd() 55 try: 56 os.chdir(f) 57 subdir = dir+f 58 except OSError: 59 subdir = None 60 if subdir: 61 print 'aux%d=insFld(%s,gFld("%s","%s"))' \ 62 % (depth,parent,f,defaultLnk) 63 generateJSTree(subdir,depth+1) 64 os.chdir(olddir)
65
66 -def generateTree(dir):
67 cmd = pydoc + " -w "+ dir 68 execute(cmd) 69 cmd = 'mv '+dir+'.html '+webroot+webpath 70 execute(cmd) 71 dir = dir + '.' 72 print '<UL>' 73 files = os.listdir('.') 74 files.sort() 75 for file in files: 76 if file in ignore: 77 continue 78 name = string.split(file,'.') 79 if len(name) == 2: 80 root = name[0] 81 if name[1] == 'py' and root != '__init__': 82 name = webpath + dir + root+'.html' 83 print '<LI>' 84 print '<A HREF="/~pynadath'+name+'">'+root+'</A>' 85 print '</LI>' 86 cmd = pydoc+" -w "+ dir + root 87 execute(cmd) 88 cmd = 'mv '+dir+root+'.html '+webroot+webpath 89 execute(cmd) 90 else: 91 olddir = os.getcwd() 92 try: 93 os.chdir(file) 94 subdir = dir+file 95 except OSError: 96 subdir = None 97 if subdir: 98 print '<LI>',file 99 generateTree(subdir) 100 print '</LI>' 101 os.chdir(olddir) 102 print '</UL>'
103 104 105 if __name__=='__main__': 106 ## Typical usage of this command: 107 ## cd ~www/teamcore/doc/COM-MTDP/src/ 108 ## python ~pynadath/workspace/teamwork/doc/gendoc.py > index.html 109 110 111 # If true, generates a JavaScript-based documentation browser; 112 # otherwise, generates a plain HTML browser 113 JSflag = 1 114 if JSflag: 115 116 path = os.path.expanduser('~pynadath') 117 webpath = '/doc/COM-MTDP/src/' 118 119 os.chdir(path) 120 os.chdir('workspace') 121 os.chdir('teamwork') 122 generateJSTree('teamwork') 123 else: 124 path = os.path.expanduser('~pynadath') 125 webpath = '/doc/COM-MTDP/src/' 126 print '<!doctype html public "-//w3c//dtd html 4.0 transitional//en">' 127 print '<html>' 128 print '<head>' 129 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">' 130 print '<TITLE>Com-MTDP Source Code Documentation</TITLE>' 131 print '</head>' 132 print '<body>' 133 print '<! bgcolor="#999999" TEXT="#000000" LINK="#B30E14" VLINK="#FFAF18" ALINK="#FFAF18">' 134 135 os.chdir(path) 136 os.chdir('python') 137 os.chdir('teamwork') 138 generateTree('teamwork') 139 print '<HR>' 140 print 'Auto-generated '+time.strftime('%x %X',time.localtime(time.time())) 141 print "</BODY></HTML>" 142