/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

util.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 class Comment:
00004     def __init__(self,comment=""):
00005         self.comment = comment
00006 
00007     def xml(self,fo,pre):
00008         lines = self.comment.split('\n')
00009         if 1 == len(lines) and len(lines[0]) <= 70:
00010             fo.write("%s<!-- %s -->\n"%(pre,lines[0]))
00011             return
00012         fo.write("%s<!--\n"%pre)
00013         for line in self.comment.split('\n'):
00014             fo.write(pre+'    '+line+'\n')
00015         fo.write("%s-->\n"%pre)
00016         return
00017 class ExternalEntity:
00018     def __init__(self,entity=""):
00019         self.entity = entity
00020 
00021     def set_path(self,base):
00022         pass
00023     def xml(self,fo,pre):
00024         fo.write("%s&%s;\n"%(pre,self.entity))
00025         return
00026 
00027 
00028 class XmlFile:
00029     def __init__(self,dtd=None,objects=[],external_entities=[]):
00030         "XmlFile. external entities are (name,file) tuples"
00031         self.dtd = dtd
00032         self.objects = objects
00033         self.external_entities = external_entities
00034         #print "Starting XML file with %d objects and %d ee"%(len(objects),len(external_entities))
00035         return
00036 
00037     def xml(self,fo,pre=''):
00038         fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
00039         Comment("Warning: this is a generated file.  Any modifications may be lost.").xml(fo,pre)
00040         if self.dtd:
00041             fo.write('<!DOCTYPE DDDB SYSTEM "%s"'%self.dtd)
00042             if self.external_entities:
00043                 fo.write(' [\n')
00044                 for ee in self.external_entities:
00045                     if isinstance(ee,str):
00046                         fo.write('%s\n'%ee)
00047                     else:
00048                         fo.write('  <!ENTITY %s SYSTEM "%s">\n'%(ee[0],ee[1]))
00049                 fo.write(' ]>\n')
00050             else:
00051                 fo.write(' >\n')
00052             fo.write('<DDDB>\n')
00053         for obj in self.objects:
00054             if isinstance(obj, str):
00055                 fo.write('%s%s\n'%(pre,obj))
00056             else:
00057                 obj.xml(fo,pre)
00058         if self.dtd:
00059             fo.write('</DDDB>\n')                
00060         return
00061 
00062     def write(self,filename):
00063         import os
00064         try:
00065             os.remove(filename)
00066         except OSError:
00067             pass
00068         file = open(filename,"w")
00069         self.xml(file,'')
00070         file.close()
00071         os.chmod(filename,0444)
00072         print 'Wrote "%s"'%filename
00073         return
00074 
00075     
00076         
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:56:07 for XmlDetDesc by doxygen 1.7.4