예제 #1
0
class DitaaGenerator(ImageGeneratorClass):

    uses_log_file = False

    object_type = 'ditaa'
    scriptname = 'ditaa.dia'
    imagename = 'ditaa.png'

    def __init__(self, plugin):
        ImageGeneratorClass.__init__(self, plugin)
        self.dotfile = TmpFile(self.scriptname)
        self.dotfile.touch()
        self.pngfile = File(self.dotfile.path[:-4] +
                            '.png')  # len('.dot') == 4

    def generate_image(self, text):
        # Write to tmp file
        self.dotfile.write(text)

        # Call GraphViz
        try:
            dot = Application(dotcmd)
            dot.run((self.dotfile, '-o', self.pngfile))
        except ApplicationError:
            return None, None  # Sorry, no log
        else:
            return self.pngfile, None

    def cleanup(self):
        self.dotfile.remove()
        self.pngfile.remove()
예제 #2
0
class DitaaGenerator(ImageGeneratorClass):

    uses_log_file = False

    object_type = "shaape"
    scriptname = "shaape.dia"
    imagename = "shaape.png"

    def __init__(self, plugin):
        ImageGeneratorClass.__init__(self, plugin)
        self.dotfile = TmpFile(self.scriptname)
        self.dotfile.touch()
        self.pngfile = File(self.dotfile.path[:-4] + ".png")  # len('.dot') == 4

    def generate_image(self, text):
        # Write to tmp file
        self.dotfile.write(text)

        # Call GraphViz
        try:
            dot = Application(dotcmd)
            dot.run(("-o", self.pngfile, self.dotfile))
        except ApplicationError:
            return None, None  # Sorry, no log
        else:
            return self.pngfile, None

    def cleanup(self):
        self.dotfile.remove()
        self.pngfile.remove()
예제 #3
0
class SequenceDiagramGenerator(ImageGeneratorClass):

    uses_log_file = False

    object_type = 'seqdiagram'
    scriptname = 'seqdiagram.diag'
    imagename = 'seqdiagram.png'

    def __init__(self, plugin):
        ImageGeneratorClass.__init__(self, plugin)
        self.diagfile = TmpFile(self.scriptname)
        self.diagfile.touch()
        self.pngfile = File(self.diagfile.path[:-5] +
                            '.png')  # len('.diag') == 5

    def generate_image(self, text):
        # Write to tmp file
        self.diagfile.write(text)

        # Call seqdiag
        try:
            diag = Application(diagcmd)
            diag.run((self.pngfile, self.diagfile))
        except ApplicationError:
            return None, None  # Sorry, no log
        else:
            return self.pngfile, None

    def cleanup(self):
        self.diagfile.remove()
        self.pngfile.remove()
예제 #4
0
class SequenceDiagramGenerator(ImageGeneratorClass):

	uses_log_file = False

	object_type = 'seqdiagram'
	scriptname = 'seqdiagram.diag'
	imagename = 'seqdiagram.png'

	def __init__(self, plugin):
		ImageGeneratorClass.__init__(self, plugin)
		self.diagfile = TmpFile(self.scriptname)
		self.diagfile.touch()
		self.pngfile = File(self.diagfile.path[:-5] + '.png') # len('.diag') == 5

	def generate_image(self, text):
		# Write to tmp file
		self.diagfile.write(text)

		# Call seqdiag
		try:
			diag = Application(diagcmd)
			diag.run((self.pngfile, self.diagfile))
		except ApplicationError:
			return None, None # Sorry, no log
		else:
			return self.pngfile, None

	def cleanup(self):
		self.diagfile.remove()
		self.pngfile.remove()
