def get(self, request, repo_id): repo = get_repo(repo_id) resp = check_repo_access_permission(request, repo) if resp: return resp path = request.GET.get('p', None) if not path: return api_error(request, '413') file_id = None try: file_id = seafserv_threaded_rpc.get_file_by_path(repo_id, path.encode('utf-8')) except SearpcError, e: return api_error(request, '412', "SearpcError:" + e.msg)
def get_starred_files(email, org_id=-1): """Return a list of starred files for some user, sorted descending by the last modified time. """ starred_files = UserStarredFiles.objects.filter(email=email, org_id=org_id) ret = [] for sfile in starred_files: # repo still exists? try: repo = get_repo(sfile.repo_id) except SearpcError: continue if not repo: sfile.delete() continue # file still exists? file_id = '' size = -1; if sfile.path != "/": try: file_id = seafserv_threaded_rpc.get_file_by_path(sfile.repo_id, sfile.path) size = seafserv_threaded_rpc.get_file_size(file_id) except SearpcError: continue if not file_id: sfile.delete() continue last_modified = 0 if not sfile.is_dir: # last modified path_hash = md5_constructor(urllib2.quote(sfile.path.encode('utf-8'))).hexdigest()[:12] last_modified = get_file_contributors(sfile.repo_id, sfile.path, path_hash, file_id)[1] f = StarredFile(sfile.org_id, repo, sfile.path, sfile.is_dir, last_modified, size) ret.append(f) # First sort by repo # Within the same repo: # dir > file # dirs are sorted by name ascending # files are sorted by last_modified descending def sort_func(fa, fb): # Different repo? if fa.repo.id != fb.repo.id: ret = cmp(fa.repo.name, fb.repo.name) if ret != 0: return ret else: # two different repo has the same name, compare the id return cmp(fa.repo.id, fb.repo.id) # OK, same repo if fa.is_dir and fb.is_dir: return cmp(fa.path, fb.path) elif fa.is_dir and not fb.is_dir: return -1 elif fb.is_dir and not fa.is_dir: return 1 else: return cmp(fb.last_modified, fa.last_modified) ret.sort(sort_func) return ret