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


Python fs.File类代码示例

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


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

示例1: 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

示例2: 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

示例3: testSaveCopyDialog

	def testSaveCopyDialog(self):
		'''Test SaveCopyDialog'''
		tmp_dir = self.create_tmp_dir('testSaveCopyDialog')
		file = File((tmp_dir, 'save_copy.txt'))
		self.assertFalse(file.exists())
		dialog = zim.gui.SaveCopyDialog(self.ui)
		dialog.set_file(file)
开发者ID:Jam71,项目名称:Zim-QDA,代码行数:7,代码来源:gui.py

示例4: 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

示例5: 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

示例6: 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

示例7: get_template

def get_template(format, template):
	'''Returns a Template object for a template name, file path, or File object'''
	# NOTE: here the "category" needs to be a format at the same time !
	if isinstance(template, File):
		file = template
	else:
		if not is_path_re.match(template):
			file = None
			path = list(data_dirs(('templates', format)))
			path.reverse()
			for dir in path:
				for basename in dir.list():
					name = basename.rsplit('.')[0] # robust if no '.' in basename
					if name == template:
						file = dir.file(basename)
						if file.exists(): # is a file
							break

			if not file:
				file = File(template)
		else:
			file = File(template)

	logger.info('Loading template from: %s', file)
	if not file.exists():
		raise AssertionError, 'No such file: %s' % file

	basename, ext = file.basename.rsplit('.', 1)
	resources = file.dir.subdir(basename)

	return Template(file.readlines(), format, name=file.path, resources_dir=resources)
开发者ID:gdw2,项目名称:zim,代码行数:31,代码来源:templates.py

示例8: testImportPageDialog

	def testImportPageDialog(self):
		'''Test ImportPageDialog'''
		tmp_dir = self.create_tmp_dir('testImportPageDialog')
		file = File((tmp_dir, 'import_page.txt'))
		file.write('test 123\n')
		self.assertTrue(file.exists())
		dialog = zim.gui.ImportPageDialog(self.ui)
		dialog.set_file(file)
开发者ID:Jam71,项目名称:Zim-QDA,代码行数:8,代码来源:gui.py

示例9: runTest

	def runTest(self):
		tmp_dir = self.create_tmp_dir()

		file = File((tmp_dir, 'test.txt'))
		file.write('test 123')
		self.assertTrue(file.exists())

		dialog = FileDialog(None, 'Test')
		dialog.set_file(file)
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:9,代码来源:widgets.py

示例10: runTest

	def runTest(self):
		from pprint import pprint

		from zim.fs import File
		file = File('./tests/data/TestTemplate.html')

		templ = Template(file)
		#~ pprint(templ.parts) # parser output

		output = []
		templ.process(output, {
			'title': 'THIS IS THE TITLE',
			'generator': {
				'name': 'ZIM VERSION',
			},
			'navigation': {
				'prev': None,
				'next': None,
			},
			'links': {},
			'pages': [
				{ # page
					'name': 'page',
					'heading': 'HEAD',
					'body': 'BODY',
					'properties': {
						'type': 'PAGE',
					},
					'backlinks': [
						{'name': 'LINK1'},
						{'name': 'LINK2'},
						{'name': 'LINK3'},
					],
					'attachments': [
						{'name': 'FILE1', 'basename': 'FILE1', 'size': '1k'},
						{'name': 'FILE2', 'basename': 'FILE2', 'size': '1k'},
					],
				},
			],
			'uri': ExpressionFunction(lambda l: "URL:%s" % l['name']),
			'anchor': ExpressionFunction(lambda l: "ANCHOR:%s" % l['name']),
		})
		#~ print ''.join(output)

		# TODO assert something

		### Test empty template OK as well
		dir = Dir(self.create_tmp_dir())
		file = dir.file('empty.html')

		self.assertRaises(FileNotFoundError, Template, file)

		file.touch()
		templ = Template(file)
		output = []
		templ.process(output, {})
		self.assertEqual(output, [])
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:57,代码来源:templates.py

示例11: get_template

def get_template(format, name):
	'''Returns a Template object for a tempalte name or a file path'''
	if is_path_re.match(name):
		file = File(name)
	else:
		templates = list_templates(format)
		#~ if not name in templates: FIXME exception type
			#~ raise
		file = File(templates[name])
	logger.info('Loading template from: %s', file)
	return Template(file.readlines(), format, name=file)
开发者ID:damiansimanuk,项目名称:texslide,代码行数:11,代码来源:templates.py

示例12: get_file

	def get_file(self):
		file = File(self.uistate['output_file'])
		if file.exists():
			ok = QuestionDialog(self, (
				_('File exists'), # T: message heading
				_('This file already exists.\n'
				  'Do you want to overwrite it?' ) # T: detailed message, answers are Yes and No
			) ).run()
			if not ok:
				return None
		return file
开发者ID:fabricehong,项目名称:zim-desktop,代码行数:11,代码来源:exportdialog.py

示例13: delete_file

	def delete_file(self, file=None, refresh=False):
		'''Deletes a file and refreshes the treeview if refresh == True'''
		if not file:
			file = self.selected_file
			refresh = True
		logger.debug('Deleting %s' % file)
		file = File(file)
		if file.exists():
			file.cleanup()
		if refresh:
			self.treeview.model.remove(self.iter)
开发者ID:thejeshgn,项目名称:Zim,代码行数:11,代码来源:cleannotebookdialog.py

示例14: testFS

	def testFS(self):
		'''Test async FS operations'''

		self.path = self.create_tmp_dir('testFS')+'/file.txt'

		file = File(self.path)

		op1 = file.write_async('foo bar 1\n')
		op2 = file.write_async('foo bar 2\n')

		op1.wait()
		op2.wait()

		self.assertEqual(file.read(), 'foo bar 2\n')
开发者ID:Jam71,项目名称:Zim-QDA,代码行数:14,代码来源:async.py

示例15: _link_tree

def _link_tree(links, notebook, path):
	# Convert a list of links (of any type) into a parsetree
	#~ print 'LINKS: ', links
	#~ print 'NOTEBOOK and PATH:', notebook, path
	builder = TreeBuilder()
	builder.start('zim-tree')
	for i in range(len(links)):
		if i > 0:
			builder.data(' ')

		link = links[i]
		type = link_type(link)
		isimage = False
		if type == 'file':
			try:
				file = File(link)
				isimage = file.isimage()
			except:
				pass

		logger.debug('Pasting link: %s (type: %s, isimage: %s)', link, type, isimage)

		if isimage:
			src = notebook.relative_filepath(file, path) or file.uri
			builder.start('img', {'src': src})
			builder.end('img')
		elif link.startswith('@'):
			# FIXME - is this ever used ??
			builder.start('tag', {'name': links[i][1:]})
			builder.data(links[i])
			builder.end('tag')
		else:
			if type == 'page':
				href = Path(notebook.cleanup_pathname(link)) # Assume links are always absolute
				link = notebook.relative_link(path, href) or link
			elif type == 'file':
				file = File(link) # Assume links are always URIs
				link = notebook.relative_filepath(file, path) or file.uri

			builder.start('link', {'href': link})
			builder.data(link)
			builder.end('link')

	builder.end('zim-tree')
	tree = ParseTree(builder.close())
	tree.resolve_images(notebook, path)
	tree.decode_urls()
	return tree
开发者ID:thejeshgn,项目名称:Zim,代码行数:48,代码来源:clipboard.py


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