def page_file(self, page):
     if page == self.namespace:
         return self.file
     elif page.ischild(self.namespace):
         name = page.relname(self.namespace)
     else:
         raise PathLookupError('%s not a child of %s' %
                               (page, self.namespace))
     return self.dir.file(encode_filename(name) + '.' + self.ext)
示例#2
0
    def init_uistate(self):
        # Switch between folder selection or file selection based
        # on whether we selected full notebook or single page in the
        # first page
        self.uistate.setdefault('output', 'multi_file')
        self.uistate.setdefault('output_folder', None, Dir)
        self.uistate.setdefault('index_page', '')
        self.uistate.setdefault('output_file', None, File)

        if self.uistate.get('format', '').startswith('MHTML'):
            # XXX make this a format property to be queried
            self.form.widgets['output:multi_file'].set_sensitive(False)
            self.form.widgets['output:single_file'].set_sensitive(False)
            self.form.widgets['output:single_file'].set_active(True)
        else:
            self.form.widgets['output:multi_file'].set_sensitive(True)
            self.form.widgets['output:single_file'].set_sensitive(True)

        self.form.widgets['output:multi_file'].show()
        self.form.widgets['output:single_file'].show()

        self.form['output'] = self.uistate['output']

        self.on_output_changed(None)

        # Set file name
        basename = self.uistate['selected_page'].basename
        format = self.uistate['format']
        if format.startswith('MHTML'):
            ext = 'mht'
        else:
            ext = zim.formats.get_format(format).info['extension']

        if self.uistate['output_file'] \
        and isinstance(self.uistate['output_file'], File):
            dir = self.uistate['output_file'].dir
            file = dir.file(encode_filename(basename + '.' + ext))
        else:
            file = File('~/' + encode_filename(basename + '.' + ext))
        self.uistate['output_file'] = file

        self.form['file'] = self.uistate['output_file']
        self.form['folder'] = self.uistate['output_folder']
 def page_file(self, page):
     if page.isroot:
         raise PathLookupError('Can not export: %s', page)
     elif self.namespace:
         if page.ischild(self.namespace):
             name = page.relname(self.namespace)
         else:
             # This layout can not store page == namespace !
             raise PathLookupError('%s not a child of %s' %
                                   (page, self.namespace))
     else:
         name = page.name
     return self.dir.file(encode_filename(name) + '.' + self.ext)
 def attachments_dir(self, page):
     if self.namespace:
         if page == self.namespace:
             return self.dir
         elif page.ischild(self.namespace):
             path = page.relname(self.namespace)
         else:
             raise PathLookupError('%s not a child of %s' %
                                   (page, self.namespace))
         name = page.relname(self.namespace)
     else:
         name = page.name
     return self.dir.folder(encode_filename(name))
示例#5
0
	def _link_notebook(self, link):
		if link.startswith('zim+'):
			link = link[4:]

		if '?' in link:
			link, path = link.split('?')
			# FIXME: code below is not robust because we don't know the
			# storage mode of linked notebook...
			path = url_decode(path) # was already encoded by interwiki_link()
			path = encode_filename(path).replace(' ', '_')
			return link + '/' + url_encode(path) + '.txt'
		else:
			return link
示例#6
0
文件: mhtml.py 项目: thorhans/zimt
	def export_iter(self, pages):
		basename = encode_filename(pages.name)
		folder = LocalFolder(get_tmpdir().subdir('mhtml_export_tmp_dir').path) # XXX
		if folder.exists():
			folder.remove_children()
		else:
			folder.touch()
		file = folder.file(basename + '.html')
		layout = SingleFileLayout(file, pages.prefix)
		exporter = SingleFileExporter(layout, self.template, 'html', document_root_url=self.document_root_url)

		for p in exporter.export_iter(pages):
			yield p

		encoder = MHTMLEncoder()
		linker = ExportLinker(pages.notebook, layout, output=file, usebase=True)
		self.file.write(encoder(layout, linker))
示例#7
0
 def page_object(self, path):
     '''Turn a L{Path} object in a relative link or URI'''
     return url_encode('/' + encode_filename(path.name) + '.html')