Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9a6c83ca
authored
Jan 30, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store: refactor commands to functions
parent
5cdd5412
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
19 deletions
+35
-19
miscellaneous/store-server/CloudStore.py
+35
-19
No files found.
miscellaneous/store-server/CloudStore.py
View file @
9a6c83ca
...
...
@@ -44,6 +44,8 @@ def neptun_GET(neptun):
statistics
=
getQuotaStatus
(
neptun
)
return
{
'Used'
:
statistics
[
0
],
'Soft'
:
statistics
[
1
],
'Hard'
:
statistics
[
2
]}
COMMANDS
=
{}
@route
(
'/<neptun>'
,
method
=
'POST'
)
def
neptun_POST
(
neptun
):
# Check if user avaiable (home folder ready)
...
...
@@ -51,16 +53,23 @@ def neptun_POST(neptun):
if
os
.
path
.
exists
(
home_path
)
!=
True
:
abort
(
401
,
'The requested user does not exist!'
)
else
:
# Parse post
# LISTING
if
request
.
json
[
'CMD'
]
==
'LIST'
:
try
:
return
COMMANDS
[
request
.
json
[
'CMD'
]](
request
,
neptun
,
home_path
)
except
KeyError
:
abort
(
400
,
"Command not found!"
)
# LISTING
def
cmd_list
(
request
,
neptun
,
home_path
):
list_path
=
home_path
+
request
.
json
[
'PATH'
]
if
os
.
path
.
exists
(
list_path
)
!=
True
:
abort
(
404
,
"Path not found!"
)
else
:
return
list_directory
(
home_path
,
list_path
)
# DOWNLOAD LINK GENERATOR
elif
request
.
json
[
'CMD'
]
==
'DOWNLOAD'
:
COMMANDS
[
'LIST'
]
=
cmd_list
# DOWNLOAD LINK GENERATOR
def
cmd_download
(
request
,
neptun
,
home_path
):
dl_path
=
home_path
+
'/'
+
request
.
json
[
'PATH'
]
dl_path
=
os
.
path
.
realpath
(
dl_path
)
if
not
dl_path
.
startswith
(
home_path
):
...
...
@@ -83,8 +92,10 @@ def neptun_POST(neptun):
result
=
subprocess
.
call
([
'/usr/bin/zip'
,
'-rqDj'
,
temp_path
,
dl_path
],
stdout
=
fnull
,
stderr
=
fnull
)
os
.
symlink
(
temp_path
,
ROOT_WWW_FOLDER
+
'/'
+
dl_hash
)
return
json
.
dumps
({
'LINK'
:
SITE_URL
+
'/dl/'
+
dl_hash
})
# UPLOAD
elif
request
.
json
[
'CMD'
]
==
'UPLOAD'
:
COMMANDS
[
'DOWNLOAD'
]
=
cmd_download
# UPLOAD
def
cmd_upload
(
request
,
neptun
,
home_path
):
up_path
=
home_path
+
'/'
+
request
.
json
[
'PATH'
]
up_path
=
os
.
path
.
realpath
(
up_path
)
if
not
up_path
.
startswith
(
home_path
):
...
...
@@ -95,8 +106,10 @@ def neptun_POST(neptun):
return
json
.
dumps
({
'LINK'
:
SITE_URL
+
'/ul/'
+
up_hash
})
else
:
abort
(
400
,
'Upload directory not exists!'
)
# MOVE
elif
request
.
json
[
'CMD'
]
==
'MOVE'
:
COMMANDS
[
'UPLOAD'
]
=
cmd_upload
# MOVE
def
cmd_move
(
request
,
neptun
,
home_path
):
src_path
=
home_path
+
'/'
+
request
.
json
[
'SOURCE'
]
dst_path
=
home_path
+
'/'
+
request
.
json
[
'DESTINATION'
]
src_path
=
os
.
path
.
realpath
(
src_path
)
...
...
@@ -111,8 +124,10 @@ def neptun_POST(neptun):
else
:
# TODO
abort
(
400
,
"Can not move the file."
)
# RENAME
elif
request
.
json
[
'CMD'
]
==
'RENAME'
:
COMMANDS
[
'MOVE'
]
=
cmd_move
# RENAME
def
cmd_rename
(
request
,
neptun
,
home_path
):
src_path
=
home_path
+
'/'
+
request
.
json
[
'PATH'
]
src_path
=
os
.
path
.
realpath
(
src_path
)
if
not
src_path
.
startswith
(
home_path
):
...
...
@@ -122,9 +137,10 @@ def neptun_POST(neptun):
os
.
rename
(
src_path
,
dst_path
)
else
:
abort
(
404
,
"File or Folder not found!"
)
return
# NEW FOLDER
elif
request
.
json
[
'CMD'
]
==
'NEW_FOLDER'
:
COMMANDS
[
'RENAME'
]
=
cmd_rename
# NEW FOLDER
def
cmd_new_folder
(
request
,
neptun
,
home_path
):
dir_path
=
home_path
+
'/'
+
request
.
json
[
'PATH'
]
dir_path
=
os
.
path
.
realpath
(
dir_path
)
if
not
dir_path
.
startswith
(
home_path
):
...
...
@@ -133,9 +149,10 @@ def neptun_POST(neptun):
abort
(
400
,
"Directory already exist!"
)
else
:
os
.
mkdir
(
dir_path
,
0755
)
return
# REMOVE
elif
request
.
json
[
'CMD'
]
==
'REMOVE'
:
COMMANDS
[
'NEW_FOLDER'
]
=
cmd_new_folder
# REMOVE
def
cmd_remove
(
request
,
neptun
,
home_path
):
remove_path
=
home_path
+
'/'
+
request
.
json
[
'PATH'
]
remove_path
=
os
.
path
.
realpath
(
remove_path
)
if
not
remove_path
.
startswith
(
home_path
):
...
...
@@ -149,8 +166,7 @@ def neptun_POST(neptun):
else
:
os
.
remove
(
remove_path
)
return
else
:
abort
(
400
,
"Command not found!"
)
COMMANDS
[
'REMOVE'
]
=
cmd_remove
@route
(
'/set/<neptun>'
,
method
=
'POST'
)
def
set_keys
(
neptun
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment