Ejemplo n.º 1
0
	def generate_image(self, text):
		if isinstance(text, basestring):
			text = text.splitlines(True)

		plotscriptfile = self.plotscriptfile
		pngfile = File(plotscriptfile.path[:-2] + '.png')

		plot_script = "".join(text)

		template_vars = {
			'gnu_r_plot_script': plot_script,
			'png_fname': pngfile.path.replace('\\', '/'),
				# Even on windows, GNU R expects unix path seperator
		}

		# Write to tmp file usign the template for the header / footer
		plotscriptfile.writelines(
			self.template.process(template_vars)
		)
		#print '>>>%s<<<' % plotscriptfile.read()

		# Call GNU R
		try:
			gnu_r = Application(gnu_r_cmd)
			#~ gnu_r.run(args=('-f', plotscriptfile.basename, ), cwd=plotscriptfile.dir)
			gnu_r.run(args=('-f', plotscriptfile.basename, '--vanilla'), cwd=plotscriptfile.dir)
		except:
			return None, None # Sorry, no log
		else:
			return pngfile, None
Ejemplo n.º 2
0
	def generate_image(self, text):

		plotscriptfile = self.plotscriptfile
		pngfile = File(plotscriptfile.path[:-4] + '.png')

		plot_script = "".join(text)

		template_vars = { # they go in the template
			'gnuplot_script': plot_script,
			'png_fname': pngfile.path,
		}
		if self.attachment_folder and self.attachment_folder.exists():
			template_vars['attachment_folder'] = self.attachment_folder.path
		else:
			template_vars['attachment_folder'] = ''

		# Write to tmp file using the template for the header / footer
		lines = []
		self.template.process(lines, template_vars)
		plotscriptfile.writelines(lines)
		#~ print '>>>\n%s<<<' % plotscriptfile.read()

		# Call Gnuplot
		try:
			gnu_gp = Application(gnuplot_cmd)
			gnu_gp.run(args=( plotscriptfile.basename, ), cwd=plotscriptfile.dir)
							# you call it as % gnuplot output.plt

		except ApplicationError:
			return None, None # Sorry - no log
		else:
			return pngfile, None
Ejemplo n.º 3
0
	def run(self, args, cwd=None):
		self._tmpfile = None
		Application.run(self, args, cwd=cwd)
		if self._tmpfile:
			notebook, page, pageview = args
			page.parse('wiki', self._tmpfile.readlines())
			self._tmpfile = None
Ejemplo n.º 4
0
    def generate_image(self, text):
        plotscriptfile = self.plotscriptfile
        pngfile = File(plotscriptfile.path[:-4] + '.png')

        template_vars = { # they go in the template
         'gnuplot_script': text,
         'png_fname': pngfile.path,
        }
        if self.attachment_folder and self.attachment_folder.exists():
            template_vars['attachment_folder'] = self.attachment_folder.path
        else:
            template_vars['attachment_folder'] = ''

        # Write to tmp file using the template for the header / footer
        lines = []
        self.template.process(lines, template_vars)
        plotscriptfile.writelines(lines)
        #~ print '>>>\n%s<<<' % plotscriptfile.read()

        # Call Gnuplot
        try:
            gnu_gp = Application(gnuplot_cmd)
            gnu_gp.run(args=(plotscriptfile.basename, ),
                       cwd=plotscriptfile.dir)
            # you call it as % gnuplot output.plt

        except ApplicationError:
            return None, None  # Sorry - no log
        else:
            return pngfile, None
Ejemplo n.º 5
0
	def generate_image(self, text):

		# Filter out empty lines, not allowed in latex equation blocks
		if isinstance(text, basestring):
			text = text.splitlines(True)
		text = (line for line in text if line and not line.isspace())
		text = ''.join(text)
		#~ print '>>>%s<<<' % text

		# Write to tmp file using the template for the header / footer
		lines = []
		self.template.process(lines, {'equation': text})
		self.texfile.writelines(lines)
		#~ print '>>>%s<<<' % self.texfile.read()

		# Call latex
		logfile = File(self.texfile.path[:-4] + '.log') # len('.tex') == 4
		#~ print ">>>", self.texfile, logfile
		try:
			latex = Application(latexcmd)
			latex.run((self.texfile.basename,), cwd=self.texfile.dir)
		except ApplicationError:
			# log should have details of failure
			return None, logfile

		# Call dvipng
		dvifile = File(self.texfile.path[:-4] + '.dvi') # len('.tex') == 4
		pngfile = File(self.texfile.path[:-4] + '.png') # len('.tex') == 4
		dvipng = Application(dvipngcmd)
		dvipng.run((pngfile, dvifile)) # output, input
			# No try .. except here - should never fail
		# TODO dvipng can start processing before latex finished - can we win speed there ?

		return pngfile, logfile
