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


Python TmpFile.writelines方法代码示例

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


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

示例1: DiagramGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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,代码行数:34,代码来源:diagrameditor.py

示例2: DitaaGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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.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

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

示例3: SequenceDiagramGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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):
		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

	def cleanup(self):
		self.diagfile.remove()
		self.pngfile.remove()
开发者ID:gdw2,项目名称:zim,代码行数:35,代码来源:sequencediagrameditor.py

示例4: print_to_file

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
	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,代码行数:9,代码来源:printtobrowser.py

示例5: DiagramGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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,代码行数:30,代码来源:diagrameditor.py

示例6: PlantumlGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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,代码行数:35,代码来源:plantumleditor.py

示例7: EquationGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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,代码行数:52,代码来源:equationeditor.py

示例8: show_side_by_side

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
	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,代码行数:16,代码来源:__init__.py

示例9: print_to_file

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
	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,代码行数:17,代码来源:printtobrowser.py

示例10: print_to_file

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
    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,代码行数:23,代码来源:printtobrowser.py

示例11: DiagramGenerator

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
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,代码行数:42,代码来源:diagrameditor.py

示例12: CustomToolDict

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
class CustomToolDict(DesktopEntryDict):
    '''This is a specialized desktop entry type that is used for
    custom tools for the "Tools" menu in zim. It uses a non-standard
    Exec spec with zim specific escapes for "X-Zim-ExecTool".

    The following fields are expanded:
        - C{%f} for source file as tmp file current page
        - C{%d} for attachment directory
        - C{%s} for real source file (if any)
        - C{%n} for notebook location (file or directory)
        - C{%D} for document root
        - C{%t} for selected text or word under cursor
        - C{%T} for the selected text including wiki formatting

    Other additional keys are:
        - C{X-Zim-ReadOnly} - boolean
        - C{X-Zim-ShowInToolBar} - boolean
        - C{X-Zim-ShowInContextMenu} - 'None', 'Text' or 'Page'

    These tools should always be executed with 3 arguments: notebook,
    page & pageview.
    '''

    _key_types = {
        'X-Zim-ExecTool': 'string',
        'X-Zim-ReadOnly': 'boolean',
        'X-Zim-ShowInToolBar': 'boolean',
    }
    _key_types.update(DesktopEntryDict._key_types)

    def isvalid(self):
        '''Check if all required fields are set.
        @returns: C{True} if all required fields are set
        '''
        entry = self['Desktop Entry']
        if entry.get('Type') == 'X-Zim-CustomTool' \
        and entry.get('Version') == 1.0 \
        and entry.get('Name') \
        and entry.get('X-Zim-ExecTool') \
        and not entry.get('X-Zim-ReadOnly') is None \
        and not entry.get('X-Zim-ShowInToolBar') is None \
        and 'X-Zim-ShowInContextMenu' in entry:
            return True
        else:
            logger.error('Invalid custom tool entry: %s %s', self.key, entry)
            return False

    def get_pixbuf(self, size):
        pixbuf = DesktopEntryDict.get_pixbuf(self, size)
        if pixbuf is None:
            pixbuf = gtk.Label().render_icon(gtk.STOCK_EXECUTE, size)
            # FIXME hack to use arbitrary widget to render icon
        return pixbuf

    @property
    def icon(self):
        return self['Desktop Entry'].get('Icon') or gtk.STOCK_EXECUTE
            # get('Icon', gtk.STOCK_EXECUTE) still returns empty string if key exists but no value

    @property
    def execcmd(self):
        return self['Desktop Entry']['X-Zim-ExecTool']

    @property
    def isreadonly(self):
        return self['Desktop Entry']['X-Zim-ReadOnly']

    @property
    def showintoolbar(self):
        return self['Desktop Entry']['X-Zim-ShowInToolBar']

    @property
    def showincontextmenu(self):
        return self['Desktop Entry']['X-Zim-ShowInContextMenu']

    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')] = ''

#.........这里部分代码省略.........
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:103,代码来源:applications.py

示例13: _get_tmp_file

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import writelines [as 别名]
	def _get_tmp_file(self, file, version):
		text = self.vcs.get_version(file, version)
		tmp = TmpFile(file.basename + '--REV%s' % version, persistent=True)
			# need to be persistent, else it is cleaned up before application spawned
		tmp.writelines(text)
		return tmp
开发者ID:gdw2,项目名称:zim,代码行数:8,代码来源:__init__.py


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