Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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 GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael William Coughlin
GraceDB Server
Commits
d7dc5464
Commit
d7dc5464
authored
12 years ago
by
Brian Moe
Browse files
Options
Downloads
Patches
Plain Diff
ReST-y file download. Some mods to easy ReST transition
parent
18976cac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gracedb/api.py
+29
-14
29 additions, 14 deletions
gracedb/api.py
gracedb/urls.py
+4
-0
4 additions, 0 deletions
gracedb/urls.py
gracedb/views.py
+33
-17
33 additions, 17 deletions
gracedb/views.py
with
66 additions
and
31 deletions
gracedb/api.py
+
29
−
14
View file @
d7dc5464
from
django.http
import
HttpResponse
,
HttpResponseNotFound
from
django.core.urlresolvers
import
reverse
import
simplejson
from
gracedb.models
import
Event
import
os
def
download
(
request
,
graceid
,
filename
=
None
):
#response = HttpResponse(buildVOEvent(event), content_type="application/xml")
if
not
filename
:
response
=
HttpResponseNotFound
(
"
Not Implemented.
"
)
response
.
status_code
=
404
def
download
(
request
,
graceid
,
filename
=
""
):
# Do not filename to be None. That messes up later os.path.join
filename
=
filename
or
""
try
:
event
=
Event
.
getByGraceid
(
graceid
)
filepath
=
os
.
path
.
join
(
event
.
datadir
(),
filename
)
if
not
os
.
path
.
exists
(
filepath
):
response
=
HttpResponseNotFound
(
"
File does not exist
"
)
elif
not
os
.
access
(
filepath
,
os
.
R_OK
):
response
=
HttpResponseNotFound
(
"
File not readable
"
)
else
:
response
=
HttpResponse
(
open
(
filepath
,
"
r
"
),
content_type
=
"
application/octet-stream
"
)
response
[
'
Content-Disposition
'
]
=
'
attachment; filename=%s
'
%
os
.
path
.
basename
(
filename
)
except
Event
.
DoesNotExist
:
response
=
HttpResponseNotFound
(
"
Event does not exist
"
)
return
HttpResponseNotFound
(
"
Event not found
"
)
filepath
=
os
.
path
.
join
(
event
.
datadir
(),
filename
)
if
not
os
.
path
.
exists
(
filepath
):
response
=
HttpResponseNotFound
(
"
File does not exist
"
)
elif
not
os
.
access
(
filepath
,
os
.
R_OK
):
response
=
HttpResponseNotFound
(
"
File not readable
"
)
elif
not
filename
:
# Get list of files w/urls.
rv
=
{}
for
dirname
,
dirnames
,
filenames
in
os
.
walk
(
filepath
):
dirname
=
dirname
[
len
(
filepath
):]
# cut off base event dir path
for
filename
in
filenames
:
# relative path from root of event data dir
filename
=
os
.
path
.
join
(
dirname
,
filename
)
rv
[
filename
]
=
reverse
(
download
,
args
=
[
graceid
,
filename
])
response
=
HttpResponse
(
simplejson
.
dumps
(
rv
),
content_type
=
"
application/json
"
)
else
:
# get an actual file.
response
=
HttpResponse
(
open
(
filepath
,
"
r
"
),
content_type
=
"
application/octet-stream
"
)
response
[
'
Content-Disposition
'
]
=
'
attachment; filename=%s
'
%
os
.
path
.
basename
(
filename
)
return
response
This diff is collapsed.
Click to expand it.
gracedb/urls.py
+
4
−
0
View file @
d7dc5464
...
...
@@ -3,6 +3,8 @@ from django.conf.urls.defaults import *
#import django.views.generic.list_detail
from
gracedb.api
import
download
urlpatterns
=
patterns
(
'
gracedb.views
'
,
url
(
r
'
^$
'
,
'
index
'
,
name
=
"
home
"
),
url
(
r
'
^create/$
'
,
'
create
'
,
name
=
"
create
"
),
...
...
@@ -10,6 +12,8 @@ urlpatterns = patterns('gracedb.views',
url
(
r
'
^view/(?P<graceid>[\w\d]+)
'
,
'
view
'
,
name
=
"
view
"
),
url
(
r
'
^voevent/(?P<graceid>[\w\d]+)
'
,
'
voevent
'
,
name
=
"
voevent
"
),
url
(
r
'
^skyalert/(?P<graceid>[\w\d]+)
'
,
'
skyalert
'
,
name
=
"
skyalert
"
),
url
(
r
'
^(?P<graceid>[\w\d]+)$
'
,
'
view
'
,
name
=
"
view2
"
),
url
(
r
'
^(?P<graceid>[\w\d]+)/files/(?P<filename>.+)$
'
,
download
,
name
=
"
file
"
),
# (r'^view/(?P<uid>[\w\d]+)', 'view'),
...
...
This diff is collapsed.
Click to expand it.
gracedb/views.py
+
33
−
17
View file @
d7dc5464
from
django.http
import
HttpResponse
from
django.http
import
HttpResponseRedirect
,
HttpResponseNotFound
,
Http404
from
django.http
import
HttpResponseRedirect
,
HttpResponseNotFound
,
HttpResponseBadRequest
,
Http404
from
django.template
import
RequestContext
from
django.core.urlresolvers
import
reverse
,
get_script_prefix
from
django.shortcuts
import
render_to_response
...
...
@@ -504,7 +504,17 @@ def cli_search(request):
if
form
.
is_valid
():
query
=
form
.
cleaned_data
[
'
query
'
]
objects
=
Event
.
objects
.
filter
(
query
).
distinct
()
# Assemble the output... should be able to choose format.
if
'
ligolw
'
in
request
.
POST
or
'
ligolw
'
in
request
.
GET
:
from
glue.ligolw
import
utils
if
objects
.
count
()
>
1000
:
return
HttpResponseBadRequest
(
"
Too many events.
"
)
xmldoc
=
assembleLigoLw
(
objects
)
response
=
HttpResponse
(
mimetype
=
'
application/xml
'
)
response
[
'
Content-Disposition
'
]
=
'
attachment; filename=gracedb-query.xml
'
utils
.
write_fileobj
(
xmldoc
,
response
)
return
response
accessFun
=
{
"
labels
"
:
lambda
e
:
\
"
,
"
.
join
([
labelling
.
label
.
name
for
labelling
in
e
.
labelling_set
.
all
()]),
...
...
@@ -539,6 +549,25 @@ def cli_search(request):
response
.
write
(
msg
)
return
response
def
assembleLigoLw
(
objects
):
from
glue.ligolw
import
ligolw
# lsctables MUST be loaded before utils.
from
glue.ligolw
import
lsctables
from
glue.ligolw
import
utils
from
glue.ligolw.utils
import
ligolw_add
xmldoc
=
ligolw
.
Document
()
for
obj
in
objects
:
fname
=
os
.
path
.
join
(
GRACEDB_DATA_DIR
,
obj
.
graceid
(),
"
private
"
,
"
coinc.xml
"
)
utils
.
load_filename
(
fname
,
xmldoc
=
xmldoc
)
ligolw_add
.
reassign_ids
(
xmldoc
)
ligolw_add
.
merge_ligolws
(
xmldoc
)
ligolw_add
.
merge_compatible_tables
(
xmldoc
)
return
xmldoc
def
search
(
request
,
format
=
""
):
assert
request
.
ligouser
# XXX DO NOT HARDCODE THIS
...
...
@@ -602,25 +631,12 @@ def search(request, format=""):
return
jqgridResponse
(
request
,
objects
)
elif
'
ligolw
'
in
request
.
POST
or
'
ligolw
'
in
request
.
GET
:
from
glue.ligolw
import
utils
if
objects
.
count
()
>
1000
:
# XXX Make this -- Better.
return
HttpResponse
(
"
Sorry -- no more than 1000 events currently allowed.
"
)
from
glue.ligolw
import
ligolw
# lsctables MUST be loaded before utils.
from
glue.ligolw
import
lsctables
from
glue.ligolw
import
utils
from
glue.ligolw.utils
import
ligolw_add
from
settings
import
GRACEDB_DATA_DIR
xmldoc
=
ligolw
.
Document
()
for
obj
in
objects
:
fname
=
os
.
path
.
join
(
GRACEDB_DATA_DIR
,
obj
.
graceid
(),
"
private
"
,
"
coinc.xml
"
)
utils
.
load_filename
(
fname
,
xmldoc
=
xmldoc
)
ligolw_add
.
reassign_ids
(
xmldoc
)
ligolw_add
.
merge_ligolws
(
xmldoc
)
ligolw_add
.
merge_compatible_tables
(
xmldoc
)
xmldoc
=
assembleLigoLw
(
objects
)
response
=
HttpResponse
(
mimetype
=
'
application/xml
'
)
response
[
'
Content-Disposition
'
]
=
'
attachment; filename=gracedb-query.xml
'
...
...
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