Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
ec55ff35
Commit
ec55ff35
authored
9 years ago
by
Gunnar Schaefer
Committed by
Nathaniel Kofalt
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
implement zip member delivery
parent
513435ac
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.py
+0
-1
0 additions, 1 deletion
api.py
containers.py
+30
-30
30 additions, 30 deletions
containers.py
util.py
+0
-6
0 additions, 6 deletions
util.py
with
30 additions
and
37 deletions
api.py
+
0
−
1
View file @
ec55ff35
...
...
@@ -80,7 +80,6 @@ routes = [
webapp2
.
Route
(
r
'
/<:[0-9a-f]{24}>
'
,
acquisitions
.
Acquisition
,
name
=
'
acquisition
'
),
webapp2
.
Route
(
r
'
/<:[0-9a-f]{24}>/file
'
,
acquisitions
.
Acquisition
,
handler_method
=
'
file
'
,
methods
=
[
'
POST
'
]),
webapp2
.
Route
(
r
'
/<:[0-9a-f]{24}>/file/<:[^/]+>
'
,
acquisitions
.
Acquisition
,
handler_method
=
'
file
'
),
webapp2
.
Route
(
r
'
/<:[0-9a-f]{24}>/tile
'
,
acquisitions
.
Acquisition
,
handler_method
=
'
get_tile
'
,
methods
=
[
'
GET
'
]),
]),
webapp2
.
Route
(
r
'
/api/jobs
'
,
jobs
.
Jobs
),
webapp2_extras
.
routes
.
PathPrefixRoute
(
r
'
/api/jobs
'
,
[
...
...
This diff is collapsed.
Click to expand it.
containers.py
+
30
−
30
View file @
ec55ff35
...
...
@@ -8,6 +8,7 @@ import cgi
import
bson
import
json
import
shutil
import
zipfile
import
datetime
import
jsonschema
...
...
@@ -247,13 +248,36 @@ class Container(base.RequestHandler):
ticket
=
util
.
download_ticket
(
self
.
request
.
client_addr
,
'
file
'
,
_id
,
filename
,
fileinfo
[
'
filesize
'
])
return
{
'
ticket
'
:
self
.
app
.
db
.
downloads
.
insert
(
ticket
)}
else
:
# authenticated or ticketed (unauthenticated) download
self
.
response
.
app_iter
=
open
(
filepath
,
'
rb
'
)
self
.
response
.
headers
[
'
Content-Length
'
]
=
str
(
fileinfo
[
'
filesize
'
])
# must be set after setting app_iter
if
self
.
request
.
GET
.
get
(
'
view
'
,
''
).
lower
()
in
(
'
1
'
,
'
true
'
):
self
.
response
.
headers
[
'
Content-Type
'
]
=
str
(
fileinfo
.
get
(
'
mimetype
'
,
'
application/octet-stream
'
))
zip_member
=
self
.
request
.
GET
.
get
(
'
member
'
)
if
self
.
request
.
GET
.
get
(
'
info
'
,
''
).
lower
()
in
(
'
1
'
,
'
true
'
):
try
:
with
zipfile
.
ZipFile
(
filepath
)
as
zf
:
return
[(
zi
.
filename
,
zi
.
file_size
,
util
.
format_timestamp
(
datetime
.
datetime
(
*
zi
.
date_time
))[
0
])
for
zi
in
zf
.
infolist
()]
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
elif
self
.
request
.
GET
.
get
(
'
comment
'
,
''
).
lower
()
in
(
'
1
'
,
'
true
'
):
try
:
with
zipfile
.
ZipFile
(
filepath
)
as
zf
:
self
.
response
.
write
(
zf
.
comment
)
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
elif
zip_member
:
try
:
with
zipfile
.
ZipFile
(
filepath
)
as
zf
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
util
.
guess_mimetype
(
zip_member
)
self
.
response
.
write
(
zf
.
open
(
zip_member
).
read
())
except
zipfile
.
BadZipfile
:
self
.
abort
(
400
,
'
not a zip file
'
)
except
KeyError
:
self
.
abort
(
400
,
'
zip file contains no such member
'
)
else
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
application/octet-stream
'
self
.
response
.
headers
[
'
Content-Disposition
'
]
=
'
attachment; filename=
"'
+
filename
+
'"'
self
.
response
.
app_iter
=
open
(
filepath
,
'
rb
'
)
self
.
response
.
headers
[
'
Content-Length
'
]
=
str
(
fileinfo
[
'
filesize
'
])
# must be set after setting app_iter
if
self
.
request
.
GET
.
get
(
'
view
'
,
''
).
lower
()
in
(
'
1
'
,
'
true
'
):
self
.
response
.
headers
[
'
Content-Type
'
]
=
str
(
fileinfo
.
get
(
'
mimetype
'
,
'
application/octet-stream
'
))
else
:
self
.
response
.
headers
[
'
Content-Type
'
]
=
'
application/octet-stream
'
self
.
response
.
headers
[
'
Content-Disposition
'
]
=
'
attachment; filename=
"'
+
filename
+
'"'
def
_delete_file
(
self
,
_id
,
container
,
filename
):
"""
Delete one file.
"""
...
...
@@ -355,27 +379,3 @@ class Container(base.RequestHandler):
self
.
abort
(
202
,
'
identical file exists
'
)
elif
success
==
False
:
self
.
abort
(
409
,
'
file exists; use force to overwrite
'
)
def
get_tile
(
self
,
cid
):
"""
fetch info about a tiled tiff, or retrieve a specific tile.
"""
_id
=
bson
.
ObjectId
(
cid
)
container
,
_
=
self
.
_get
(
_id
,
'
ro
'
)
# need at least read access to view tiles
montage_info
=
None
for
f
in
container
.
get
(
'
files
'
):
if
f
[
'
filetype
'
]
==
'
montage
'
:
montage_info
=
f
break
if
not
montage_info
:
self
.
abort
(
404
,
'
montage zip not found
'
)
fn
=
montage_info
[
'
filename
'
]
fp
=
os
.
path
.
join
(
self
.
app
.
config
[
'
data_path
'
],
cid
[
-
3
:],
cid
,
fn
)
z
=
self
.
request
.
GET
.
get
(
'
z
'
)
x
=
self
.
request
.
GET
.
get
(
'
x
'
)
y
=
self
.
request
.
GET
.
get
(
'
y
'
)
if
not
(
z
and
x
and
y
):
return
util
.
get_info
(
fp
)
else
:
self
.
response
.
content_type
=
'
image/jpeg
'
tile
=
util
.
get_tile
(
fp
,
int
(
z
),
int
(
x
),
int
(
y
))
if
tile
:
self
.
response
.
write
(
tile
)
This diff is collapsed.
Click to expand it.
util.py
+
0
−
6
View file @
ec55ff35
...
...
@@ -4,9 +4,7 @@ import logging
log
=
logging
.
getLogger
(
'
scitran.api
'
)
import
os
import
bson
import
copy
import
json
import
pytz
import
uuid
import
shutil
...
...
@@ -19,7 +17,6 @@ import dateutil.parser
import
tempdir
as
tempfile
import
scitran.data
import
scitran.data.medimg.montage
MIMETYPES
=
[
(
'
.bvec
'
,
'
text
'
,
'
bvec
'
),
...
...
@@ -31,9 +28,6 @@ MIMETYPES = [
for
mt
in
MIMETYPES
:
mimetypes
.
types_map
.
update
({
mt
[
0
]:
mt
[
1
]
+
'
/
'
+
mt
[
2
]})
get_info
=
scitran
.
data
.
medimg
.
montage
.
get_info
get_tile
=
scitran
.
data
.
medimg
.
montage
.
get_tile
valid_timezones
=
pytz
.
all_timezones
PROJECTION_FIELDS
=
[
'
group
'
,
'
timestamp
'
,
'
permissions
'
,
'
public
'
]
...
...
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