Logo Search packages:      
Sourcecode: zim version File versions  Download package

def zim::notebook::Notebook::resolve_file (   self,
  filename,
  path 
)

Resolves a file or directory path relative to a page. Returns a
File object. However the file does not have to exist.

File urls and paths that start with '~/' or '~user/' are considered
absolute paths and are returned unmodified.

In case the file path starts with '/' the the path is taken relative
to the document root - this can e.g. be a parent directory of the
notebook. Defaults to the home dir.

Other paths are considered attachments and are resolved relative
to the namespce below the page.

Because this is used to resolve file links and is supposed to be
platform independent it tries to convert windows filenames to
unix equivalents.

Definition at line 964 of file notebook.py.

00964                                             :
            '''Resolves a file or directory path relative to a page. Returns a
            File object. However the file does not have to exist.

            File urls and paths that start with '~/' or '~user/' are considered
            absolute paths and are returned unmodified.

            In case the file path starts with '/' the the path is taken relative
            to the document root - this can e.g. be a parent directory of the
            notebook. Defaults to the home dir.

            Other paths are considered attachments and are resolved relative
            to the namespce below the page.

            Because this is used to resolve file links and is supposed to be
            platform independent it tries to convert windows filenames to
            unix equivalents.
            '''
            filename = filename.replace('\\', '/')
            if filename.startswith('~') or filename.startswith('file:/'):
                  return File(filename)
            elif filename.startswith('/'):
                  dir = self.get_document_root() or Dir('/')
                  return dir.file(filename)
            elif is_win32_path_re.match(filename):
                  if not filename.startswith('/'):
                        filename = '/'+filename
                        # make absolute on unix
                  return File(filename)
            else:
                  # TODO - how to deal with '..' in the middle of the path ?
                  filepath = [p for p in filename.split('/') if len(p) and p != '.']
                  if not filepath: # filename is e.g. "."
                        return self.get_attachments_dir(path)
                  pagepath = path.name.split(':')
                  filename = filepath.pop()
                  while filepath and filepath[0] == '..':
                        if not pagepath:
                              print 'TODO: handle paths relative to notebook but outside notebook dir'
                              return File('/TODO')
                        else:
                              filepath.pop(0)
                              pagepath.pop()
                  pagename = ':'+':'.join(pagepath + filepath)
                  dir = self.get_attachments_dir(Path(pagename))
                  return dir.file(filename)

      def relative_filepath(self, file, path=None):


Generated by  Doxygen 1.6.0   Back to index