当前位置: 首页>>代码示例>>Python>>正文


Python fs.TmpFile类代码示例

本文整理汇总了Python中zim.fs.TmpFile的典型用法代码示例。如果您正苦于以下问题:Python TmpFile类的具体用法?Python TmpFile怎么用?Python TmpFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TmpFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_to_file

	def print_to_file(self, notebook, page):
		file = TmpFile('print-to-browser.html', persistent=True, unique=False)
		template = zim.templates.get_template('html', 'Print')
		template.set_linker(StaticLinker('html', notebook, page))
		html = template.process(notebook, page)
		file.writelines(html)
		return file
开发者ID:gdw2,项目名称:zim,代码行数:7,代码来源:printtobrowser.py

示例2: LogContext

class LogContext(object):
	'''Context to log errors and warnings to a log file'''

	def __init__(self):
		names = ['zim.export', 'zim.templates', 'zim.formats']
		level = logging.INFO

		self.logger = logging.getLogger('zim')
		self.level = level
		self.file = TmpFile(basename='export-log.txt', unique=False, persistent=True)
		self.file.remove() # clean up previous run
		self.handler = LogHandler(self.file.path)
		self.handler.setLevel(self.level)
		self.handler.addFilter(LogFilter(names))
		self.handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s') )

	def __enter__(self):
		#~ self._old_level = self.logger.getEffectiveLevel()
		#~ if self._old_level > self.level:
			#~ self.logger.setLevel(self.level)
		self.logger.addHandler(self.handler)

	def __exit__(self, exc_type, exc_val, exc_tb):
		self.logger.removeHandler(self.handler)
		#~ self.logger.setLevel(self._old_level)
		self.handler.close()
		return False # re-raises error
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:27,代码来源:exportdialog.py

示例3: EquationGenerator

class EquationGenerator(ImageGeneratorClass):

	object_type = 'equation'
	scriptname = 'equation.tex'
	imagename = 'equation.png'

	def __init__(self, plugin):
		ImageGeneratorClass.__init__(self, plugin)
		self.template = get_template('plugins', 'equationeditor.tex')
		self.texfile = TmpFile(self.scriptname)

	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

	def cleanup(self):
		path = self.texfile.path
		for path in glob.glob(path[:-4]+'.*'):
			File(path).remove()
开发者ID:hjq300,项目名称:zim-wiki,代码行数:50,代码来源:equationeditor.py

示例4: show_side_by_side

	def show_side_by_side(self):
		file = self._get_file()
		versions = self.versionlist.get_versions()
		if not (file and versions):
			raise AssertionError

		files = map(lambda v: self._get_tmp_file(file, v), versions)
		if len(files) == 1:
			tmp = TmpFile(file.basename + '--CURRENT', persistent=True)
				# need to be persistent, else it is cleaned up before application spawned
			tmp.writelines(file.readlines())
			files.insert(0, tmp)

		self._side_by_side_app.spawn(files)
开发者ID:gdw2,项目名称:zim,代码行数:14,代码来源:__init__.py

示例5: print_to_file

	def print_to_file(self, notebook, page):
		file = TmpFile('print-to-browser.html', persistent=True, unique=False)
		template = zim.templates.get_template('html', 'Print')

		linker_factory = partial(StaticExportLinker, notebook, template.resources_dir)
		dumper_factory = zim.formats.get_format('html').Dumper # XXX
		context = ExportTemplateContext(
			notebook, linker_factory, dumper_factory,
			page.basename, [page]
		)

		lines = []
		template.process(lines, context)
		file.writelines(lines)
		return file
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:15,代码来源:printtobrowser.py

示例6: __init__

	def __init__(self):
		names = ['zim.export', 'zim.templates', 'zim.formats']
		level = logging.INFO

		self.logger = logging.getLogger('zim')
		self.level = level
		self.file = TmpFile(basename='export-log.txt', unique=False, persistent=True)
		self.file.remove() # clean up previous run
		self.handler = LogHandler(self.file.path)
		self.handler.setLevel(self.level)
		self.handler.addFilter(LogFilter(names))
		self.handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s') )
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:12,代码来源:exportdialog.py

