Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyiricdata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bioinfo_iric
pyiricdata
Commits
0d59783b
Commit
0d59783b
authored
4 years ago
by
Albert Feghaly
Browse files
Options
Downloads
Patches
Plain Diff
Split download file content into get and download
parent
8049ef60
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Resolve "Allow to keep file content in memory"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyiricdata/Client.py
+25
-8
25 additions, 8 deletions
pyiricdata/Client.py
with
25 additions
and
8 deletions
pyiricdata/Client.py
+
25
−
8
View file @
0d59783b
...
...
@@ -8,10 +8,14 @@ import numpy as np
import
json
from
bs4
import
BeautifulSoup
import
sys
from
collections
import
namedtuple
from
.tools
import
is_json
IDF
=
namedtuple
(
'
IricDataFile
'
,
[
'
name
'
,
'
data
'
,
'
metadata
'
])
class
Client
:
"""
python client to IRICdata API
"""
def
__init__
(
self
,
username
,
password
=
None
,
url
=
'
https://thepond.bioinfo.iric.ca
'
):
...
...
@@ -199,22 +203,35 @@ class Client:
def
search_dataset_names
(
self
,
term
):
return
self
.
datasets
.
loc
[
self
.
datasets
.
dataset_name
.
str
.
contains
(
term
),:]
"""
Get file content according to file_id
"""
def
get_file
(
self
,
file_id
):
file_object
=
self
.
get_file_metadata
(
file_id
)
path
=
os
.
path
.
join
(
self
.
url
,
'
secure/datafiles/download
'
,
str
(
file_id
))
try
:
file_name
=
file_object
[
'
filename
'
]
file_content
=
self
.
session
.
get
(
path
,
allow_redirects
=
True
).
content
file_annotation
=
self
.
get_file_metadata
(
file_id
)
return
IDF
(
file_name
,
file_content
,
file_annotation
)
except
TypeError
:
return
IDF
(
None
,
None
,
None
)
"""
Download file according to file_id
"""
def
dwnl_file_content
(
self
,
file_id
,
folder_out
=
''
,
filename
=
''
):
folder_out
=
folder_out
if
folder_out
and
folder_out
[
0
]
==
'
/
'
else
os
.
path
.
join
(
os
.
getcwd
(),
folder_out
)
os
.
makedirs
(
folder_out
,
exist_ok
=
True
)
file_object
=
self
.
get_file_metadata
(
file_id
)
if
not
file_object
is
None
:
filename
=
file_object
[
'
filename
'
]
if
not
filename
else
filename
idf
=
self
.
get_file
(
file_id
)
if
idf
.
data
is
not
None
:
if
folder_out
and
folder_out
[
0
]
==
'
/
'
:
pass
else
:
folder_out
=
os
.
path
.
join
(
os
.
getcwd
(),
folder_out
)
os
.
makedirs
(
folder_out
,
exist_ok
=
True
)
filename
=
idf
.
name
if
not
filename
else
filename
out_file_path
=
os
.
path
.
join
(
folder_out
,
filename
)
path
=
os
.
path
.
join
(
self
.
url
,
'
secure/datafiles/download
'
,
str
(
file_id
))
r
=
self
.
session
.
get
(
path
,
allow_redirects
=
True
)
if
os
.
path
.
exists
(
out_file_path
):
sys
.
stderr
.
write
(
'
Warning: File already exists at location %s, skipping.
\n
'
%
out_file_path
)
else
:
with
open
(
out_file_path
,
'
wb
'
)
as
outfile
:
print
(
'
Downloading %s
'
%
out_file_path
)
outfile
.
write
(
r
.
content
)
outfile
.
write
(
idf
.
data
)
"""
Write file annotations json to disk
"""
def
dwnl_file_annotation
(
self
,
file_id
,
folder_out
=
''
,
filename
=
''
):
...
...
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