Commits

Takeshi Komiya committed b277783

blockdiag: following new APIs of blockdiag

  • Participants
  • Parent commits 94babe0

Comments (0)

Files changed (6)

actdiag/sphinxcontrib/actdiag.py

     :license: BSDL.
 """
 
+import io
+import os
+import re
 import posixpath
-import re
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from actdiag_sphinxhelper import command, parser, builder, drawer
-from actdiag_sphinxhelper import collections, FontMap
-from actdiag_sphinxhelper import actdiag, ActdiagDirective
-namedtuple = collections.namedtuple
-
-import blockdiag_sphinxhelper
-detectfont = blockdiag_sphinxhelper.command.detectfont
+import actdiag_sphinxhelper as actdiag
 
 
 class ActdiagError(SphinxError):
     category = 'Actdiag error'
 
 
-class Actdiag(ActdiagDirective):
+class Actdiag(actdiag.utils.rst.directives.ActdiagDirective):
     def run(self):
         try:
             return super(Actdiag, self).run()
-        except parser.ParseException, e:
+        except actdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = actdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.actdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = detectfont(config)
+            _fontpath = actdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_actdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
+        tree = actdiag.core.parser.parse_string(code)
+        diagram = actdiag.core.builder.ScreenNodeBuilder.build(tree)
 
-        for lane in screen.lanes:
+        for lane in diagram.lanes:
             if lane.href:
                 lane.href = resolve_reference(self, lane.href, options)
-        for node in screen.traverse_nodes():
+        for node in diagram.traverse_nodes():
             if node.href:
                 node.href = resolve_reference(self, node.href, options)
 
         antialias = self.builder.config.actdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = actdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                               fontmap=fontmap, antialias=antialias)
     except Exception, e:
         if self.builder.config.actdiag_debug:
             traceback.print_exc()
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("actdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(actdiag):
+    for node in doctree.traverse(actdiag.utils.rst.nodes.actdiag):
         code = node['code']
         prefix = 'actdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(actdiag,
+    app.add_node(actdiag.utils.rst.nodes.actdiag,
                  html=(html_visit_actdiag, None),
                  latex=(latex_visit_actdiag, None))
     app.add_directive('actdiag', Actdiag)

blockdiag/sphinxcontrib/blockdiag.py

     :license: BSDL.
 """
 
+import io
+import os
+import re
 import posixpath
-import re
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from blockdiag_sphinxhelper import command, parser, builder, drawer
-from blockdiag_sphinxhelper import collections, FontMap
-from blockdiag_sphinxhelper import blockdiag, BlockdiagDirective
-namedtuple = collections.namedtuple
+import blockdiag_sphinxhelper as blockdiag
 
 
 class BlockdiagError(SphinxError):
     category = 'Blockdiag error'
 
 
-class Blockdiag(BlockdiagDirective):
+class Blockdiag(blockdiag.utils.rst.directives.BlockdiagDirective):
     def run(self):
         try:
             return super(Blockdiag, self).run()
