Showing
9 changed files
with
180 additions
and
55 deletions
dcloud/calculator.java
0 → 100644
| 1 | +import java.util.Scanner; | ||
| 2 | + | ||
| 3 | +class calculator{ | ||
| 4 | + public static void main(String[] args) { | ||
| 5 | + | ||
| 6 | + Scanner scn = new Scanner(System.in); | ||
| 7 | + | ||
| 8 | + System.out.print("Input first args: "); | ||
| 9 | + | ||
| 10 | + float num1 = scn.nextFloat(); | ||
| 11 | + | ||
| 12 | + System.out.print("Input second args: "); | ||
| 13 | + float num2 = scn.nextFloat(); | ||
| 14 | + | ||
| 15 | + System.out.print("Input Operator(+,-,/,*): "); | ||
| 16 | + | ||
| 17 | + String oper = scn.next(); | ||
| 18 | + | ||
| 19 | + float result = 0.0f; | ||
| 20 | + | ||
| 21 | + switch (oper) { | ||
| 22 | + case "+": | ||
| 23 | + result = num1 + num2; | ||
| 24 | + break; | ||
| 25 | + | ||
| 26 | + case "-": | ||
| 27 | + result = num1 - num2; | ||
| 28 | + break; | ||
| 29 | + | ||
| 30 | + case "/": | ||
| 31 | + result = num1 / num2; | ||
| 32 | + break; | ||
| 33 | + | ||
| 34 | + case "*": | ||
| 35 | + result = num1 * num2; | ||
| 36 | + break; | ||
| 37 | + | ||
| 38 | + default: | ||
| 39 | + break; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + System.out.println("Result is " + result); | ||
| 43 | + scn.close(); | ||
| 44 | + } | ||
| 45 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -4,10 +4,6 @@ from dcloud import aws_conf | ... | @@ -4,10 +4,6 @@ from dcloud import aws_conf |
| 4 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | 4 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
| 5 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 5 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 6 | 6 | ||
| 7 | - | ||
| 8 | -# Quick-start development settings - unsuitable for production | ||
| 9 | -# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ | ||
| 10 | - | ||
| 11 | # SECURITY WARNING: keep the secret key used in production secret! | 7 | # SECURITY WARNING: keep the secret key used in production secret! |
| 12 | SECRET_KEY = '534f6m=i@*)=q3kuwlge1m3c+@^cabr3ttcx*omv^+dorydjfr' | 8 | SECRET_KEY = '534f6m=i@*)=q3kuwlge1m3c+@^cabr3ttcx*omv^+dorydjfr' |
| 13 | 9 | ||
| ... | @@ -16,9 +12,7 @@ DEBUG = True | ... | @@ -16,9 +12,7 @@ DEBUG = True |
| 16 | 12 | ||
| 17 | ALLOWED_HOSTS = [] | 13 | ALLOWED_HOSTS = [] |
| 18 | 14 | ||
| 19 | - | ||
| 20 | # Application definition | 15 | # Application definition |
| 21 | - | ||
| 22 | INSTALLED_APPS = [ | 16 | INSTALLED_APPS = [ |
| 23 | 'django.contrib.admin', | 17 | 'django.contrib.admin', |
| 24 | 'django.contrib.auth', | 18 | 'django.contrib.auth', |
| ... | @@ -112,6 +106,8 @@ USE_TZ = True | ... | @@ -112,6 +106,8 @@ USE_TZ = True |
| 112 | 106 | ||
| 113 | STATIC_URL = '/static/' | 107 | STATIC_URL = '/static/' |
| 114 | 108 | ||
| 109 | +MEDIA_URL = '/media/' | ||
| 110 | +MEDIA_ROOT = os.path.join(BASE_DIR, "media") | ||
| 115 | 111 | ||
| 116 | # Login redirect | 112 | # Login redirect |
| 117 | 113 | ... | ... |
dcloud/media/calculator.java
0 → 100644
| 1 | +import java.util.Scanner; | ||
| 2 | + | ||
| 3 | +class calculator{ | ||
| 4 | + public static void main(String[] args) { | ||
| 5 | + | ||
| 6 | + Scanner scn = new Scanner(System.in); | ||
| 7 | + | ||
| 8 | + System.out.print("Input first args: "); | ||
| 9 | + | ||
| 10 | + float num1 = scn.nextFloat(); | ||
| 11 | + | ||
| 12 | + System.out.print("Input second args: "); | ||
| 13 | + float num2 = scn.nextFloat(); | ||
| 14 | + | ||
| 15 | + System.out.print("Input Operator(+,-,/,*): "); | ||
| 16 | + | ||
| 17 | + String oper = scn.next(); | ||
| 18 | + | ||
| 19 | + float result = 0.0f; | ||
| 20 | + | ||
| 21 | + switch (oper) { | ||
| 22 | + case "+": | ||
| 23 | + result = num1 + num2; | ||
| 24 | + break; | ||
| 25 | + | ||
| 26 | + case "-": | ||
| 27 | + result = num1 - num2; | ||
| 28 | + break; | ||
| 29 | + | ||
| 30 | + case "/": | ||
| 31 | + result = num1 / num2; | ||
| 32 | + break; | ||
| 33 | + | ||
| 34 | + case "*": | ||
| 35 | + result = num1 * num2; | ||
| 36 | + break; | ||
| 37 | + | ||
| 38 | + default: | ||
| 39 | + break; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + System.out.println("Result is " + result); | ||
| 43 | + scn.close(); | ||
| 44 | + } | ||
| 45 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -2,12 +2,13 @@ from django.db import models | ... | @@ -2,12 +2,13 @@ from django.db import models |
| 2 | 2 | ||
| 3 | # Create your models here. | 3 | # Create your models here. |
| 4 | class File(models.Model): | 4 | class File(models.Model): |
| 5 | + file = models.FileField(blank=False, null=False) | ||
| 6 | + # title = models.CharField(max_length=100) | ||
| 5 | created = models.DateTimeField(auto_now_add=True) | 7 | created = models.DateTimeField(auto_now_add=True) |
| 6 | - modified = models.DateTimeField(auto_now=True) | 8 | + |
| 7 | - title = models.CharField(max_length=100) | 9 | + # modified = models.DateTimeField(auto_now=True) |
| 8 | # file_name = models.CharField(max_length=100, primary_key=True) | 10 | # file_name = models.CharField(max_length=100, primary_key=True) |
| 9 | - | 11 | + # object_key = models.CharField(max_length=1025) |
| 10 | - object_key = models.CharField(max_length=1025) | ||
| 11 | # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE) | 12 | # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE) |
| 12 | 13 | ||
| 13 | class Meta: | 14 | class Meta: | ... | ... |
| ... | @@ -27,5 +27,24 @@ def list_path(bucket, user, path): | ... | @@ -27,5 +27,24 @@ def list_path(bucket, user, path): |
| 27 | 27 | ||
| 28 | return {'files':files} | 28 | return {'files':files} |
| 29 | 29 | ||
| 30 | +def upload_file(bucket, user, local_path, key): | ||
| 31 | + return S3.upload_file(local_path, bucket, user+"/"+key) | ||
| 32 | + | ||
| 33 | +def download_file(bucket, user, local_path, key): | ||
| 34 | + return S3.download_file(bucket, user+"/"+key, local_path) | ||
| 35 | + | ||
| 30 | def delete_path(bucket, user, path): | 36 | def delete_path(bucket, user, path): |
| 31 | - return S3.delete_object(Bucket=bucket, Key='{}/{}'.format(user, path)) | 37 | + return S3.delete_object(Bucket=bucket, Key=user+"/"+path) |
| 38 | + | ||
| 39 | +def make_directory(bucket, user, path): | ||
| 40 | + return S3.put_object(Bucket=BUCKET, Key=user+"/"+path) | ||
| 41 | + | ||
| 42 | +# | ||
| 43 | +def move_file(bucket, user, old_path, new_path): | ||
| 44 | + S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path) | ||
| 45 | + S3.delete_object(Bucket=bucket, Key=user+"/"+old_path) | ||
| 46 | + return | ||
| 47 | + | ||
| 48 | +def copy_file(bucket, user, old_path, new_path): | ||
| 49 | + S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path) | ||
| 50 | + return | ... | ... |
| ... | @@ -3,11 +3,12 @@ from django.shortcuts import redirect | ... | @@ -3,11 +3,12 @@ from django.shortcuts import redirect |
| 3 | from rest_framework.urlpatterns import format_suffix_patterns | 3 | from rest_framework.urlpatterns import format_suffix_patterns |
| 4 | from restful import views | 4 | from restful import views |
| 5 | 5 | ||
| 6 | -urlpatterns = [ | 6 | +file_regex = '[\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]' |
| 7 | - url(r'^list/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'), | ||
| 8 | - # url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()), | ||
| 9 | 7 | ||
| 10 | - url(r'^file/(?P<path>([a-zA-z0-9가-힣._-]*/*)*)$', views.FileDetail.as_view(), name='file-detail') | 8 | +urlpatterns = [ |
| 9 | + url(r'^list/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.FileList.as_view(), name='file-list'), | ||
| 10 | + url(r'^file/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.FileDetail.as_view(), name='file-detail'), | ||
| 11 | + url(r'^file-mod/(?P<old_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)&(?P<new_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]]*/*)*)$', views.FileCopyMove.as_view(), name='file-copy-move') | ||
| 11 | ] | 12 | ] |
| 12 | 13 | ||
| 13 | urlpatterns = format_suffix_patterns(urlpatterns) | 14 | urlpatterns = format_suffix_patterns(urlpatterns) |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -13,44 +13,74 @@ class FileList(APIView): | ... | @@ -13,44 +13,74 @@ class FileList(APIView): |
| 13 | List all file, or create a new snippet. | 13 | List all file, or create a new snippet. |
| 14 | """ | 14 | """ |
| 15 | 15 | ||
| 16 | + """ | ||
| 17 | + list files or view detail | ||
| 18 | + """ | ||
| 16 | def get(self, request, path="/", format=None): | 19 | def get(self, request, path="/", format=None): |
| 17 | - data = s3_interface.list_path(s3_interface.BUCKET, 'test1', path) | 20 | + user = request.user |
| 21 | + data = s3_interface.list_path(s3_interface.BUCKET, user.username, path) | ||
| 18 | return Response(data) | 22 | return Response(data) |
| 19 | 23 | ||
| 20 | - | 24 | + """ |
| 25 | + upload file | ||
| 26 | + """ | ||
| 21 | def post(self, request, path="/", format=None): | 27 | def post(self, request, path="/", format=None): |
| 22 | - # TODO file upload | 28 | + # file upload |
| 23 | - return Response({}) | 29 | + # upload to server |
| 24 | - | 30 | + file_serializer = FileSerializer(data=request.data) |
| 31 | + if file_serializer.is_valid(): | ||
| 32 | + file_serializer.save() | ||
| 33 | + # upload to s3 | ||
| 34 | + file_path = '.' + file_serializer.data.get('file') | ||
| 35 | + user = request.user | ||
| 36 | + data = s3_interface.upload_file(s3_interface.BUCKET, user.username, file_path, path+file_path.split('/')[-1]) | ||
| 37 | + # TODO upload check | ||
| 38 | + # TODO remove local file | ||
| 39 | + return Response(file_serializer.data, status=status.HTTP_201_CREATED) | ||
| 40 | + else: | ||
| 41 | + return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
| 42 | + return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
| 43 | + | ||
| 44 | + """ | ||
| 45 | + make directory | ||
| 46 | + """ | ||
| 47 | + def put(self, request, path="/", format=None): | ||
| 48 | + user = request.user | ||
| 49 | + data = s3_interface.make_directory(s3_interface.BUCKET, user.username, path) | ||
| 50 | + return Response(data, status=status.HTTP_201_CREATED) | ||
| 25 | 51 | ||
| 26 | class FileDetail(APIView): | 52 | class FileDetail(APIView): |
| 27 | """ | 53 | """ |
| 28 | - Retrieve, update or delete a file instance. | 54 | + Download or delete a file instance. |
| 29 | """ | 55 | """ |
| 30 | - # def get_object(self, pk): | ||
| 31 | - # try: | ||
| 32 | - # return File.objects.get(pk=pk) | ||
| 33 | - # except File.DoesNotExist: | ||
| 34 | - # raise Http404 | ||
| 35 | 56 | ||
| 36 | def get(self, request, path="/", format=None): | 57 | def get(self, request, path="/", format=None): |
| 37 | - # file = self.get_object(pk) | 58 | + # download file from s3 |
| 38 | - # serializer = FileSerializer(file) | 59 | + file = 'media/'+path.split('/')[-1] |
| 39 | - # return Response(serializer.data, status=status.HTTP_200_OK) | 60 | + user = request.user |
| 40 | - # TODO | 61 | + s3_interface.download_file(s3_interface.BUCKET, user.username, file, path) |
| 41 | - return | 62 | + # TODO error |
| 42 | - | 63 | + return Response({'file': file}) |
| 43 | - def put(self, request, path="/", format=None): | ||
| 44 | - # file = self.get_object(pk) | ||
| 45 | - # serializer = FileSerializer(file, data=request.data) | ||
| 46 | - # if serializer.is_valid(): | ||
| 47 | - # serializer.save() | ||
| 48 | - # return Response(serializer.data, status=status.HTTP_204_NO_CONTENT) | ||
| 49 | - # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
| 50 | - # TODO | ||
| 51 | - return | ||
| 52 | 64 | ||
| 53 | def delete(self, request, path="/", format=None): | 65 | def delete(self, request, path="/", format=None): |
| 54 | - result = s3_interface.delete_path(s3_interface.BUCKET, 'test1', path) | 66 | + user = request.user |
| 67 | + result = s3_interface.delete_path(s3_interface.BUCKET, user.username, path) | ||
| 55 | return Response(result) | 68 | return Response(result) |
| 56 | 69 | ||
| 70 | +class FileCopyMove(APIView): | ||
| 71 | + """ | ||
| 72 | + Download or delete a file instance. | ||
| 73 | + """ | ||
| 74 | + #TODO is folder move, copy well? | ||
| 75 | + # move | ||
| 76 | + def post(self, request, old_path, new_path, format=None): | ||
| 77 | + user = request.user | ||
| 78 | + if request.data.get('method') == 'mv': | ||
| 79 | + s3_interface.move_file(s3_interface.BUCKET, user.username, old_path, new_path) | ||
| 80 | + elif request.data.get('method') == 'cp': | ||
| 81 | + s3_interface.copy_file(s3_interface.BUCKET, user.username, old_path, new_path) | ||
| 82 | + else: | ||
| 83 | + return Response({'stats': 'bad_request'}, status=status.HTTP_400_BAD_REQUEST) | ||
| 84 | + return Response({'old_path': old_path, 'new_path': new_path}) | ||
| 85 | + | ||
| 86 | + | ... | ... |
-
Please register or login to post a comment