Ejemplo n.º 6
0
    def generate_image(self, text):
        if isinstance(text, basestring):
            text = text.splitlines(True)

        plotscriptfile = self.plotscriptfile
        pngfile = File(plotscriptfile.path[:-2] + '.png')

        plot_script = "".join(text)

        template_vars = {
            'gnu_r_plot_script': plot_script,
            'png_fname': pngfile.path.replace('\\', '/'),
                # Even on windows, GNU R expects unix path seperator
        }

        # Write to tmp file usign the template for the header / footer
        plotscriptfile.writelines(
            self.template.process(template_vars)
        )
        #print '>>>%s<<<' % plotscriptfile.read()

        # Call GNU R
        try:
            gnu_r = Application(gnu_r_cmd)
            #~ gnu_r.run(args=('-f', plotscriptfile.basename, ), cwd=plotscriptfile.dir)
            gnu_r.run(args=('-f', plotscriptfile.basename, '--vanilla'), cwd=plotscriptfile.dir)
        except:
            return None, None # Sorry, no log
        else:
            return pngfile, None
Ejemplo n.º 7
0
 def run(self, args):
     self._tmpfile = None
     Application.run(self, args)
     if self._tmpfile:
         notebook, page, pageview = args
         page.parse('wiki', self._tmpfile.readlines())
         self._tmpfile = None
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    def generate_image(self, text):
        if isinstance(text, basestring):
            text = text.splitlines(True)

        # Filter out empty lines, not allowed in latex equation blocks
        text = (line for line in text if line and not line.isspace())
        text = ''.join(text)
        #~ print '>>>%s<<<' % text

        # Write to tmp file using the template for the header / footer
        texfile = self.texfile
        texfile.writelines(self.template.process({'equation': text}))
        #~ print '>>>%s<<<' % texfile.read()

        # Call latex
        logfile = File(texfile.path[:-4] + '.log')  # len('.tex') == 4
        try:
            latex = Application(latexcmd)
            latex.run((texfile.basename, ), cwd=texfile.dir)
        except ApplicationError:
            # log should have details of failure
            return None, logfile

        # Call dvipng
        dvifile = File(texfile.path[:-4] + '.dvi')  # len('.tex') == 4
        pngfile = File(texfile.path[:-4] + '.png')  # len('.tex') == 4
        dvipng = Application(dvipngcmd)
        dvipng.run((pngfile, dvifile))  # output, input
        # No try .. except here - should never fail
        # TODO dvipng can start processing before latex finished - can we win speed there ?

        return pngfile, logfile
Ejemplo n.º 10
0
	def generate_image(self, text):
		if isinstance(text, basestring):
			text = text.splitlines(True)

		# Write to tmp file
		self.dotfile.writelines(text)

		# Call GraphViz
		dot = Application(dotcmd)
		dot.run((self.pngfile, self.dotfile))

		return self.pngfile, None
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
	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
Ejemplo n.º 15
0
	def export(self):
		dir = Dir(self.create_tmp_dir('source_files'))
		init_notebook(dir)
		notebook = Notebook(dir=dir)
		for name, text in tests.WikiTestData:
			page = notebook.get_page(Path(name))
			page.parse('wiki', text)
			notebook.store_page(page)
		file = dir.file('Test/foo.txt')
		self.assertTrue(file.exists())

		zim = Application(('./zim.py', '--export', '--template=Default', dir.path, '--output', self.dir.path, '--index-page', 'index'))
		zim.run()
