• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python fs.TmpFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CustomToolDict

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,代码行数:101,代码来源:applications.py


示例17: testTmpFile

	def testTmpFile(self):
		'''Test TmpFile object'''
		dir = get_tmpdir()
		file = TmpFile('foo.txt')
		self.assertTrue(file.ischild(dir))
开发者ID:damiansimanuk,项目名称:texslide,代码行数:5,代码来源:fs.py


示例18: __init__

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


示例19: on_print_tasklist

	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
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:5,代码来源:printtobrowser.py


示例20: _get_tmp_file

	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,代码行数:6,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python widgets.Dialog类代码示例发布时间:2022-05-26
下一篇:
Python fs.File类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap