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_id_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) ret.sort(lambda x, y: cmp(y.last_modified, x.last_modified)) return ret
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_id_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_id_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) ret.sort(lambda x, y: cmp(y.last_modified, x.last_modified)) return ret
def get_file_last_modified(repo_id, file_path): email = '' last_modified = 0 file_path_hash = calc_file_path_hash(file_path) file_id = seafserv_threaded_rpc.get_file_id_by_path(repo_id, file_path) try: fc = FileLastModifiedInfo.objects.get(repo_id=repo_id, file_path_hash=file_path_hash) except FileLastModifiedInfo.DoesNotExist: # has no cache yet user, last_modified = calc_file_last_modified(repo_id, file_path, file_path_hash, file_id) else: # cache found if fc.file_id != file_id: # but cache is outdated fc.delete() user, last_modified = calc_file_last_modified(repo_id, file_path, file_path_hash, file_id) else: # cache is valid user, last_modified = fc.email, fc.last_modified return user, last_modified
def get(self, request, repo_id, format=None): # view file repo = get_repo(repo_id) if not repo: return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.') resp = check_repo_access_permission(request, repo) if resp: return resp path = request.GET.get('p', None) if not path: return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.') file_name = os.path.basename(path) file_id = None try: file_id = seafserv_threaded_rpc.get_file_id_by_path( repo_id, path.encode('utf-8')) except SearpcError, e: return api_error(HTTP_520_OPERATION_FAILED, "Failed to get file id by path.")
def get(self, request, repo_id, format=None): # view file repo = get_repo(repo_id) if not repo: return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.') resp = check_repo_access_permission(request, repo) if resp: return resp path = request.GET.get('p', None) if not path: return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.') file_name = os.path.basename(path) file_id = None try: file_id = seafserv_threaded_rpc.get_file_id_by_path(repo_id, path.encode('utf-8')) except SearpcError, e: return api_error(HTTP_520_OPERATION_FAILED, "Failed to get file id by path.")
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_id_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