diff options
author | Andy Doan <andy.doan@linaro.org> | 2015-06-08 10:20:16 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2015-06-29 10:25:29 -0500 |
commit | e5529e826206a141970deda80c667c8eafdb8b4c (patch) | |
tree | 5e0b5a93e42900f957825ceb50f7d95e1a5b18ce | |
parent | 36a9f856df4c02b6384252130b4fbb8cd87c48ec (diff) |
convert dir_list logic to use artifact
Another place we need to remove local file references.
Change-Id: I1dba475054fec5ff06b42da46c2390143520fee5
-rw-r--r-- | license_protected_downloads/api/v1.py | 4 | ||||
-rw-r--r-- | license_protected_downloads/common.py | 11 | ||||
-rw-r--r-- | license_protected_downloads/views.py | 17 |
3 files changed, 14 insertions, 18 deletions
diff --git a/license_protected_downloads/api/v1.py b/license_protected_downloads/api/v1.py index 0b50852..8542b86 100644 --- a/license_protected_downloads/api/v1.py +++ b/license_protected_downloads/api/v1.py @@ -90,11 +90,10 @@ def file_server_post(request, path): def list_files_api(request, path): path = iri_to_uri(path) - url = path artifact = find_artifact(request, path) if artifact.isdir(): - listing = dir_list(url, path, human_readable=False) + listing = dir_list(artifact, human_readable=False) else: listing = [artifact.get_listing()] @@ -109,7 +108,6 @@ def list_files_api(request, path): }) data = json.dumps({"files": clean_listing}) - return HttpResponse(data, mimetype='application/json') diff --git a/license_protected_downloads/common.py b/license_protected_downloads/common.py index 0c06631..2693285 100644 --- a/license_protected_downloads/common.py +++ b/license_protected_downloads/common.py @@ -319,12 +319,11 @@ class LocalArtifact(Artifact): return os.path.isdir(self.full_path) -def dir_list(url, path, human_readable=True): - - artifacts = [] - if os.path.exists(path): - artifacts = [LocalArtifact(url, x, human_readable, path) - for x in os.listdir(path)] +def dir_list(artifact, human_readable=True): + path = artifact.full_path + url = artifact.url() + artifacts = [LocalArtifact(url, x, human_readable, path) + for x in os.listdir(path)] artifacts.sort(_sort_artifacts) listing = [] diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py index 33717b5..f73f2ab 100644 --- a/license_protected_downloads/views.py +++ b/license_protected_downloads/views.py @@ -247,13 +247,15 @@ def _check_build_info(request, build_info): return response -def _handle_dir_list(request, url, path): +def _handle_dir_list(request, artifact): # Generate a link to the parent directory (if one exists) - if url != '/' and url != '': - up_dir = "/" + os.path.split(url)[0] + url = artifact.url() + if url != '/': + up_dir = os.path.split(url)[0] else: up_dir = None + path = artifact.full_path header_content = _get_header_html_content(path) download = None if 'dl' in request.GET: @@ -264,7 +266,7 @@ def _handle_dir_list(request, url, path): rendered_files = {} rendered_files["Git Descriptions"] = render_descriptions(path) - dirlist = dir_list(url, path) + dirlist = dir_list(artifact) lics = [x['license_digest_list'] for x in dirlist if x['license_digest_list']] @@ -305,10 +307,7 @@ def _check_file_permission(request, artifact, internal): def file_server_get(request, path): - - url = path artifact = find_artifact(request, path) - path = artifact.full_path internal = get_client_ip(request) in config.INTERNAL_HOSTS if not internal: @@ -322,7 +321,7 @@ def file_server_get(request, path): return resp if artifact.isdir(): - return _handle_dir_list(request, url, path) + return _handle_dir_list(request, artifact) # prevent download of files like BUILD-INFO.txt if artifact.hidden(): @@ -331,7 +330,7 @@ def file_server_get(request, path): resp = _check_file_permission(request, artifact, internal) if resp: return resp - return send_file(path) + return send_file(artifact.full_path) def get_textile_files(request): |