示例7: print_to_file

    def print_to_file(self, page):
        # FIXME - HACK - dump and parse as wiki first to work
        # around glitches in pageview parsetree dumper
        # main visibility when copy pasting bullet lists
        # Same hack in gui clipboard code
        from zim.notebook import Path, Page
        from zim.formats import get_format
        parsetree = page.get_parsetree()
        dumper = get_format('wiki').Dumper()
        text = ''.join( dumper.dump(parsetree) ).encode('utf-8')
        parser = get_format('wiki').Parser()
        parsetree = parser.parse(text)
        page = Page(Path(page.name), parsetree=parsetree)
        #--

        file = TmpFile('print-to-browser.html', persistent=True, unique=False)
        template = zim.templates.get_template('html', 'Print')
        template.set_linker(StaticLinker('html', self.ui.notebook, page))
        html = template.process(self.ui.notebook, page)
        file.writelines(html)
        return file
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:21,代码来源:printtobrowser.py

示例8: PlantumlGenerator

class PlantumlGenerator(ImageGeneratorClass):

	uses_log_file = False

	object_type = 'plantuml'
	scriptname = 'plantuml.pu'
	imagename = 'plantuml.png'

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

	def generate_image(self, text):
		if isinstance(text, basestring):
			text = text.splitlines(True)

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

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

	def cleanup(self):
		self.dotfile.remove()
		self.pngfile.remove()
开发者ID:ibingr,项目名称:zim-plantuml,代码行数:33,代码来源:plantumleditor.py

示例9: DitaaGenerator

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()
开发者ID:dstuxo,项目名称:zim-plugins,代码行数:30,代码来源:shaape.py

示例10: DiagramGenerator

class DiagramGenerator(object):

	# TODO: generic base class for image generators

	type = 'diagram'
	basename = 'diagram.dot'

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

	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

	def cleanup(self):
		self.dotfile.remove()
		self.pngfile.remove()
开发者ID:damiansimanuk,项目名称:texslide,代码行数:28,代码来源:diagrameditor.py

示例11: DiagramGenerator

class DiagramGenerator(ImageGeneratorClass):

    uses_log_file = False

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

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

    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

    def cleanup(self):
        self.dotfile.remove()
        self.pngfile.remove()
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:32,代码来源:diagrameditor.py

示例12: SequenceDiagramGenerator

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()
开发者ID:hjq300,项目名称:zim-wiki,代码行数:30,代码来源:sequencediagrameditor.py

示例13: parse_exec

    def parse_exec(self, args=None):
        if not (isinstance(args, tuple) and len(args) == 3):
            raise AssertionError, 'Custom commands needs 3 arguments'
            # assert statement could be optimized away
        notebook, page, pageview = args

        cmd = split_quoted_strings(self['Desktop Entry']['X-Zim-ExecTool'])
        if '%f' in cmd:
            self._tmpfile = TmpFile('tmp-page-source.txt')
            self._tmpfile.writelines(page.dump('wiki'))
            cmd[cmd.index('%f')] = self._tmpfile.path

        if '%d' in cmd:
            dir = notebook.get_attachments_dir(page)
            if dir:
                cmd[cmd.index('%d')] = dir.path
            else:
                cmd[cmd.index('%d')] = ''

        if '%s' in cmd:
            if hasattr(page, 'source') and isinstance(page.source, File):
                cmd[cmd.index('%s')] = page.source.path
            else:
                cmd[cmd.index('%s')] = ''

        if '%n' in cmd:
            cmd[cmd.index('%n')] = File(notebook.uri).path

        if '%D' in cmd:
            dir = notebook.document_root
            if dir:
                cmd[cmd.index('%D')] = dir.path
            else:
                cmd[cmd.index('%D')] = ''

        if '%t' in cmd:
            text = pageview.get_selection() or pageview.get_word()
            cmd[cmd.index('%t')] = text or ''
            # FIXME - need to substitute this in arguments + url encoding

        if '%T' in cmd:
            text = pageview.get_selection(format='wiki') or pageview.get_word(format='wiki')
            cmd[cmd.index('%T')] = text or ''
            # FIXME - need to substitute this in arguments + url encoding

        return tuple(cmd)
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:46,代码来源:applications.py

示例14: DiagramGenerator

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):
		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:
			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()
开发者ID:gdw2,项目名称:zim,代码行数:40,代码来源:diagrameditor.py

示例15: __init__

	def __init__(self):
		self.dotfile = TmpFile('diagram-editor.dot')
		self.dotfile.touch()
		self.pngfile = File(self.dotfile.path[:-4] + '.png') # len('.dot') == 4
开发者ID:damiansimanuk,项目名称:texslide,代码行数:4,代码来源:diagrameditor.py


注:本文中的zim.fs.TmpFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。