airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] 03/04: AIRAVATA-3033 delete dir API
Date Wed, 22 May 2019 23:17:10 GMT
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 <machristie@apache.org>
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 = {


Mime
View raw message