Ejemplo n.º 16
0
    def generate_image(self, text):
        if isinstance(text, basestring):
            text = text.splitlines(True)

        # Write to tmp file
        self.diagfile.writelines(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
Ejemplo n.º 17
0
    def generate_image(self, text):
        if isinstance(text, basestring):
            text = text.splitlines(True)

        # Write to tmp file
        self.dotfile.writelines(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
Ejemplo n.º 18
0
    def generate_image(self, text):
        if isinstance(text, basestring):
            text = text.splitlines(True)

        # Write to tmp file
        self.dotfile.writelines(text)

        # Call GraphViz
        try:
            dot = Application(dotcmd)
            dot.run((self.pngfile, self.dotfile))
        except ApplicationError:
            return None, None # Sorry, no log
        else:
            return self.pngfile, None
Ejemplo n.º 19
0
    def generate_image(self, text):

        (version, text) = self.extract_version(text)
        text = ''.join(text)
        #~ print '>>>%s<<<' % text

        # Write to tmp file using the template for the header / footer
        scorefile = self.scorefile
        lines = []
        self.template.process(
            lines, {
                'score': text,
                'version': version or '',
                'include_header': self.include_header or '',
                'include_footer': self.include_footer or '',
            })
        scorefile.writelines(lines)
        #~ print '>>>%s<<<' % scorefile.read()

        # Call convert-ly to convert document of current version of
        # Lilypond.
        clogfile = File(scorefile.path[:-3] +
                        '-convertly.log')  # len('.ly) == 3
        try:
            convertly = Application(convertly_cmd)
            convertly.run((scorefile.basename, ), cwd=scorefile.dir)
        except ApplicationError:
            clogfile.write('convert-ly failed.\n')
            return None, clogfile

        # Call lilypond to generate image.
        logfile = File(scorefile.path[:-3] + '.log')  # len('.ly') == 3
        try:
            lilypond = Application(lilypond_cmd)
            lilypond.run((
                '-dlog-file=' + logfile.basename[:-4],
                scorefile.basename,
            ),
                         cwd=scorefile.dir)
        except ApplicationError:
            # log should have details of failure
            return None, logfile
        pngfile = File(scorefile.path[:-3] + '.png')  # len('.ly') == 3

        return pngfile, logfile
Ejemplo n.º 20
0
	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
Ejemplo n.º 21
0
    def generate_image(self, text):
        # Write to tmp file
        self.dotfile.writelines(text)

        # Call PlantUML
        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
Ejemplo n.º 22
0
    def generate_image(self, text):

        plotscriptfile = self.plotscriptfile
        pngfile = File(plotscriptfile.path[:-2] + '.png')

        plot_script = "".join(text)

        plot_width = 480  # default image width (px)
        plot_height = 480  # default image height (px)

        # LOOK for image size in comments of the script
        r = re.search(r"^#\s*WIDTH\s*=\s*([0-9]+)$", plot_script, re.M)
        if r:
            plot_width = int(r.group(1))
        r = re.search(r"^#\s*HEIGHT\s*=\s*([0-9]+)$", plot_script, re.M)
        if r:
            plot_height = int(r.group(1))

        template_vars = {
            'gnu_r_plot_script': plot_script,
            'r_width': plot_width,
            'r_height': plot_height,
            'png_fname': pngfile.path.replace('\\', '/'),
            # Even on windows, GNU R expects unix path seperator
        }

        # Write to tmp file usign the template for the header / footer
        lines = []
        self.template.process(lines, template_vars)
        plotscriptfile.writelines(lines)
        #print '>>>%s<<<' % plotscriptfile.read()

        # Call GNU R
        try:
            gnu_r = Application(gnu_r_cmd)
            #~ gnu_r.run(args=('-f', plotscriptfile.basename, ), cwd=plotscriptfile.dir)
            gnu_r.run(args=('-f', plotscriptfile.basename, '--vanilla'),
                      cwd=plotscriptfile.dir)
        except:
            return None, None  # Sorry, no log
        else:
            return pngfile, None
    def generate_image(self, text):

        # Filter out empty lines, not allowed in latex equation blocks
        if isinstance(text, str):
            text = text.splitlines(True)
        text = (line for line in text if line and not line.isspace())
        text = ''.join(text)
        #~ print('>>>%s<<<' % text)

        # Write to tmp file using the template for the header / footer
        lines = []
        self.template.process(
            lines, {
                'equation': text,
                'font_size': self.preferences['font_size'],
                'dark_mode': self.preferences['dark_mode']
            })
        self.texfile.writelines(lines)
        #~ print('>>>%s<<<' % self.texfile.read())

        # Call latex
        logfile = File(self.texfile.path[:-4] + '.log')  # len('.tex') == 4
        #~ print(">>>", self.texfile, logfile)
        try:
            latex = Application('%s -no-shell-escape -halt-on-error' %
                                (latexcmd))
            latex.run((self.texfile.basename, ), cwd=self.texfile.dir)
        except ApplicationError:
            # log should have details of failure
            return None, logfile

        # Call dvipng
        dvifile = File(self.texfile.path[:-4] + '.dvi')  # len('.tex') == 4
        pngfile = File(self.texfile.path[:-4] + '.png')  # len('.tex') == 4
        dvipng = Application('%s -q -bg Transparent -T tight -D %s -o' %
                             (dvipngcmd, self.preferences['output_dpi']))
        dvipng.run((pngfile, dvifile))  # output, input
        # No try .. except here - should never fail
        # TODO dvipng can start processing before latex finished - can we win speed there ?

        return pngfile, logfile
Ejemplo n.º 24
0
	def generate_image(self, text):

		plotscriptfile = self.plotscriptfile
		pngfile = File(plotscriptfile.path[:-2] + '.png')

		plot_script = "".join(text)
		
		plot_width = 480 # default image width (px)
		plot_height = 480 # default image height (px)

		# LOOK for image size in comments of the script
		r=re.search(r"^#\s*WIDTH\s*=\s*([0-9]+)$",plot_script,re.M)
		if r:
			plot_width=int(r.group(1))
		r=re.search(r"^#\s*HEIGHT\s*=\s*([0-9]+)$",plot_script,re.M)
		if r:
			plot_height=int(r.group(1))

		template_vars = {
			'gnu_r_plot_script': plot_script,
			'r_width': plot_width,
			'r_height': plot_height,
			'png_fname': pngfile.path.replace('\\', '/'),
				# Even on windows, GNU R expects unix path seperator
		}

		# Write to tmp file usign the template for the header / footer
		lines = []
		self.template.process(lines, template_vars)
		plotscriptfile.writelines(lines)
		#print '>>>%s<<<' % plotscriptfile.read()

		# Call GNU R
		try:
			gnu_r = Application(gnu_r_cmd)
			#~ gnu_r.run(args=('-f', plotscriptfile.basename, ), cwd=plotscriptfile.dir)
			gnu_r.run(args=('-f', plotscriptfile.basename, '--vanilla'), cwd=plotscriptfile.dir)
		except:
			return None, None # Sorry, no log
		else:
			return pngfile, None
Ejemplo n.º 25
0
	def generate_image(self, text):

		(version, text) = self.extract_version(text)
		text = ''.join(text)
		#~ print '>>>%s<<<' % text

		# Write to tmp file using the template for the header / footer
		scorefile = self.scorefile
		lines = []
		self.template.process(lines, {
			'score': text,
			'version': version or '',
			'include_header': self.include_header or '',
			'include_footer': self.include_footer or '',
		} )
		scorefile.writelines(lines)
		#~ print '>>>%s<<<' % scorefile.read()

		# Call convert-ly to convert document of current version of
		# Lilypond.
		clogfile = File(scorefile.path[:-3] + '-convertly.log') # len('.ly) == 3
		try:
			convertly = Application(convertly_cmd)
			convertly.run((scorefile.basename,), cwd=scorefile.dir)
		except ApplicationError:
			clogfile.write('convert-ly failed.\n')
			return None, clogfile


		# Call lilypond to generate image.
		logfile = File(scorefile.path[:-3] + '.log') # len('.ly') == 3
		try:
			lilypond = Application(lilypond_cmd)
			lilypond.run(('-dlog-file=' + logfile.basename[:-4], scorefile.basename,), cwd=scorefile.dir)
		except ApplicationError:
			# log should have details of failure
			return None, logfile
		pngfile = File(scorefile.path[:-3] + '.png') # len('.ly') == 3

		return pngfile, logfile
Ejemplo n.º 26
0
Archivo: hg.py Proyecto: thejeshgn/Zim
	def run(self, args, pwd):
		args = ('--noninteractive',) + tuple(args)
			# force hg to run in non-interactive mode
			# which will force user name to be auto-setup
		Application.run(self, args, pwd)
Ejemplo n.º 27
0
	def run(self, args, cwd=None):
		if bzrlib:
			cwd = unicode(cwd).encode('utf-8')
			self._bzrlib(args, cwd)
		else:
			Application.run(self, cwd=cwd)