Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Coscine Python SDK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
community features
Coscine Python SDK
Commits
6a85dd84
Commit
6a85dd84
authored
3 years ago
by
Romin
Browse files
Options
Downloads
Patches
Plain Diff
Fixed directory and subdirectory interaction in S3 resources
parent
f5118adb
No related branches found
No related tags found
No related merge requests found
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/coscine/object.py
+39
-11
39 additions, 11 deletions
src/coscine/object.py
src/coscine/resource.py
+11
-4
11 additions, 4 deletions
src/coscine/resource.py
src/coscine/version.py
+1
-1
1 addition, 1 deletion
src/coscine/version.py
with
51 additions
and
16 deletions
src/coscine/object.py
+
39
−
11
View file @
6a85dd84
...
...
@@ -16,7 +16,7 @@
###############################################################################
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
,
Callable
from
typing
import
TYPE_CHECKING
,
Callable
,
List
,
Type
if
TYPE_CHECKING
:
from
.client
import
Client
from
.resource
import
Resource
...
...
@@ -41,6 +41,8 @@ class Object:
name
:
str
size
:
int
type
:
str
path
:
str
is_folder
:
bool
CHUNK_SIZE
:
int
=
4096
...
...
@@ -64,6 +66,8 @@ class Object:
self
.
name
=
data
[
"
Name
"
]
self
.
size
=
data
[
"
Size
"
]
self
.
type
=
data
[
"
Kind
"
]
self
.
path
=
data
[
"
Path
"
]
self
.
is_folder
=
data
[
"
IsFolder
"
]
###############################################################################
...
...
@@ -89,8 +93,9 @@ class Object:
If no metadata has been set for the file-like object.
"""
uri
=
self
.
client
.
uri
(
"
Tree
"
,
"
Tree
"
,
self
.
resource
.
id
,
self
.
name
)
data
=
self
.
client
.
get
(
uri
).
json
()
uri
=
self
.
client
.
uri
(
"
Tree
"
,
"
Tree
"
,
self
.
resource
.
id
)
args
=
{
"
path
"
:
self
.
path
}
data
=
self
.
client
.
get
(
uri
,
params
=
args
).
json
()
metadata
=
data
[
"
data
"
][
"
metadataStorage
"
]
if
not
metadata
:
return
None
...
...
@@ -115,8 +120,9 @@ class Object:
A raw byte-array containing the Coscine file-object
'
s data.
"""
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
,
self
.
name
)
return
self
.
client
.
get
(
uri
).
content
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
)
args
=
{
"
path
"
:
self
.
path
}
return
self
.
client
.
get
(
uri
,
params
=
args
).
content
###############################################################################
...
...
@@ -132,8 +138,9 @@ class Object:
A callback function to be called during downloading chunks.
"""
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
,
self
.
name
)
response
=
self
.
client
.
get
(
uri
,
stream
=
True
)
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
)
args
=
{
"
path
"
:
self
.
path
}
response
=
self
.
client
.
get
(
uri
,
params
=
args
,
stream
=
True
)
path
=
os
.
path
.
join
(
path
,
self
.
name
)
fd
=
open
(
path
,
"
wb
"
)
bar
=
ProgressBar
(
self
.
client
,
self
.
size
,
self
.
name
,
"
DOWN
"
,
callback
)
...
...
@@ -149,8 +156,9 @@ class Object:
Deletes the file-like object on the Coscine server.
"""
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
,
self
.
name
)
self
.
client
.
delete
(
uri
)
uri
=
self
.
client
.
uri
(
"
Blob
"
,
"
Blob
"
,
self
.
resource
.
id
)
args
=
{
"
path
"
:
self
.
path
}
self
.
client
.
delete
(
uri
,
params
=
args
)
###############################################################################
...
...
@@ -174,8 +182,9 @@ class Object:
elif
type
(
metadata
)
is
not
dict
:
raise
TypeError
(
"
Expected MetadataForm or dict.
"
)
uri
=
self
.
client
.
uri
(
"
Tree
"
,
"
Tree
"
,
self
.
resource
.
id
,
self
.
name
)
self
.
client
.
put
(
uri
,
data
=
metadata
)
uri
=
self
.
client
.
uri
(
"
Tree
"
,
"
Tree
"
,
self
.
resource
.
id
)
args
=
{
"
path
"
:
self
.
path
}
self
.
client
.
put
(
uri
,
params
=
args
,
data
=
metadata
)
###############################################################################
...
...
@@ -188,4 +197,23 @@ class Object:
form
.
parse
(
self
.
metadata
())
return
form
###############################################################################
def
objects
(
self
,
**
kwargs
)
->
List
[
Object
]:
if
self
.
is_folder
:
return
self
.
resource
.
objects
(
path
=
self
.
path
,
**
kwargs
)
else
:
raise
TypeError
(
"
object is not a directory!
"
)
###############################################################################
def
object
(
self
,
displayName
:
str
=
None
,
**
kwargs
)
->
Object
:
if
self
.
is_folder
:
if
displayName
.
endswith
(
"
/
"
):
# expect directory
displayName
=
self
.
name
+
"
/
"
+
displayName
return
self
.
resource
.
object
(
displayName
=
displayName
,
path
=
self
.
path
,
**
kwargs
)
else
:
raise
TypeError
(
"
object is not a directory!
"
)
###############################################################################
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/coscine/resource.py
+
11
−
4
View file @
6a85dd84
...
...
@@ -225,7 +225,7 @@ class Resource:
###############################################################################
def
objects
(
self
,
**
kwargs
)
->
List
[
Object
]:
def
objects
(
self
,
path
:
str
=
None
,
**
kwargs
)
->
List
[
Object
]:
"""
Returns a list of Objects stored within the resource
...
...
@@ -242,7 +242,11 @@ class Resource:
objects
=
[]
uri
=
self
.
client
.
uri
(
"
Tree
"
,
"
Tree
"
,
self
.
id
)
data
=
self
.
client
.
get
(
uri
).
json
()
if
path
:
args
=
{
"
path
"
:
path
}
else
:
args
=
None
data
=
self
.
client
.
get
(
uri
,
params
=
args
).
json
()
fileStorage
=
data
[
"
data
"
][
"
fileStorage
"
]
metadataStorage
=
data
[
"
data
"
][
"
metadataStorage
"
]
for
data
in
fileStorage
:
...
...
@@ -255,7 +259,8 @@ class Resource:
###############################################################################
def
object
(
self
,
displayName
:
str
=
None
,
**
kwargs
)
->
Object
:
def
object
(
self
,
displayName
:
str
=
None
,
path
:
str
=
None
,
**
kwargs
)
\
->
Object
:
"""
Returns an Object stored within the resource
...
...
@@ -273,11 +278,13 @@ class Resource:
"""
if
displayName
:
if
displayName
.
endswith
(
"
/
"
):
displayName
=
displayName
[:
-
1
]
kwargs
[
"
Name
"
]
=
displayName
elif
not
kwargs
:
raise
ParameterError
(
""
)
objects
=
self
.
objects
(
**
kwargs
)
objects
=
self
.
objects
(
path
=
path
,
**
kwargs
)
if
len
(
objects
)
==
1
:
return
objects
[
0
]
elif
len
(
objects
)
==
0
:
...
...
This diff is collapsed.
Click to expand it.
src/coscine/version.py
+
1
−
1
View file @
6a85dd84
...
...
@@ -16,4 +16,4 @@
###############################################################################
# Do not set version to 1.0.0 before Coscine end of pilot phase
__version__
=
"
0.5.2
"
\ No newline at end of file
__version__
=
"
0.5.3
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment