aboutsummaryrefslogtreecommitdiff
path: root/pow/POW-0.7/docs/doc.py
blob: 0a0e4450e806673dc0993b8adf9d8d2ada6699fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python

import sys, string, os, commands
 
class DocError(Exception):
   def __init__(self, mesg):
      self.mesg = mesg

   def __str__(self):
      return self.mesg

class Extractor:
   def __init__(self, module):
      exec('import %s' % module)
      self.module = eval(module)

   def get(self):
      fragments = ''
      for doc in self.module._docset():
         fragments += doc

      return '<moduleSet>' + fragments + '</moduleSet>' 


if __name__ == '__main__':
   if len(sys.argv) < 2:
      raise DocError( 'module name must be supplied')

   lines = ''
   for mod in sys.argv[1:]:
      print 'processing module', mod
      ex = Extractor(mod)
      lines += ex.get()

   file = open('fragments.xml', 'w')
   file.write('%s\n%s\n%s' % ('<collection>', lines, '</collection>'))
   file.close()

   print 'transforming document...'
   (status, doc) = commands.getstatusoutput('java org.apache.xalan.xslt.Process -IN fragments.xml -XSL doc.xsl' )
   if status:
      print doc
      sys.exit(1)

   doc = doc.replace('/>', '>')
   lines = string.split(doc, '\n')
   lines[0] = '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">'

   file = open(sys.argv[1] + '.sgm', 'w')
   file.write( string.join(lines, '\n') )
   file.close()