clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / python / blockdiag-family / src / blockdiag / command.py
command.py 2.2K
1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516import re17import sys1819import blockdiag20import blockdiag.builder21import blockdiag.drawer22import blockdiag.parser23from blockdiag.utils.bootstrap import Application, Options242526class BlockdiagOptions(Options):27 def build_parser(self):28 super(BlockdiagOptions, self).build_parser()29 self.parser.add_option(30 '-s', '--separate', action='store_true',31 help='Separate diagram images for each group (SVG only)'32 )333435class BlockdiagApp(Application):36 module = blockdiag3738 def parse_options(self, args):39 self.options = BlockdiagOptions(self.module).parse(args)40 if self.options.module:41 self.module = self.options.module4243 def build_diagram(self, tree):44 if not self.options.separate:45 return super(BlockdiagApp, self).build_diagram(tree)46 else:47 DiagramBuilder = self.module.builder.SeparateDiagramBuilder48 DiagramDraw = self.module.drawer.DiagramDraw4950 basename = re.sub('.svg$', '', self.options.output)51 for i, group in enumerate(DiagramBuilder.build(tree)):52 outfile = '%s_%d.svg' % (basename, i + 1)53 draw = DiagramDraw(self.options.type, group, outfile,54 fontmap=self.fontmap,55 antialias=self.options.antialias,56 nodoctype=self.options.nodoctype,57 transparency=self.options.transparency)58 draw.draw()59 draw.save()6061 return 0626364def main(args=None):65 if args is None:66 args = sys.argv[1:]6768 return BlockdiagApp().run(args)