Commit bf546e4a authored by Brian Moe's avatar Brian Moe
Browse files

Added download command

parent 251881d5
ligo-gracedb (1.2-1) unstable; urgency=low
* Added file download command.
-- Brian Moe <brian.moe@ligo.org> Mon, 11 Jun 2012 16:04:26 -0600
ligo-gracedb (1.1-1) unstable; urgency=low ligo-gracedb (1.1-1) unstable; urgency=low
* Bug Fix. * Bug Fix.
......
...@@ -22,10 +22,11 @@ __all__ = ["utils"] ...@@ -22,10 +22,11 @@ __all__ = ["utils"]
import httplib, mimetypes, urllib import httplib, mimetypes, urllib
import socket import socket
import os, sys, shutil import os, sys, shutil
import simplejson
DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/gracedb/cli" DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/gracedb/cli"
GIT_TAG = 'gracedb-1.1-1' GIT_TAG = 'gracedb-1.2-1'
#----------------------------------------------------------------- #-----------------------------------------------------------------
# Util routines # Util routines
...@@ -378,6 +379,10 @@ class Client: ...@@ -378,6 +379,10 @@ class Client:
files = [ ('upload', filename, filecontents) ] files = [ ('upload', filename, filecontents) ]
return self._upload('upload', fields, files, alert) return self._upload('upload', fields, files, alert)
def listfiles(self, graceid):
response = self.rest('/event/%s/files/' % graceid)
return response
def download(self, graceid, filename, destfile): def download(self, graceid, filename, destfile):
# Check that we *could* write the file before we # Check that we *could* write the file before we
# go to the trouble of getting it. Also, try not # go to the trouble of getting it. Also, try not
...@@ -514,9 +519,18 @@ Longer strings will be truncated.""" % { ...@@ -514,9 +519,18 @@ Longer strings will be truncated.""" % {
comment = " ".join(args[3:]) comment = " ".join(args[3:])
response = client.upload(graceid, filename, comment=comment, alert=options.alert) response = client.upload(graceid, filename, comment=comment, alert=options.alert)
elif args[0] == 'download': elif args[0] == 'download':
if len(args) not in [3,4]: if len(args) not in [2,3,4]:
op.error("not enough arguments for upload") op.error("not enough arguments for download")
graceid = args[1] graceid = args[1]
if len(args) == 2:
# get/print listing.
response = client.listfiles(graceid)
if response and response.status == 200:
for fname in simplejson.loads(response.read()):
print(fname)
exit(0)
print(response.reason)
exit(1)
filename = args[2] filename = args[2]
if len(args) == 4: if len(args) == 4:
outfile = args[3] outfile = args[3]
...@@ -524,6 +538,7 @@ Longer strings will be truncated.""" % { ...@@ -524,6 +538,7 @@ Longer strings will be truncated.""" % {
outfile = os.path.basename(filename) outfile = os.path.basename(filename)
response = client.download(graceid, filename, outfile) response = client.download(graceid, filename, outfile)
if response: if response:
# no response means file saved. any other response is an error message.
print response print response
exit(1) exit(1)
exit(0) exit(0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment