/[gzz]/gzz/metacode/umldoc.py
ViewVC logotype

Diff of /gzz/metacode/umldoc.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by humppake, Mon Dec 16 03:53:26 2002 UTC revision 1.2 by humppake, Tue Dec 17 14:11:38 2002 UTC
# Line 16  Line 16 
16  #  #
17    
18  import sys, os  import sys, os
19  from umltool import *  import docutils.core
20  from umlrst import *  import umltool, umlrst
21    
22  # must be run in the main directory of gzz module  # must be run in the main directory of gzz module
23    
24  settings['tmpdir'] = 'doc/uml'  umltool.settings['css'] = 'doc/gzz.css'
 settings['to_root'] = ''  
 settings['css'] = 'doc/gzz.css'  
25    
26  os.putenv("MPINPUTS", "metacode")  #Environmental variable MPINPUTS should be relative to tmpdir, or absolute path.
27  os.putenv("TEXMFOUTPUT", settings['tmpdir'])  os.putenv("MPINPUTS", "../../metacode")
   
 def run_documl(path):  
     depth = path.count("/")  
     settings['to_root'] = "".join(["../" for i in range(depth)])  
28    
29    #TEXFMOUTPUT should change the output directory of metapost, but it didn't
30    #seem to do that. Instead of this, metapost is currently run in tmpdir.
31    #os.putenv("TEXMFOUTPUT", umltool.settings['tmpdir'])
32    
33    def run(path):
34        set_to_root(path)
35        
36      if os.path.isdir(path):      if os.path.isdir(path):
37          if not path.endswith("/"): settings['to_root'] += "../"                  if not path.endswith("/"): umltool.settings['to_root'] += "../"        
38    
39      elif os.path.isfile(path) or os.path.isfile(path+'.rst'):      elif os.path.isfile(path) or os.path.isfile(path+'.rst'):
40          #the first pass - converts rst into html          rst2html(path)
41          if path.endswith(".rst"): path = path[0:len(path)-4]          embed_diagram(path)
42          args = '-stg --stylesheet '+settings['to_root']+settings['css'] \  
43                 +' '+path+'.rst '+path+'.html'  def set_to_root(path):
44          docutils.core.publish_cmdline(writer_name='html', argv=args.split())      depth = path.count("/")
45        umltool.settings['to_root'] = "".join(["../" for i in range(depth)])
46          #the second pass - adds uml into html  
47          if os.path.isfile(path+".html"):  def rst2html(path):
48              html = open(path+".html").read()      #the first pass - converts rst into html
49              out = open(path+".html", "w")                  if path.endswith(".rst"): path = path[0:len(path)-4]
50        args = '-stg --stylesheet '+umltool.settings['to_root']\
51               +umltool.settings['css']+' '+path+'.rst '+path+'.html'
52        docutils.core.publish_cmdline(writer_name='html', argv=args.split())
53    
54    def create_diagram(diagram):
55        umltool.run(diagram)
56    
57    def embed_diagram(path):
58        if not umltool.settings.has_key('to_root'):
59            set_to_root(path)
60            
61        #the second pass - adds uml into html
62        if path.endswith(".rst"): path = path[0:len(path)-4]
63        print path
64        if os.path.isfile(path+".html"):
65            html = open(path+".html").read()
66            out = open(path+".html", "w")            
67            insert = html.find("<!-- UML:")
68            while insert > -1:
69                out.write(html[0:insert]);
70                name = html[insert+9:html.find(" ", insert+9)]
71                create_diagram(name)
72                imgmap = open(umltool.settings['tmpdir']+"/"+name+".html").read()
73                out.write("<map name=\""+name+"\">\n")
74                out.write(imgmap[imgmap.find('>',imgmap.find('<map'))+1:\
75                                 imgmap.find('</map>')])
76                out.write("</map>\n")
77                out.write("<img src=\""+umltool.settings['to_root']\
78                          +umltool.settings['tmpdir']+"/"+name+".png"\
79                          +"\" usemap=\""+name+"\"/>")
80                html = html[html.find("-->", insert)+3:len(html)]
81              insert = html.find("<!-- UML:")              insert = html.find("<!-- UML:")
82              while insert > -1:          out.write(html)
83                  out.write(html[0:insert]);          out.close()
                 name = html[insert+9:html.find(" ", insert+9)]  
                 imgmap = open(settings['tmpdir']+"/"+name+".html").read()  
                 out.write("<map name=\""+name+"\">\n")  
                 out.write(imgmap[imgmap.find('>',imgmap.find('<map'))+1:\  
                                  imgmap.find('</map>')])  
                 out.write("</map>\n")  
                 out.write("<img src=\""+settings['to_root']\  
                           +settings['tmpdir']+"/"+name+".png"\  
                           +"\" usemap=\""+name+"\"/>")  
                 html = html[html.find("-->", insert)+3:len(html)]  
                 insert = html.find("<!-- UML:")  
             out.write(html)  
             out.close()  
84    
85  for path in sys.argv[1:]:  for path in sys.argv[1:]:
86      run_documl(path)      run(path)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26