[ARVADOS] created: 143bbe8d10d826b05357a531de6aa2a14f4cffb9

git at public.curoverse.com git at public.curoverse.com
Fri Aug 29 15:27:49 EDT 2014


        at  143bbe8d10d826b05357a531de6aa2a14f4cffb9 (commit)


commit 143bbe8d10d826b05357a531de6aa2a14f4cffb9
Author: Tim Pierce <twp at curoverse.com>
Date:   Fri Aug 29 13:46:39 2014 -0400

    3699: add arv-copy
    
    * arvados.config.load(config_file) reads config_file for Arvados
      configuration settings.  It returns a hash with the Arvados config
      vars and values.
    
    * arv-copy can authenticate to multiple Arvados instances.

diff --git a/sdk/cli/bin/arv-copy b/sdk/cli/bin/arv-copy
new file mode 100755
index 0000000..b076782
--- /dev/null
+++ b/sdk/cli/bin/arv-copy
@@ -0,0 +1,64 @@
+#! /usr/bin/env python
+
+import argparse
+import hashlib
+import os
+import re
+import string
+import sys
+import logging
+
+import arvados
+import arvados.config
+
+def main():
+    logger = logging.getLogger('arvados.arv-copy')
+
+    parser = argparse.ArgumentParser(
+        description='Copy a pipeline instance from one Arvados instance to another.')
+
+    parser.add_argument('--recursive', dest='recursive', action='store_true')
+    parser.add_argument('--no-recursive', dest='recursive', action='store_false')
+    parser.add_argument('pipeline_instance_uuid')
+    parser.add_argument('source_arvados')
+    parser.add_argument('destination_arvados')
+    parser.set_defaults(recursive=True)
+
+    args = parser.parse_args()
+
+    # Create API clients for the source and destination instances
+    src_arv = api_for_instance(args.source_arvados)
+    dst_arv = api_for_instance(args.destination_arvados)
+
+    # And now for the copying.
+
+    exit(0)
+
+# Creates an API client for the Arvados instance identified by
+# instance_name.  Looks in $HOME/.config/arvados/instance_name.conf
+# for credentials.
+#
+def api_for_instance(instance_name):
+    if '/' in instance_name:
+        abort('illegal instance name {}'.format(instance_name))
+    config_file = os.path.join(os.environ['HOME'], '.config', 'arvados', "{}.conf".format(instance_name))
+    cfg = arvados.config.load(config_file)
+
+    if 'ARVADOS_API_HOST' in cfg and 'ARVADOS_API_TOKEN' in cfg:
+        api_is_insecure = (
+            cfg.get('ARVADOS_API_HOST_INSECURE', '').lower() in set(
+                ['1', 't', 'true', 'y', 'yes']))
+        client = arvados.api('v1',
+                             host=cfg['ARVADOS_API_HOST'],
+                             token=cfg['ARVADOS_API_TOKEN'],
+                             insecure=api_is_insecure)
+    else:
+        abort('need ARVADOS_API_HOST and ARVADOS_API_TOKEN for {}'.format(instance_name))
+    return client
+
+def abort(msg, code=1):
+    print >>sys.stderr, "arv-copy:", msg
+    exit(code)
+
+if __name__ == '__main__':
+    main()
diff --git a/sdk/python/arvados/config.py b/sdk/python/arvados/config.py
index 2b8374a..211e6f5 100644
--- a/sdk/python/arvados/config.py
+++ b/sdk/python/arvados/config.py
@@ -14,17 +14,28 @@ EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
 def initialize(config_file=default_config_file):
     global _settings
     _settings = {}
-    if os.path.exists(config_file):
-        with open(config_file, "r") as f:
-            for config_line in f:
-                if re.match('^\s*#', config_line):
-                    continue
-                var, val = config_line.rstrip().split('=', 2)
-                _settings[var] = val
+
+    # load the specified config file if available
+    try:
+        _settings = load(config_file)
+    except IOError:
+        pass
+
+    # override any settings with environment vars
     for var in os.environ:
         if var.startswith('ARVADOS_'):
             _settings[var] = os.environ[var]
 
+def load(config_file):
+    cfg = {}
+    with open(config_file, "r") as f:
+        for config_line in f:
+            if re.match('^\s*#', config_line):
+                continue
+            var, val = config_line.rstrip().split('=', 2)
+            cfg[var] = val
+    return cfg
+
 def flag_is_true(key):
     return get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes'])
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list