-        except parser.ParseException, e:
+        except blockdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = blockdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.blockdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = command.detectfont(config)
+            _fontpath = blockdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_blockdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
-        for node in screen.traverse_nodes():
+        tree = blockdiag.core.parser.parse_string(code)
+        diagram = blockdiag.core.builder.ScreenNodeBuilder.build(tree)
+        for node in diagram.traverse_nodes():
             if node.href:
                 node.href = resolve_reference(self, node.href, options)
 
         antialias = self.builder.config.blockdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = blockdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                                 fontmap=fontmap, antialias=antialias)
 
     except Exception, e:
         if self.builder.config.blockdiag_debug:
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("blockdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(blockdiag):
+    for node in doctree.traverse(blockdiag.utils.rst.nodes.blockdiag):
         code = node['code']
         prefix = 'blockdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(blockdiag,
+    app.add_node(blockdiag.utils.rst.nodes.blockdiag,
                  html=(html_visit_blockdiag, None),
                  latex=(latex_visit_blockdiag, None))
     app.add_directive('blockdiag', Blockdiag)

nwdiag/sphinxcontrib/nwdiag.py

     :license: BSDL.
 """
 
+import io
+import os
 import posixpath
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from nwdiag_sphinxhelper import command, parser, builder, drawer
-from nwdiag_sphinxhelper import collections, FontMap
-from nwdiag_sphinxhelper import nwdiag, NwdiagDirective
-namedtuple = collections.namedtuple
-
-import blockdiag_sphinxhelper
-detectfont = blockdiag_sphinxhelper.command.detectfont
+import nwdiag_sphinxhelper as nwdiag
 
 
 class NwdiagError(SphinxError):
     category = 'Nwdiag error'
 
 
-class Nwdiag(NwdiagDirective):
+class Nwdiag(nwdiag.utils.rst.directives.NwdiagDirective):
     def run(self):
         try:
             return super(Nwdiag, self).run()
-        except parser.ParseException, e:
+        except nwdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = nwdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.nwdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = detectfont(config)
+            _fontpath = nwdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_nwdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
+        tree = nwdiag.core.parser.parse_string(code)
+        diagram = nwdiag.core.builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.nwdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = nwdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                              fontmap=fontmap, antialias=antialias)
     except Exception, e:
         if self.builder.config.nwdiag_debug:
             traceback.print_exc()
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("nwdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(nwdiag):
+    for node in doctree.traverse(nwdiag.utils.rst.nodes.nwdiag):
         code = node['code']
         prefix = 'nwdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(nwdiag,
+    app.add_node(nwdiag.utils.rst.nodes.nwdiag,
                  html=(html_visit_nwdiag, None),
                  latex=(latex_visit_nwdiag, None))
     app.add_directive('nwdiag', Nwdiag)

nwdiag/sphinxcontrib/packetdiag.py

     :license: BSDL.
 """
 
+import io
+import os
 import posixpath
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from packetdiag_sphinxhelper import command, parser, builder, drawer
-from packetdiag_sphinxhelper import collections, FontMap
-from packetdiag_sphinxhelper import packetdiag, PacketdiagDirective
-namedtuple = collections.namedtuple
-
-import blockdiag_sphinxhelper
-detectfont = blockdiag_sphinxhelper.command.detectfont
+import packetdiag_sphinxhelper as packetdiag
 
 
 class PacketdiagError(SphinxError):
     category = 'Packetdiag error'
 
 
-class Packetdiag(PacketdiagDirective):
+class Packetdiag(packetdiag.utils.rst.directives.PacketdiagDirective):
     def run(self):
         try:
             return super(Packetdiag, self).run()
-        except parser.ParseException, e:
+        except packetdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = packetdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.packetdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = detectfont(config)
+            _fontpath = packetdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_packetdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
+        tree = packetdiag.core.parser.parse_string(code)
+        diagram = packetdiag.core.builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.packetdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = packetdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                                  fontmap=fontmap, antialias=antialias)
     except Exception, e:
         if self.builder.config.packetdiag_debug:
             traceback.print_exc()
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("packetdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(packetdiag):
+    for node in doctree.traverse(packetdiag.utils.rst.nodes.packetdiag):
         code = node['code']
         prefix = 'packetdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(packetdiag,
+    app.add_node(packetdiag.utils.rst.nodes.packetdiag,
                  html=(html_visit_packetdiag, None),
                  latex=(latex_visit_packetdiag, None))
     app.add_directive('packetdiag', Packetdiag)

nwdiag/sphinxcontrib/rackdiag.py

     :license: BSDL.
 """
 
+import io
+import os
 import posixpath
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from rackdiag_sphinxhelper import command, parser, builder, drawer
-from rackdiag_sphinxhelper import collections, FontMap
-from rackdiag_sphinxhelper import rackdiag, RackdiagDirective
-namedtuple = collections.namedtuple
-
-import blockdiag_sphinxhelper
-detectfont = blockdiag_sphinxhelper.command.detectfont
+import rackdiag_sphinxhelper as rackdiag
 
 
 class RackdiagError(SphinxError):
     category = 'Rackdiag error'
 
 
-class Rackdiag(RackdiagDirective):
+class Rackdiag(rackdiag.utils.rst.directives.RackdiagDirective):
     def run(self):
         try:
             return super(Rackdiag, self).run()
-        except parser.ParseException, e:
+        except rackdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = rackdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.rackdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = detectfont(config)
+            _fontpath = rackdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_rackdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
+        tree = rackdiag.core.parser.parse_string(code)
+        diagram = rackdiag.core.builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.rackdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = rackdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                                fontmap=fontmap, antialias=antialias)
     except Exception, e:
         if self.builder.config.rackdiag_debug:
             traceback.print_exc()
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("rackdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(rackdiag):
+    for node in doctree.traverse(rackdiag.utils.rst.nodes.rackdiag):
         code = node['code']
         prefix = 'rackdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(rackdiag,
+    app.add_node(rackdiag.utils.rst.nodes.rackdiag,
                  html=(html_visit_rackdiag, None),
                  latex=(latex_visit_rackdiag, None))
     app.add_directive('rackdiag', Rackdiag)

seqdiag/sphinxcontrib/seqdiag.py

     :license: BSDL.
 """
 
+import io
+import os
 import posixpath
-import os
-import codecs
 import traceback
+from collections import namedtuple
 try:
     from hashlib import sha1 as sha
 except ImportError:
     from sha import sha
 
 from docutils import nodes
-from docutils.parsers.rst import directives
+from sphinx.errors import SphinxError
+from sphinx.util.osutil import ensuredir
 
-from sphinx.errors import SphinxError
-from sphinx.util.osutil import ensuredir, ENOENT, EPIPE
-from sphinx.util.compat import Directive
-
-from seqdiag_sphinxhelper import command, parser, builder, drawer
-from seqdiag_sphinxhelper import collections, FontMap
-from seqdiag_sphinxhelper import seqdiag, SeqdiagDirective
-namedtuple = collections.namedtuple
-
-import blockdiag_sphinxhelper
-detectfont = blockdiag_sphinxhelper.command.detectfont
+import seqdiag_sphinxhelper as seqdiag
 
 
 class SeqdiagError(SphinxError):
     category = 'Seqdiag error'
 
 
-class Seqdiag(SeqdiagDirective):
+class Seqdiag(seqdiag.utils.rst.directives.SeqdiagDirective):
     def run(self):
         try:
             return super(Seqdiag, self).run()
-        except parser.ParseException, e:
+        except seqdiag.core.parser.ParseException, e:
             if self.content:
                 msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
             else:
 
 
 def get_fontmap(self):
+    FontMap = seqdiag.utils.fontmap.FontMap
+
     try:
         fontmappath = self.builder.config.seqdiag_fontmap
         fontmap = FontMap(fontmappath)
 
         if fontpath:
             config = namedtuple('Config', 'font')(fontpath)
-            _fontpath = detectfont(config)
+            _fontpath = seqdiag.utils.bootstrap.detectfont(config)
             fontmap.set_default_font(_fontpath)
     except:
         attrname = '_seqdiag_fontpath_warned'
     draw = None
     fontmap = get_fontmap(self)
     try:
-        tree = parser.parse_string(code)
-        screen = builder.ScreenNodeBuilder.build(tree)
+        tree = seqdiag.core.parser.parse_string(code)
+        diagram = seqdiag.core.builder.ScreenNodeBuilder.build(tree)
 
         antialias = self.builder.config.seqdiag_antialias
-        draw = drawer.DiagramDraw(format, screen, filename,
-                                  fontmap=fontmap, antialias=antialias)
+        draw = seqdiag.core.drawer.DiagramDraw(format, diagram, filename,
+                                               fontmap=fontmap, antialias=antialias)
     except Exception, e:
         if self.builder.config.seqdiag_debug:
             traceback.print_exc()
     alt="%s" width="%s" height="%s">%s
     </svg>"""
 
-    code = open(outfn, 'r').read().decode('utf-8')
+    code = io.open(outfn, 'r', encoding='utf-8-sig').read()
 
     return (svgtag_format %
             (alt, image_size[0], image_size[1], code))
                 image.filename = toutfn
                 image.save(thumb_size)
 
-    except UnicodeEncodeError, e:
+    except UnicodeEncodeError:
         msg = ("seqdiag error: UnicodeEncodeError caught "
                "(check your font settings)")
         self.builder.warn(msg)
     if self.builder.name in ('gettext', 'singlehtml', 'html', 'latex', 'epub'):
         return
 
-    for node in doctree.traverse(seqdiag):
+    for node in doctree.traverse(seqdiag.utils.rst.nodes.seqdiag):
         code = node['code']
         prefix = 'seqdiag'
         format = 'PNG'
 
 
 def setup(app):
-    app.add_node(seqdiag,
+    app.add_node(seqdiag.utils.rst.nodes.seqdiag,
                  html=(html_visit_seqdiag, None),
                  latex=(latex_visit_seqdiag, None))
     app.add_directive('seqdiag', Seqdiag)