예제 #5
0
class DiagramGenerator(ImageGeneratorClass):

	def __init__(self, plugin, notebook, page):
		ImageGeneratorClass.__init__(self, plugin, notebook, page)
		self.dotfile = TmpFile('diagram.dot')
		self.dotfile.touch()
		self.pngfile = File(self.dotfile.path[:-4] + '.png') # len('.dot') == 4

	def generate_image(self, text):
		# Write to tmp file
		self.dotfile.write(text)

		# Call GraphViz
		try:
			dot = Application(dotcmd)
			dot.run((self.pngfile, self.dotfile))
		except ApplicationError:
			return None, None # Sorry, no log
		else:
			if self.pngfile.exists():
				return self.pngfile, None
			else:
				# When supplying a dot file with a syntax error, the dot command
				# doesn't return an error code (so we don't raise
				# ApplicationError), but we still don't have a png file to
				# return, so return None.
				return None, None

	def cleanup(self):
		self.dotfile.remove()
		self.pngfile.remove()
예제 #6
0
class LatexGenerator(ImageGeneratorClass):
    def __init__(self, plugin, notebook, page):
        ImageGeneratorClass.__init__(self, plugin, notebook, page)
        self.texfile = TmpFile('latex.tex')
        print('[PLUGINS:INSERT LATEX] text file: %s' % self.texfile)

    def generate_image(self, text):

        if isinstance(text, str):
            text = text.splitlines(True)
        text = (line for line in text if line and not line.isspace())
        text = ''.join(text)
        print('[PLUGINS:INSERT LATEX] text written >>>%s<<<' % text)

        # Write to tmp file
        self.texfile.write(text)
        print('[PLUGINS:INSERT LATEX] read from file >>>%s<<<' %
              self.texfile.read())

        # Call latex
        logfile = File(self.texfile.path[:-4] + '.log')  # len('.tex') == 4
        print("[PLUGINS:INSERT LATEX] >>>", self.texfile, logfile)

        try:
            latex = Application(latex_cmd)
            latex.run((self.texfile.basename, ), cwd=self.texfile.dir)
        except ApplicationError:
            print("[PLUGINS:INSERT LATEX] ApplicationError")
            return None, logfile

        png_file = File(self.texfile.path[:-4] + '.png')  # len('.tex') == 4

        return png_file, logfile

    def cleanup(self):
        path = self.texfile.path
        for path in glob.glob(path[:-4] + '.*'):
            File(path).remove()
예제 #7
0
class DiagramGenerator(ImageGeneratorClass):

	uses_log_file = False

	object_type = 'diagram'
	scriptname = 'diagram.dot'
	imagename = 'diagram.png'

	def __init__(self, plugin):
		ImageGeneratorClass.__init__(self, plugin)
		self.dotfile = TmpFile(self.scriptname)
		self.dotfile.touch()
		self.pngfile = File(self.dotfile.path[:-4] + '.png') # len('.dot') == 4

	def generate_image(self, text):
		# Write to tmp file
		self.dotfile.write(text)

		# Call GraphViz
		try:
			dot = Application(dotcmd)
			dot.run((self.pngfile, self.dotfile))
		except ApplicationError:
			return None, None # Sorry, no log
		else:
			if self.pngfile.exists():
				return self.pngfile, None
			else:
				# When supplying a dot file with a syntax error, the dot command
				# doesn't return an error code (so we don't raise
				# ApplicationError), but we still don't have a png file to
				# return, so return None.
				return None, None

	def cleanup(self):
		self.dotfile.remove()
		self.pngfile.remove()
예제 #8
0
class PlantumlGenerator(ImageGeneratorClass):
    def __init__(self, plugin, notebook, page):
        ImageGeneratorClass.__init__(self, plugin, notebook, page)
        self.dotfile = TmpFile('plantuml.pu')
        self.dotfile.touch()
        self.pngfile = File(self.dotfile.path[:-3] + '.png')  # len('.pu') == 3

    def generate_image(self, text):
        # Write to tmp file
        self.dotfile.write(text)

        # Call GraphViz
        try:
            dot = Application(dotcmd)
            dot.run((self.dotfile, ))
        except ApplicationError as e:
            print(e)
            return None, None  # Sorry, no log
        else:
            return self.pngfile, None

    def cleanup(self):
        self.dotfile.remove()
        self.pngfile.remove()
예제 #9
0
	def on_print_tasklist(self, o):
		html = self.window.task_list.get_visible_data_as_html()
		file = TmpFile('print-to-browser.html', persistent=True, unique=False)
		file.write(html)
		self.window.ui.open_url('file://%s' % file) # XXX