コード例 #1
0
    def translate_client_path(self, client_path):
        """Translate a path received from a network client into a local
        relpath.

        All paths received from the client *must* be translated.

        :param client_path: the path from the client.
        :returns: a relpath that may be used with self._backing_transport
            (unlike the untranslated client_path, which must not be used with
            the backing transport).
        """
        if self._root_client_path is None:
            # no translation necessary!
            return client_path
        if not client_path.startswith('/'):
            client_path = '/' + client_path
        if client_path + '/' == self._root_client_path:
            return '.'
        if client_path.startswith(self._root_client_path):
            path = client_path[len(self._root_client_path):]
            relpath = urlutils.joinpath('/', path)
            if not relpath.startswith('/'):
                raise ValueError(relpath)
            return urlutils.escape('.' + relpath)
        else:
            raise errors.PathNotChild(client_path, self._root_client_path)
コード例 #2
0
    def translate_client_path(self, client_path):
        """Translate a path received from a network client into a local
        relpath.

        All paths received from the client *must* be translated.

        :param client_path: the path from the client.
        :returns: a relpath that may be used with self._backing_transport
            (unlike the untranslated client_path, which must not be used with
            the backing transport).
        """
        if self._root_client_path is None:
            # no translation necessary!
            return client_path
        if not client_path.startswith('/'):
            client_path = '/' + client_path
        if client_path + '/' == self._root_client_path:
            return '.'
        if client_path.startswith(self._root_client_path):
            path = client_path[len(self._root_client_path):]
            relpath = urlutils.joinpath('/', path)
            if not relpath.startswith('/'):
                raise ValueError(relpath)
            return urlutils.escape('.' + relpath)
        else:
            raise errors.PathNotChild(client_path, self._root_client_path)
コード例 #3
0
ファイル: bzr.py プロジェクト: jelmer/wikkid
    def list_directory(self, directory_path):
        """Return a list of File objects for in the directory path.

        If the path doesn't exist, returns None.  If the path exists but is
        empty, an empty list is returned.  Otherwise a list of File objects in
        that directory.
        """
        if directory_path is not None:
            directory = self.get_file(directory_path)
            if directory is None or directory.file_type != FileType.DIRECTORY:
                return None
        listing = []
        wt = self.tree
        wt.lock_read()
        try:
            for fp, fc, fkind, fid, entry in wt.list_files(
                from_dir=directory_path, recursive=False):
                if fc != 'V':
                    # If the file isn't versioned, skip it.
                    continue
                if directory_path is None:
                    file_path = fp
                else:
                    file_path = joinpath(directory_path, fp)
                listing.append(File(self, file_path, fid))
            return listing
        finally:
            wt.unlock()
コード例 #4
0
ファイル: loader.py プロジェクト: jelmer/wikkid
 def static_dir(self):
     location = os.path.abspath(
         urlutils.joinpath(self.dir_name, 'static'))
     if os.path.exists(location):
         return location
     else:
         return None
コード例 #5
0
ファイル: loader.py プロジェクト: jelmer/wikkid
 def favicon(self):
     location = os.path.abspath(
         urlutils.joinpath(self.dir_name, 'favicon.ico'))
     if os.path.exists(location):
         return location
     else:
         return None
コード例 #6
0
ファイル: bzr.py プロジェクト: jelmer/wikkid
def iter_paths(path):
    path_segments = splitpath(path)
    while len(path_segments) > 0:
        tail = path_segments.pop()
        if len(path_segments) == 0:
            yield '', tail
        else:
            yield joinpath(*path_segments), tail
コード例 #7
0
ファイル: dispatcher.py プロジェクト: jelmer/wikkid
def load_view_modules():
    curr_dir = os.path.abspath(dirname(__file__))
    view_dir = joinpath(curr_dir, 'view')
    py_files = [
        filename for filename in os.listdir(view_dir)
        if filename.endswith('.py') and not filename.startswith('__')]
    for filename in py_files:
        __import__('wikkid.view.%s' % filename[:-3])
コード例 #8
0
 def _setup_edited_file(self, relpath='.'):
     """Create a tree with a locally edited file."""
     tree = self.make_branch_and_tree(relpath)
     file_relpath = joinpath(relpath, 'file')
     self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
     tree.add('file')
     tree.commit('add file', committer="test@host", rev_id="rev1")
     self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
     return tree
コード例 #9
0
ファイル: factory.py プロジェクト: jelmer/wikkid
    def get_preferred_path(self, path):
        """Get the preferred path for the path passed in.

        If the path ends with '.txt' and doesn't have any other '.'s in the
        basename, then we prefer to access that file without the '.txt'.

        If the resulting path is the default path, then the preferred path
        should be '/Home' providing Home is the default path..
        """
        filename = basename(path)
        if filename.endswith('.txt'):
            filename = filename[:-4]

        if path == '/':
            return '/' + self.DEFAULT_PATH
        elif '.' in filename:
            return path
        else:
            return joinpath(dirname(path), filename)
コード例 #10
0
ファイル: loader.py プロジェクト: jelmer/wikkid
 def __init__(self, skin_name=None):
     """Load the required templates."""
     # Need to load the initial templates for the skin.
     if skin_name is None:
         skin_name = 'default'
     self.logger = logging.getLogger('wikkid')
     # TODO: if we are using a user defined directory for the skin, here is
     # where we'd use a different loader.
     loader = PackageLoader('wikkid.skin', skin_name)
     self.env = Environment(loader=loader)
     self.templates = {
         'view_page': self.env.get_template('page.html'),
         'edit_page': self.env.get_template('edit.html'),
         'view_directory': self.env.get_template('directory_listing.html'),
         'missing': self.env.get_template('missing-page.html'),
         'missing-dir' : self.env.get_template('missing-directory.html')
         }
     module_location = urlutils.dirname(__file__)
     self.dir_name = urlutils.joinpath(module_location, skin_name)
コード例 #11
0
ファイル: test_urlutils.py プロジェクト: GymWenFLL/tpp_libs
 def test(expected, *args):
     joined = urlutils.joinpath(*args)
     self.assertEqual(expected, joined)
コード例 #12
0
ファイル: transport.py プロジェクト: pombredanne/launchpad-3
 def _abspath(self, relpath):
     """Return the absolute, escaped path to `relpath` without the schema.
     """
     return urlutils.joinpath(self.base[len(self.server.get_url()) - 1:],
                              relpath)
コード例 #13
0
 def test(expected, *args):
     joined = urlutils.joinpath(*args)
     self.assertEqual(expected, joined)
コード例 #14
0
 def _abspath(self, relpath):
     """Return the absolute, escaped path to `relpath` without the schema.
     """
     return urlutils.joinpath(
         self.base[len(self.server.get_url())-1:], relpath)