Beispiel #1
0
    def absolute_pathname(self, internal_pathname):
        """Convert a warebox relative pathname into the corresponding
        filesystem absolute pathname.

        @param internal_pathname:
                    A pathname relative to the warebox.
        @return
                    The filesystem absolute version of internal_pathname.
        """

        absolute_name = fastjoin(self._warebox_path, internal_pathname)
        n = fastnormpath(absolute_name)
        return n
Beispiel #2
0
    def get_content(self,
                    folder=u'',
                    recursive=True,
                    blacklisted=True,
                    interruption=None):
        """Get the list of pathnames contained in the given folder.

        If "folder" is omitted than a list of the whole Warebox is
        returned.

        @param folder:
                    A warebox relative directory of the warebox to whom
                    read the content.
        @param recursive:
                    Boolean telling whether the scan should be recursive.
        @param blacklisted:
                    Boolean telling whether blacklisted pathnames must
                    be returned too.
        @return
                    List of pathnames.
        """
        pathnames = []
        abs_folder = self.absolute_pathname(folder)

        for curr_folder, contained_folders, contained_files in os.walk(abs_folder):
            self._check_interruption(interruption)
            folders_to_not_walk_into = []
            #prefix = os.path.relpath(curr_folder, self._warebox_path)
            #if prefix == u'.':
                #prefix = u''
            prefix = fastrelpath(curr_folder, self._warebox_path)

            for a_folder in contained_folders:
                self._check_interruption(interruption)
                _a_folder = fastjoin(prefix, a_folder)
                _a_folder = _a_folder.replace('\\', '/')  # Damn Windows
                _a_folder += '/' if not _a_folder.endswith('/') else ''
                if not blacklisted or not self.is_blacklisted(_a_folder):
                    pathnames.append(_a_folder)
                else:
                    folders_to_not_walk_into.append(a_folder)

                # It seems that get_content() can return non-unicode pathnames.
                # This guard checks against it.
                self._assert_unicode(
                    _a_folder, self._warebox_path, folder,
                    abs_folder, prefix, a_folder)

            for folder in folders_to_not_walk_into:
                contained_folders.remove(folder)

            for a_file in contained_files:
                self._check_interruption(interruption)
                _a_file = fastjoin(prefix, a_file)
                _a_file = _a_file.replace('\\', '/')  # Damn Windows
                if self._can_i_add_this_file(blacklisted, _a_file):
                    pathnames.append(_a_file)

                # It seems that get_content() can return non-unicode pathnames.
                # This guard checks against it.
                self._assert_unicode(
                    _a_file, self._warebox_path, folder,
                    abs_folder, prefix, a_file)

            if not recursive:
                break

        all_pathnames = set(self.cache.get_all_keys())
        self.cache.delete_records(all_pathnames.difference(set(pathnames)))
        return pathnames