~ubuntu-branches/ubuntu/raring/dot2tex/raring

« back to all changes in this revision

Viewing changes to dot2tex/dot2tex.py

  • Committer: Bazaar Package Importer
  • Author(s): Peter Collingbourne
  • Date: 2008-01-16 01:31:30 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080116013130-z4dr2lw8mswabbso
Tags: 2.7.0-1
* New upstream release
* dot2tex/dot2tex.py: backed out all changes apart from shebang as
  taken upstream
* debian/dot2tex.1: documented new command line option --codeonly
* debian/rules: moved patching system to CDBS simple-patchsys
* debian/control: updated Standards-Version
* debian/control: added Uploaders, Vcs-Svn, Vcs-Browser fields for
  PAPT
* debian/copyright: changed year to 2008

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
1
2
# -*- coding: Latin-1 -*-
2
3
"""Convert graphviz graphs to LaTeX-friendly formats
3
4
 
29
30
# IN THE SOFTWARE.
30
31
 
31
32
__author__ = 'Kjell Magne Fauske'
32
 
__version__ = '2.6.1'
 
33
__version__ = '2.7.0'
33
34
__license__ = 'MIT'
34
35
 
35
36
        
833
834
    
834
835
    def cleanTemplate(self, template):
835
836
        """Remove preprocsection or outputsection"""
 
837
        if not self.dopreproc and self.options.get('codeonly',False):
 
838
            r = re.compile('<<startcodeonlysection>>(.*?)<<endcodeonlysection>>',
 
839
                    re.DOTALL | re.MULTILINE)
 
840
            m = r.search(template)
 
841
            if m:
 
842
                return m.group(1).strip()
836
843
        if not self.dopreproc and self.options.get('figonly',False):
837
844
            r = re.compile('<<startfigonlysection>>(.*?)<<endfigonlysection>>',
838
845
                    re.DOTALL | re.MULTILINE)
840
847
            if m:
841
848
                return m.group(1)
842
849
 
 
850
        
843
851
        if self.dopreproc:
844
852
            r = re.compile('<<startoutputsection>>.*?<<endoutputsection>>',
845
853
                    re.DOTALL | re.MULTILINE)
846
854
        else:
847
855
            r = re.compile('<<startpreprocsection>>.*?<<endpreprocsection>>',
848
856
                    re.DOTALL | re.MULTILINE)
849
 
                    
 
857
        # remove codeonly and figonly section
850
858
        r2 = re.compile('<<startfigonlysection>>.*?<<endfigonlysection>>',
851
859
                    re.DOTALL | re.MULTILINE)
852
860
        tmp = r2.sub('',template)
 
861
        r2 = re.compile('<<startcodeonlysection>>.*?<<endcodeonlysection>>',
 
862
                    re.DOTALL | re.MULTILINE)
 
863
        tmp = r2.sub('',tmp)
853
864
        return r.sub('',tmp)
854
865
 
855
866
    def initTemplateVars(self):
1106
1117
        if not ok:
1107
1118
            errormsg = """\
1108
1119
Failed to preprocess the graph.
1109
 
Is the preview LaTeX package installed? (Debian package preview-latex-style)
 
1120
Is the preview LaTeX package installed? ((Debian package preview-latex-style)
1110
1121
To see what happened, run dot2tex with the --debug option.
1111
1122
"""
1112
1123
            log.error(errormsg)
1231
1242
<<figpostamble>>%
1232
1243
\end{pspicture}
1233
1244
<<endfigonlysection>>
 
1245
%
 
1246
<<startcodeonlysection>>
 
1247
<<figpreamble>>%
 
1248
<<drawcommands>>
 
1249
<<figpostamble>>%
 
1250
<<endcodeonlysection>>
1234
1251
"""
1235
1252
 
1236
1253
class Dot2PSTricksConv(DotConvBase):
1522
1539
<<figpostamble>>%
1523
1540
\end{tikzpicture}
1524
1541
<<endfigonlysection>>
 
1542
<<startcodeonlysection>>
 
1543
<<figpreamble>>%
 
1544
<<drawcommands>>
 
1545
<<figpostamble>>%
 
1546
<<endcodeonlysection>>
1525
1547
"""
1526
1548
 
1527
1549
class Dot2PGFConv(DotConvBase):
1935
1957
<<figpostamble>>%
1936
1958
\end{tikzpicture}
1937
1959
<<endfigonlysection>>
 
1960
<<startcodeonlysection>>
 
1961
<<figpreamble>>%
 
1962
<<drawcommands>>
 
1963
<<figpostamble>>%
 
1964
<<endcodeonlysection>>
1938
1965
"""
1939
1966
 
1940
1967
class Dot2TikZConv(Dot2PGFConv):
2394
2421
                  default=False, help="Include gvcols.tex"),
2395
2422
    parser.add_option('--figonly', dest='figonly', action ="store_true",
2396
2423
                  help="Output graph with no preamble", default=False)
 
2424
    parser.add_option('--codeonly', dest='codeonly', action ="store_true",
 
2425
                  help="Output only drawing commands", default=False)
2397
2426
    parser.add_option('--styleonly', dest='styleonly', action ="store_true",
2398
2427
                  help="Use style parameter only", default=False)
2399
2428
    parser.add_option('--debug',dest='debug', action="store_true",
2457
2486
        nodebug = True
2458
2487
 
2459
2488
    log.info('------- Start of run -------')
 
2489
    log.info("Dot2tex version % s" % __version__)
2460
2490
    log.info("System information:\n"
2461
2491
             "  Python: %s \n"
2462
2492
             "  Platform: %s\n"