[ARVADOS] created: 1a3ec903e591304b72bd0d394219729ac76bfed0
git at public.curoverse.com
git at public.curoverse.com
Mon Jun 16 15:18:11 EDT 2014
at 1a3ec903e591304b72bd0d394219729ac76bfed0 (commit)
commit 1a3ec903e591304b72bd0d394219729ac76bfed0
Author: radhika <radhika at curoverse.com>
Date: Mon Jun 16 15:17:20 2014 -0400
2896: add arv-ws cli tool to arv.
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index b485b7b..d4aef2c 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -68,6 +68,9 @@ when 'pipeline'
when 'tag'
ARGV.shift
exec `which arv-tag`.strip, *ARGV
+when 'ws'
+ ARGV.shift
+ exec `which arv-ws`.strip, *ARGV
end
ENV['ARVADOS_API_VERSION'] ||= 'v1'
diff --git a/sdk/cli/bin/arv-ws b/sdk/cli/bin/arv-ws
new file mode 120000
index 0000000..622916b
--- /dev/null
+++ b/sdk/cli/bin/arv-ws
@@ -0,0 +1 @@
+../../python/bin/arv-ws
\ No newline at end of file
diff --git a/sdk/python/arvados/events.py b/sdk/python/arvados/events.py
index e61b20c..3df934a 100644
--- a/sdk/python/arvados/events.py
+++ b/sdk/python/arvados/events.py
@@ -26,8 +26,18 @@ class EventClient(WebSocketClient):
def received_message(self, m):
self.on_event(json.loads(str(m)))
+ def close_connection(self):
+ try:
+ self.sock.shutdown(socket.SHUT_RDWR)
+ self.sock.close()
+ except:
+ pass
+
def subscribe(api, filters, on_event):
- url = "{}?api_token={}".format(api._rootDesc['websocketUrl'], config.get('ARVADOS_API_TOKEN'))
- ws = EventClient(url, filters, on_event)
- ws.connect()
- return ws
+ try:
+ url = "{}?api_token={}".format(api._rootDesc['websocketUrl'], config.get('ARVADOS_API_TOKEN'))
+ ws = EventClient(url, filters, on_event)
+ ws.connect()
+ return ws
+ except:
+ ws.close_connection()
diff --git a/sdk/python/bin/arv-ws b/sdk/python/bin/arv-ws
new file mode 100755
index 0000000..0721687
--- /dev/null
+++ b/sdk/python/bin/arv-ws
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+import argparse
+import sys
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-u', '--uuid', type=str, default="")
+args = parser.parse_args()
+
+def on_message(ev):
+ print "\n", ev
+
+filters = []
+if len(args.uuid)>0:
+ filter1 = []
+ filter1.append ('object_uuid')
+ filter1.append ('=')
+ filter1.append (args.uuid)
+ filters.append (filter1)
+
+import arvados
+from arvados.events import subscribe
+
+api = arvados.api('v1', cache=False)
+
+ws = None
+try:
+ ws = subscribe(api, filters, lambda ev: on_message(ev))
+ ws.run_forever()
+except:
+ if (ws):
+ ws.close_connection()
+ else:
+ sys.exc_info()
diff --git a/sdk/python/setup.py b/sdk/python/setup.py
index a209863..9f9c962 100644
--- a/sdk/python/setup.py
+++ b/sdk/python/setup.py
@@ -15,6 +15,7 @@ setup(name='arvados-python-client',
'bin/arv-ls',
'bin/arv-normalize',
'bin/arv-put',
+ 'bin/arv-ws',
],
install_requires=[
'python-gflags',
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list