From commits-return-20588-archive-asf-public=cust-asf.ponee.io@airavata.apache.org Wed May 22 23:17:12 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C8208180651 for ; Thu, 23 May 2019 01:17:11 +0200 (CEST) Received: (qmail 43455 invoked by uid 500); 22 May 2019 23:17:11 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 43446 invoked by uid 99); 22 May 2019 23:17:11 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 May 2019 23:17:11 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 99DCD85D9C; Wed, 22 May 2019 23:17:07 +0000 (UTC) Date: Wed, 22 May 2019 23:17:10 +0000 To: "commits@airavata.apache.org" Subject: [airavata-django-portal] 03/04: AIRAVATA-3033 delete dir API MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: machristie@apache.org In-Reply-To: <155856702749.1767.11903947991611546596@gitbox.apache.org> References: <155856702749.1767.11903947991611546596@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: airavata-django-portal X-Git-Refname: refs/heads/airavata-3016 X-Git-Reftype: branch X-Git-Rev: 51534098c8f4243aec3cc6eeab2c6eddfc9feffa X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190522231707.99DCD85D9C@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. machristie pushed a commit to branch airavata-3016 in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git commit 51534098c8f4243aec3cc6eeab2c6eddfc9feffa Author: Marcus Christie AuthorDate: Wed May 22 19:15:28 2019 -0400 AIRAVATA-3033 delete dir API --- django_airavata/apps/api/data_products_helper.py | 4 ++++ django_airavata/apps/api/datastore.py | 14 ++++++++++++++ django_airavata/apps/api/serializers.py | 1 + django_airavata/apps/api/views.py | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/django_airavata/apps/api/data_products_helper.py b/django_airavata/apps/api/data_products_helper.py index 51f8951..ef550e4 100644 --- a/django_airavata/apps/api/data_products_helper.py +++ b/django_airavata/apps/api/data_products_helper.py @@ -42,6 +42,10 @@ def dir_exists(request, path): return datastore.exists(request.user.username, path) +def delete_dir(request, path): + return datastore.delete_dir(request.user.username, path) + + def delete(request, data_product): "Delete replica for data product in this data store." path = _get_replica_filepath(data_product) diff --git a/django_airavata/apps/api/datastore.py b/django_airavata/apps/api/datastore.py index 220803f..c1663eb 100644 --- a/django_airavata/apps/api/datastore.py +++ b/django_airavata/apps/api/datastore.py @@ -1,5 +1,6 @@ import logging import os +import shutil from django.conf import settings from django.core.exceptions import ObjectDoesNotExist, SuspiciousFileOperation @@ -63,6 +64,15 @@ def delete(username, path): raise ObjectDoesNotExist("File path does not exist: {}".format(path)) +def delete_dir(username, path): + """Delete entire directory in this data store.""" + if exists(username, path): + user_path = path_(username, path) + shutil.rmtree(user_path) + else: + raise ObjectDoesNotExist("File path does not exist: {}".format(path)) + + # TODO: update this to just return an available experiment directory name def get_experiment_dir( username, @@ -110,6 +120,10 @@ def list_user_dir(username, file_path): def path(username, file_path): + return path_(username, file_path) + + +def path_(username, file_path): user_data_storage = _user_data_storage(username) return user_data_storage.path(file_path) diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py index 1f0d69e..e1aff77 100644 --- a/django_airavata/apps/api/serializers.py +++ b/django_airavata/apps/api/serializers.py @@ -751,6 +751,7 @@ class ParserSerializer(thrift_utils.create_serializer_class(Parser)): class UserStorageFileSerializer(serializers.Serializer): name = serializers.CharField() downloadURL = serializers.SerializerMethodField() + dataProductURI = serializers.CharField(source='data-product-uri') def get_downloadURL(self, file): """Getter for downloadURL field.""" diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py index caf1c35..dc0abfa 100644 --- a/django_airavata/apps/api/views.py +++ b/django_airavata/apps/api/views.py @@ -1342,6 +1342,7 @@ class UserStoragePathView(APIView): serializer_class = serializers.UserStoragePathSerializer def get(self, request, path="/", format=None): + # TODO: don't need to relativize path any longer? user_storage_path = path if user_storage_path.startswith("/"): user_storage_path = "." + user_storage_path @@ -1361,6 +1362,13 @@ class UserStoragePathView(APIView): request, user_storage_path, user_file) return self._create_response(request, path, uploaded=data_product) + def delete(self, request, path="/", format=None): + user_storage_path = path + if user_storage_path.startswith("/"): + user_storage_path = "." + user_storage_path + data_products_helper.delete_dir(request, user_storage_path) + return Response(status=204) + def _create_response(self, request, path, uploaded=None): directories, files = data_products_helper.listdir(request, path) data = {