本文整理匯總了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()
示例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()
示例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)
示例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()
示例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()
示例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()
示例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)
示例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)
示例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)
示例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, [])
示例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)
示例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
示例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)
示例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')
示例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