[ARVADOS] updated: d84737275793fcab0ac253c4abe734ad5e84ea12

git at public.curoverse.com git at public.curoverse.com
Tue Jan 21 17:14:55 EST 2014


Summary of changes:
 doc/gen_api_method_docs.py                         |   42 ++++++++++++++++----
 sdk/cli/bin/arv                                    |   14 ++++--
 sdk/perl/lib/Arvados.pm                            |   32 +++++++++++++-
 sdk/ruby/lib/arvados.rb                            |   40 ++++++++++++++++---
 .../controllers/arvados/v1/schema_controller.rb    |   35 +++++++++++------
 5 files changed, 129 insertions(+), 34 deletions(-)

       via  d84737275793fcab0ac253c4abe734ad5e84ea12 (commit)
       via  b84df42d2949d46fe62c8ab5302be439bea66663 (commit)
       via  f1eba78bed609adcbcfb0fbf370485e538791fde (commit)
      from  1e3aba5a02acd7670a4525ba9c0ce53b7e7e12de (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d84737275793fcab0ac253c4abe734ad5e84ea12
Merge: 1e3aba5 b84df42
Author: Tim Pierce <twp at curoverse.com>
Date:   Tue Jan 21 17:14:40 2014 -0500

    Merge branch '1943-client-sdk-config-files'
    
    Conflicts:
    	sdk/python/arvados/__init__.py


commit b84df42d2949d46fe62c8ab5302be439bea66663
Author: Tim Pierce <twp at curoverse.com>
Date:   Tue Jan 21 17:09:00 2014 -0500

    Clients use $HOME/.config/arvados/settings.conf for configuration. (fixes #1943)

diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index b133a77..3955c94 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -12,7 +12,7 @@ end
 
 # read authentication data from ~/.config/arvados if present
 lineno = 0
-config_file = File.expand_path('~/.config/arvados')
+config_file = File.expand_path('~/.config/arvados/settings.conf')
 if File.exist? config_file then
   File.open(config_file, 'r').each do |line|
     lineno = lineno + 1
diff --git a/sdk/perl/lib/Arvados.pm b/sdk/perl/lib/Arvados.pm
index 8a64378..31258f5 100644
--- a/sdk/perl/lib/Arvados.pm
+++ b/sdk/perl/lib/Arvados.pm
@@ -82,9 +82,18 @@ sub new
 sub build
 {
     my $self = shift;
-    $self->{'authToken'} ||= $ENV{'ARVADOS_API_TOKEN'};
-    $self->{'apiHost'} ||= $ENV{'ARVADOS_API_HOST'};
-    $self->{'apiProtocolScheme'} ||= $ENV{'ARVADOS_API_PROTOCOL_SCHEME'};
+
+    $config = load_config_file("$ENV{HOME}/.config/arvados/settings.conf");
+
+    $self->{'authToken'} ||= 
+	$ENV{ARVADOS_API_TOKEN} || $config->{ARVADOS_API_TOKEN};
+
+    $self->{'apiHost'} ||=
+	$ENV{ARVADOS_API_HOST} || $config->{ARVADOS_API_HOST};
+
+    $self->{'apiProtocolScheme'} ||=
+	$ENV{ARVADOS_API_PROTOCOL_SCHEME} ||
+	$config->{ARVADOS_API_PROTOCOL_SCHEME};
 
     $self->{'ua'} = new Arvados::Request;
 
@@ -124,4 +133,21 @@ sub new_request
     Arvados::Request->new();
 }
 
+sub load_config_file ($)
+{
+    my $config_file = shift;
+    my %config;
+
+    if (open (CONF, $config_file)) {
+	while (<CONF>) {
+	    next if /^\s*#/ || /^\s*$/;  # skip comments and blank lines
+	    chomp;
+	    my ($key, $val) = split /\s*=\s*/, $_, 2;
+	    $config{$key} = $val;
+	}
+    }
+    close CONF;
+    return \%config;
+}
+
 1;
diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index dacdba8..1adadd1 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -37,7 +37,7 @@ class ArvadosConfig(dict):
                 self[var] = os.environ[var]
 
 
-config = ArvadosConfig(os.environ['HOME'] + '/.config/arvados')
+config = ArvadosConfig(os.environ['HOME'] + '/.config/arvados/settings.conf')
 
 if 'ARVADOS_DEBUG' in config:
     logging.basicConfig(level=logging.DEBUG)
diff --git a/sdk/ruby/lib/arvados.rb b/sdk/ruby/lib/arvados.rb
index 0b00463..5be1fd9 100644
--- a/sdk/ruby/lib/arvados.rb
+++ b/sdk/ruby/lib/arvados.rb
@@ -32,18 +32,20 @@ class Arvados
     @application_version ||= 0.0
     @application_name ||= File.split($0).last
 
+    @config = self.load_config_file
+
     @arvados_api_version = opts[:api_version] ||
-      ENV['ARVADOS_API_VERSION'] ||
+      @config['ARVADOS_API_VERSION'] ||
       'v1'
     @arvados_api_host = opts[:api_host] ||
-      ENV['ARVADOS_API_HOST'] or
+      @config['ARVADOS_API_HOST'] or
       raise "#{$0}: no :api_host or ENV[ARVADOS_API_HOST] provided."
     @arvados_api_token = opts[:api_token] ||
-      ENV['ARVADOS_API_TOKEN'] or
+      @config['ARVADOS_API_TOKEN'] or
       raise "#{$0}: no :api_token or ENV[ARVADOS_API_TOKEN] provided."
 
-    if (opts[:api_host] ? opts[:suppress_ssl_warnings] :
-        ENV['ARVADOS_API_HOST_INSECURE'])
+    if (opts[:suppress_ssl_warnings] or
+        @config['ARVADOS_API_HOST_INSECURE'])
       suppress_warnings do
         OpenSSL::SSL.const_set 'VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE
       end
@@ -132,6 +134,32 @@ class Arvados
     $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if @@debuglevel >= verbosity
   end
 
+  def load_config_file(config_file_path="~/.config/arvados/settings.conf")
+    # Initialize config settings with environment variables.
+    config = {}
+    config['ARVADOS_API_HOST']          = ENV['ARVADOS_API_HOST']
+    config['ARVADOS_API_TOKEN']         = ENV['ARVADOS_API_TOKEN']
+    config['ARVADOS_API_HOST_INSECURE'] = ENV['ARVADOS_API_HOST_INSECURE']
+    config['ARVADOS_API_VERSION']       = ENV['ARVADOS_API_VERSION']
+
+    # Load settings from the config file.
+    lineno = 0
+    File.open(File.expand_path config_file_path).each do |line|
+      lineno = lineno + 1
+      # skip comments and blank lines
+      next if line.match('^\s*#') or not line.match('\S')
+      var, val = line.chomp.split('=', 2)
+      # allow environment settings to override config files.
+      if var and val
+        config[var] ||= val
+      else
+        warn "#{config_file}: #{lineno}: could not parse `#{line}'"
+      end
+    end
+
+    config
+  end
+
   class Model
     def self.arvados_api
       arvados.arvados_api
@@ -147,7 +175,7 @@ class Arvados
     end
     def self.api_exec(method, parameters={})
       parameters = parameters.
-        merge(:api_token => ENV['ARVADOS_API_TOKEN'])
+        merge(:api_token => @config['ARVADOS_API_TOKEN'])
       parameters.each do |k,v|
         parameters[k] = v.to_json if v.is_a? Array or v.is_a? Hash
       end

commit f1eba78bed609adcbcfb0fbf370485e538791fde
Author: Tim Pierce <twp at curoverse.com>
Date:   Tue Jan 21 15:28:19 2014 -0500

    Updating API parameter documentation (refs #1901)
    
    Removed unused parameters.
    More docs for the "list" command.
    Use only the first line of the parameter documentation in "arv resource help".

diff --git a/doc/gen_api_method_docs.py b/doc/gen_api_method_docs.py
index ddafeea..ac8fe03 100755
--- a/doc/gen_api_method_docs.py
+++ b/doc/gen_api_method_docs.py
@@ -9,13 +9,35 @@
 # and will generate Textile documentation files in the current
 # directory.
 
-import requests
+import argparse
+import pprint
 import re
+import requests
 import os
-import pprint
+import sys #debugging
+
+p = argparse.ArgumentParser(description='Generate Arvados API method documentation.')
+
+p.add_argument('--host',
+               type=str,
+               default='localhost',
+               help="The hostname or IP address of the API server")
+
+p.add_argument('--port',
+               type=int,
+               default=9900,
+               help="The port of the API server")
+
+p.add_argument('--output-dir',
+               type=str,
+               default='.',
+               help="Directory in which to write output files.")
+
+args = p.parse_args()
+
+api_url = 'https://{host}:{port}/discovery/v1/apis/arvados/v1/rest'.format(**vars(args))
 
-r = requests.get('https://localhost:9900/discovery/v1/apis/arvados/v1/rest',
-                 verify=False)
+r = requests.get(api_url, verify=False)
 if r.status_code != 200:
     raise Exception('Bad status code %d: %s' % (r.status_code, r.text))
 
@@ -23,15 +45,19 @@ if 'application/json' not in r.headers.get('content-type', ''):
     raise Exception('Unexpected content type: %s: %s' %
                     (r.headers.get('content-type', ''), r.text))
 
-api = r.json
+api = r.json()
 
 resource_num = 0
 for resource in sorted(api[u'resources']):
     resource_num = resource_num + 1
-    out_fname = resource + '.textile'
+    out_fname = os.path.join(args.output_dir, resource + '.textile')
     if os.path.exists(out_fname):
-        print "PATH EXISTS ", out_fname
-        next
+        backup_name = out_fname + '.old'
+        try:
+            os.rename(out_fname, backup_name)
+        except OSError as e:
+            print "WARNING: could not back up {1} as {2}: {3}".format(
+                out_fname, backup_name, e)
     outf = open(out_fname, 'w')
     outf.write(
 """---
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 3fd3c57..b133a77 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -152,7 +152,10 @@ def help_methods(discovery_document, resource, method=nil)
   discovery_document["resources"][resource.pluralize]["methods"].
     each do |k,v|
     description = ''
-    description = '  ' + v["description"] if v.include?("description")
+    if v.include? "description"
+      # add only the first line of the discovery doc description
+      description = '  ' + v["description"].split("\n").first.chomp
+    end
     banner += "   #{sprintf("%20s",k)}#{description}\n"
   end
   banner += "\n"
@@ -171,9 +174,10 @@ def help_resources(discovery_document, resource)
   banner += "\n\n"
   discovery_document["resources"].each do |k,v|
     description = ''
-    if discovery_document["schemas"].include?(k.singularize.capitalize) and 
-        discovery_document["schemas"][k.singularize.capitalize].include?('description') then
-      description = '  ' + discovery_document["schemas"][k.singularize.capitalize]["description"]
+    resource_info = discovery_document["schemas"][k.singularize.capitalize]
+    if resource_info and resource_info.include?('description')
+      # add only the first line of the discovery doc description
+      description = '  ' + resource_info["description"].split("\n").first.chomp
     end
     banner += "   #{sprintf("%30s",k.singularize)}#{description}\n"
   end
diff --git a/services/api/app/controllers/arvados/v1/schema_controller.rb b/services/api/app/controllers/arvados/v1/schema_controller.rb
index 0baa865..8a16356 100644
--- a/services/api/app/controllers/arvados/v1/schema_controller.rb
+++ b/services/api/app/controllers/arvados/v1/schema_controller.rb
@@ -188,7 +188,28 @@ class Arvados::V1::SchemaController < ApplicationController
               id: "arvados.#{k.to_s.underscore.pluralize}.list",
               path: k.to_s.underscore.pluralize,
               httpMethod: "GET",
-              description: "List #{k.to_s.underscore.pluralize}.",
+              description:
+                 %|List #{k.to_s.pluralize}.
+
+                   The <code>list</code> method returns a 
+                   <a href="/api/resources.html">resource list</a> of
+                   matching #{k.to_s.pluralize}. For example:
+
+                   <pre>
+                   {
+                    "kind":"arvados##{k.to_s.camelcase(:lower)}List",
+                    "etag":"",
+                    "self_link":"",
+                    "next_page_token":"",
+                    "next_link":"",
+                    "items":[
+                       ...
+                    ],
+                    "items_available":745,
+                    "_profile":{
+                     "request_time":0.157236317
+                    }
+                    </pre>|,
               parameters: {
                 limit: {
                   type: "integer",
@@ -196,17 +217,7 @@ class Arvados::V1::SchemaController < ApplicationController
                   default: 100,
                   format: "int32",
                   minimum: 0,
-                  location: "query"
-                },
-                pageToken: {
-                  type: "string",
-                  description: "Page token.",
-                  location: "query"
-                },
-                q: {
-                  type: "string",
-                  description: "Query string for searching #{k.to_s.underscore.pluralize}.",
-                  location: "query"
+                  location: "query",
                 },
                 where: {
                   type: "object",

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list