示例#1
0
    def get_member_list(self):
        member_list = []
        d = self.obj

        if d.version == 0:
            file_mtimes = []
            try:
                file_mtimes = seafile_api.get_files_last_modified(self.repo.id, self.rel_path, -1)
            except:
                raise DAVError(HTTP_INTERNAL_ERROR)

            mtimes = {}
            for entry in file_mtimes:
                mtimes[entry.file_name] = entry.last_modified
        for name, dent in d.dirents.items():
            member_path = posixpath.join(self.path, name)
            member_rel_path = posixpath.join(self.rel_path, name)

            if dent.is_dir():
                obj = fs_mgr.load_seafdir(d.store_id, d.version, dent.id)
                res = SeafDirResource(member_path, self.repo, member_rel_path, obj, self.environ)
            elif dent.is_file():
                obj = fs_mgr.load_seafile(d.store_id, d.version, dent.id)
                res = SeafileResource(member_path, self.repo, member_rel_path, obj, self.environ)
            else:
                continue

            if d.version == 1:
                obj.last_modified = dent.mtime
            else:
                obj.last_modified = mtimes[name]

            member_list.append(res)

        return member_list
    def getMemberList(self):
        member_list = []
        d = self.obj

        if d.version == 0:
            file_mtimes = []
            try:
                file_mtimes = seafile_api.get_files_last_modified(self.repo.id, self.rel_path, -1)
            except:
                raise DAVError(HTTP_INTERNAL_ERROR)

            mtimes = UTF8Dict()
            for entry in file_mtimes:
                mtimes[entry.file_name] = entry.last_modified
        for name, dent in d.dirents.iteritems():
            member_path = utf8_path_join(self.path, name)
            member_rel_path = utf8_path_join(self.rel_path, name)

            if dent.is_dir():
                obj = fs_mgr.load_seafdir(d.store_id, d.version, dent.id)
                res = SeafDirResource(member_path, self.repo, member_rel_path, obj, self.environ)
            elif dent.is_file():
                obj = fs_mgr.load_seafile(d.store_id, d.version, dent.id)
                res = SeafileResource(member_path, self.repo, member_rel_path, obj, self.environ)
            else:
                continue

            if d.version == 1:
                obj.last_modified = dent.mtime
            else:
                obj.last_modified = mtimes[name]

            member_list.append(res)

        return member_list
    def getLastModified(self):
        cached_mtime = getattr(self.obj, 'last_modified', None)
        if cached_mtime:
            return cached_mtime

        parent, filename = os.path.split(self.rel_path)
        mtimes = seafile_api.get_files_last_modified(self.repo.id, parent, -1)
        for mtime in mtimes:
            if (mtime.file_name.encode('utf-8') == filename):
                return mtime.last_modified

        return None
    def getLastModified(self):
        cached_mtime = getattr(self.obj, 'last_modified', None)
        if cached_mtime:
            return cached_mtime

        parent, filename = os.path.split(self.rel_path)
        mtimes = seafile_api.get_files_last_modified(self.repo.id, parent, -1)
        for mtime in mtimes:
            if (mtime.file_name.encode('utf-8') == filename):
                return mtime.last_modified

        return None
    def getLastModified(self):
        cached_mtime = getattr(self.obj, 'last_modified', None)
        if cached_mtime:
            return cached_mtime

        if self.obj.mtime > 0:
            return self.obj.mtime

        # XXX: What about not return last modified for files in v0 repos,
        # since they can be too expensive sometimes?
        parent, filename = os.path.split(self.rel_path)
        mtimes = seafile_api.get_files_last_modified(self.repo.id, parent, -1)
        for mtime in mtimes:
            if (mtime.file_name.encode('utf-8') == filename):
                return mtime.last_modified

        return None
示例#6
0
    def get_last_modified(self):
        cached_mtime = getattr(self.obj, 'last_modified', None)
        if cached_mtime:
            return cached_mtime

        if self.obj.mtime > 0:
            return self.obj.mtime

        # XXX: What about not return last modified for files in v0 repos,
        # since they can be too expensive sometimes?
        parent, filename = os.path.split(self.rel_path)
        mtimes = seafile_api.get_files_last_modified(self.repo.id, parent, -1)
        for mtime in mtimes:
            if (mtime.file_name == filename):
                return mtime.last_modified

        return None
示例#7
0
    def _calc_dir_files_last_modified(self, repo_id, parent_dir,
                                      parent_dir_hash, dir_id):
        """
        
        Arguments:
        - `self`:
        - `repo_id`:
        - `parent_dir`:
        - `parent_dir_hash`:
        - `dir_id`:
        """
        try:
            ret_list = seafile_api.get_files_last_modified(
                repo_id, parent_dir, 0)
        except:
            return {}

        # ret_list is like:
        # [
        #    {'file_name': 'xxx', 'last_modified': t1}
        #    {'file_name': 'yyy', 'last_modified': t2}
        # ]
        # and we transform it to:
        # {'xxx': t1, 'yyy': t2}
        last_modified_info = {}
        for entry in ret_list:
            key = entry.file_name
            value = entry.last_modified
            last_modified_info[key] = value

        info = self.model(repo_id=repo_id,
                          parent_dir=parent_dir,
                          parent_dir_hash=parent_dir_hash,
                          dir_id=dir_id,
                          last_modified_info=json.dumps(last_modified_info))

        try:
            info.save()
        except IntegrityError, e:
            # If this record is already saved, skip this step.
            pass
示例#8
0
    def _calc_dir_files_last_modified(self, repo_id, parent_dir, parent_dir_hash, dir_id):
        """
        
        Arguments:
        - `self`:
        - `repo_id`:
        - `parent_dir`:
        - `parent_dir_hash`:
        - `dir_id`:
        """
        try:
            ret_list = seafile_api.get_files_last_modified(repo_id, parent_dir, 0)
        except:
            return {}

        # ret_list is like:
        # [
        #    {'file_name': 'xxx', 'last_modified': t1}
        #    {'file_name': 'yyy', 'last_modified': t2}
        # ]
        # and we transform it to:
        # {'xxx': t1, 'yyy': t2}
        last_modified_info = {}
        for entry in ret_list:
            key = entry.file_name
            value = entry.last_modified
            last_modified_info[key] = value

        info = self.model(
            repo_id=repo_id,
            parent_dir=parent_dir,
            parent_dir_hash=parent_dir_hash,
            dir_id=dir_id,
            last_modified_info=json.dumps(last_modified_info),
        )

        try:
            info.save()
        except IntegrityError, e:
            # If this record is already saved, skip this step.
            pass