chimps 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -107
- data/VERSION +1 -1
- data/bin/chimps +1 -1
- data/lib/chimps/cli.rb +8 -85
- data/lib/chimps/commands/base.rb +9 -61
- data/lib/chimps/commands/batch.rb +2 -30
- data/lib/chimps/commands/create.rb +1 -3
- data/lib/chimps/commands/destroy.rb +1 -3
- data/lib/chimps/commands/download.rb +15 -45
- data/lib/chimps/commands/help.rb +16 -5
- data/lib/chimps/commands/list.rb +3 -16
- data/lib/chimps/commands/query.rb +5 -11
- data/lib/chimps/commands/search.rb +6 -17
- data/lib/chimps/commands/show.rb +1 -3
- data/lib/chimps/commands/test.rb +2 -3
- data/lib/chimps/commands/update.rb +1 -3
- data/lib/chimps/commands/upload.rb +6 -25
- data/lib/chimps/commands.rb +106 -27
- data/lib/chimps/config.rb +35 -72
- data/lib/chimps/request.rb +14 -14
- data/lib/chimps/typewriter.rb +4 -0
- data/lib/chimps/utils/log.rb +5 -7
- data/lib/chimps/utils/uses_model.rb +3 -20
- data/lib/chimps/utils/uses_yaml_data.rb +5 -13
- data/lib/chimps/workflows/upload/bundler.rb +3 -3
- data/lib/chimps/workflows/upload/notifier.rb +1 -1
- data/lib/chimps.rb +7 -1
- metadata +65 -31
- data/spec/chimps/cli_spec.rb +0 -22
- data/spec/chimps/commands/base_spec.rb +0 -25
- data/spec/chimps/commands/list_spec.rb +0 -25
data/LICENSE
CHANGED
@@ -1,107 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Version 2.0, January 2004
|
22
|
-
http://www.apache.org/licenses/
|
23
|
-
|
24
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
25
|
-
|
26
|
-
<notextile><div class="toggle"></notextile>
|
27
|
-
|
28
|
-
h2. 1. Definitions.
|
29
|
-
|
30
|
-
* **License** shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
31
|
-
* **Licensor** shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
32
|
-
* **Legal Entity** shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, **control** means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
33
|
-
* **You** (or **Your**) shall mean an individual or Legal Entity exercising permissions granted by this License.
|
34
|
-
* **Source** form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
35
|
-
* **Object** form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
36
|
-
* **Work** shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
37
|
-
* **Derivative Works** shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
38
|
-
* **Contribution** shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, **submitted** means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
39
|
-
* **Contributor** shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
40
|
-
|
41
|
-
<notextile></div><div class="toggle"></notextile>
|
42
|
-
|
43
|
-
h2. 2. Grant of Copyright License.
|
44
|
-
|
45
|
-
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
46
|
-
|
47
|
-
|
48
|
-
<notextile></div><div class="toggle"></notextile>
|
49
|
-
|
50
|
-
h2. 3. Grant of Patent License.
|
51
|
-
|
52
|
-
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
53
|
-
|
54
|
-
<notextile></div><div class="toggle"></notextile>
|
55
|
-
|
56
|
-
h2. 4. Redistribution.
|
57
|
-
|
58
|
-
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
59
|
-
|
60
|
-
# You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
61
|
-
# You must cause any modified files to carry prominent notices stating that You changed the files; and
|
62
|
-
# You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
63
|
-
# If the Work includes a __NOTICE__ text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
64
|
-
|
65
|
-
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
66
|
-
|
67
|
-
<notextile></div><div class="toggle"></notextile>
|
68
|
-
|
69
|
-
h2. 5. Submission of Contributions.
|
70
|
-
|
71
|
-
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
72
|
-
|
73
|
-
<notextile></div><div class="toggle"></notextile>
|
74
|
-
|
75
|
-
h2. 6. Trademarks.
|
76
|
-
|
77
|
-
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
78
|
-
|
79
|
-
<notextile></div><div class="toggle"></notextile>
|
80
|
-
|
81
|
-
h2. 7. Disclaimer of Warranty.
|
82
|
-
|
83
|
-
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an **AS IS** BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
84
|
-
|
85
|
-
<notextile></div><div class="toggle"></notextile>
|
86
|
-
|
87
|
-
h2. 8. Limitation of Liability.
|
88
|
-
|
89
|
-
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
90
|
-
|
91
|
-
<notextile></div><div class="toggle"></notextile>
|
92
|
-
|
93
|
-
h2. 9. Accepting Warranty or Additional Liability.
|
94
|
-
|
95
|
-
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
96
|
-
|
97
|
-
END OF TERMS AND CONDITIONS
|
98
|
-
|
99
|
-
<notextile></div><div class="toggle"></notextile>
|
100
|
-
|
101
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
102
|
-
|
103
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
104
|
-
|
105
|
-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an **AS IS** BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
106
|
-
|
107
|
-
<notextile></div></notextile>
|
1
|
+
Copyright (c) 2010 Dhruv Bansal
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/chimps
CHANGED
data/lib/chimps/cli.rb
CHANGED
@@ -4,102 +4,25 @@ module Chimps
|
|
4
4
|
# instantiated from the ARGV passed in on the command line.
|
5
5
|
module CLI
|
6
6
|
|
7
|
-
|
7
|
+
include Chimps::Commands
|
8
|
+
|
9
|
+
# Execute the Chimps command specified on the command line.
|
8
10
|
#
|
9
11
|
# Will exit the Ruby process with 0 on success or 1 on an error.
|
10
|
-
|
11
|
-
# @param [Array<String>] argv
|
12
|
-
def self.execute! argv
|
12
|
+
def self.execute!
|
13
13
|
begin
|
14
|
-
|
14
|
+
Chimps.boot!
|
15
|
+
command.execute!
|
15
16
|
return 0
|
16
|
-
rescue Chimps::Error => e
|
17
|
+
rescue Chimps::Error, Configliere::Error => e
|
17
18
|
puts e.message
|
18
19
|
return 1
|
19
20
|
rescue => e
|
20
21
|
$stderr.puts("#{e.message} (#{e.class})")
|
21
22
|
$stderr.puts(e.backtrace.join("\n"))
|
22
|
-
return
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Defines methods to parse the original ARGV and from it choose
|
27
|
-
# and instantiate the appropriate Chimps::Command subclass with
|
28
|
-
# the appropriate arguments.
|
29
|
-
class Runner
|
30
|
-
include Chimps::Commands
|
31
|
-
|
32
|
-
# The original ARGV passed in by the user.
|
33
|
-
attr_reader :argv
|
34
|
-
|
35
|
-
# Create a new Chimps::CLI::Runner from +argv+.
|
36
|
-
#
|
37
|
-
# @param [Array<String>] argv
|
38
|
-
# @return [Chimps::CLI::Runner]
|
39
|
-
def initialize argv
|
40
|
-
@argv = argv
|
41
|
-
end
|
42
|
-
|
43
|
-
# Execute this Runner's chosen and initialized command.
|
44
|
-
def execute!
|
45
|
-
command.execute!
|
46
|
-
end
|
47
|
-
|
48
|
-
# The chosen and initialized command for this Runner.
|
49
|
-
#
|
50
|
-
# @return [Chimps::Command]
|
51
|
-
def command
|
52
|
-
@command ||= construct(command_name, argv_for_command)
|
53
|
-
end
|
54
|
-
|
55
|
-
protected
|
56
|
-
|
57
|
-
# Return the index in ARGV of the command name to run.
|
58
|
-
#
|
59
|
-
# It may not always be the first element of ARGV because
|
60
|
-
#
|
61
|
-
# chimps show my-dataset
|
62
|
-
# chimps -v show my-dataset
|
63
|
-
# chimps show -v my-dataset
|
64
|
-
#
|
65
|
-
# should all have the same behavior.
|
66
|
-
#
|
67
|
-
# @return [Integer] the index in ARGV of the command name.
|
68
|
-
def command_index
|
69
|
-
return @command_index if @command_index
|
70
|
-
argv.each_with_index do |arg, index|
|
71
|
-
if command_name?(arg)
|
72
|
-
@command_index = index
|
73
|
-
break
|
74
|
-
end
|
75
|
-
end
|
76
|
-
@command_index or raise CLIError.new("Must specify a command. Try running `chimps help'")
|
77
|
-
end
|
78
|
-
|
79
|
-
# The name of the command to run.
|
80
|
-
#
|
81
|
-
# @return [String]
|
82
|
-
def command_name
|
83
|
-
@command_name ||= argv[command_index]
|
84
|
-
end
|
85
|
-
|
86
|
-
# The ARGV to pass to the command chosen to run.
|
87
|
-
#
|
88
|
-
# It differs from the original ARGV only in that the command's
|
89
|
-
# name has been stripped:
|
90
|
-
#
|
91
|
-
# Chimps::CLI::Runner.new('show', '-v', 'my-dataset').argv_for_command
|
92
|
-
# => ['-v','my-dataset']
|
93
|
-
#
|
94
|
-
# This does not always return "all but the first element" of
|
95
|
-
# ARGV; see Chimps::CLI::Runner#command_index for details.
|
96
|
-
def argv_for_command
|
97
|
-
returning(argv.dup) do |new_argv|
|
98
|
-
new_argv.delete_at(command_index)
|
99
|
-
end
|
23
|
+
return 2
|
100
24
|
end
|
101
25
|
end
|
102
|
-
|
103
26
|
end
|
104
27
|
end
|
105
28
|
|
data/lib/chimps/commands/base.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
1
|
module Chimps
|
4
2
|
|
5
3
|
# A base class from which to subclass specific commands. A subclass
|
@@ -14,32 +12,30 @@ module Chimps
|
|
14
12
|
#
|
15
13
|
# - define a method <tt>execute!</tt> which will actually run the
|
16
14
|
# command.
|
17
|
-
class Command
|
15
|
+
class Command
|
18
16
|
|
19
17
|
# Appears when printing help for this command, as the very first
|
20
18
|
# line. Should be one-line summary of how to use this command.
|
21
|
-
|
19
|
+
USAGE = "Define #{self}::USAGE when you subclass Chimps::Command"
|
22
20
|
|
23
21
|
# Appears when printing help for this command. Should consist of
|
24
22
|
# general help or examples of the command iteslf. Help on
|
25
23
|
# specific options is automatically generated.
|
26
24
|
HELP = "Define #{self}::HELP when you subclass Chimps::Command"
|
27
25
|
|
28
|
-
# The
|
29
|
-
|
26
|
+
# The configuration settings for this command.
|
27
|
+
#
|
28
|
+
# @return [Configliere::Param]
|
29
|
+
attr_accessor :config
|
30
30
|
|
31
31
|
# Create a new command. Will define options specific to
|
32
32
|
# subclases, parse the given +argv+, and load the global Chimps
|
33
33
|
# configuration. Will _not_ execute the command.
|
34
34
|
#
|
35
|
-
# @param
|
35
|
+
# @param [Configliere::Param]
|
36
36
|
# @return [Chimps::Command]
|
37
|
-
def initialize
|
38
|
-
|
39
|
-
@argv = argv
|
40
|
-
run_options_definers
|
41
|
-
parse_command_line!
|
42
|
-
Chimps.boot!
|
37
|
+
def initialize config
|
38
|
+
self.config = config
|
43
39
|
end
|
44
40
|
|
45
41
|
# The name of this command, including the
|
@@ -58,54 +54,6 @@ module Chimps
|
|
58
54
|
self.class.name.split('::').last
|
59
55
|
end
|
60
56
|
|
61
|
-
protected
|
62
|
-
|
63
|
-
# Parse the command line.
|
64
|
-
def parse_command_line!
|
65
|
-
begin
|
66
|
-
parse!(argv)
|
67
|
-
rescue OptionParser::InvalidOption => e
|
68
|
-
raise CLIError.new("#{e.message}. Try `chimps help #{name}'")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Run all methods beginning with +define+ and ending with +option+
|
73
|
-
# or +options+.
|
74
|
-
#
|
75
|
-
# This is (hackish) mechanism for subclasses of Chimps::Command to
|
76
|
-
# define their own specific options.
|
77
|
-
def run_options_definers
|
78
|
-
# FIXME there's a better way to do this...
|
79
|
-
methods.grep(/^define.+options?$/).each { |method| send method }
|
80
|
-
end
|
81
|
-
|
82
|
-
# Define options common to all Chimps' commands. The two only two
|
83
|
-
# such options at the moment are <tt>-v</tt> (or
|
84
|
-
# <tt>--[no-]verbose</tt>) for verbosity, and <tt>-i</tt> (or
|
85
|
-
# <tt>--identity-file</tt>) for setting the identify file to use.
|
86
|
-
# <tt>--log-file</tt>) for setting the log file to use.
|
87
|
-
def define_common_options
|
88
|
-
separator self.class::HELP
|
89
|
-
separator "\nOptions include:"
|
90
|
-
|
91
|
-
on("-v", "--[no-]verbose", "Be verbose, or not.") do |verbose|
|
92
|
-
Chimps::COMMAND_LINE_OPTIONS[:verbose] = verbose
|
93
|
-
end
|
94
|
-
|
95
|
-
on("-i", "--identity-file PATH", "Use the given YAML identify file to authenticate with Infochimps instead of the default (~/.chimps) ") do |path|
|
96
|
-
Chimps::COMMAND_LINE_OPTIONS[:identity_file] = File.expand_path(path)
|
97
|
-
end
|
98
|
-
|
99
|
-
on("-l", "--log-file PATH", "Use the given path to log Chimps output (`-' is interpreted as $stdout).") do |path|
|
100
|
-
Chimps::COMMAND_LINE_OPTIONS[:log_file] = path # don't expand_path as it might be a `-'
|
101
|
-
end
|
102
|
-
|
103
|
-
on("-q", "--skip-plugins", "Don't load plugins from Chimps::CONFIG[:plugins] directory.") do |bool|
|
104
|
-
Chimps::CONFIG[:skip_plugins] = true
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
57
|
# Run this command.
|
110
58
|
#
|
111
59
|
# Will raise a NotImplementedError for Chimps::Command itself --
|
@@ -4,7 +4,7 @@ module Chimps
|
|
4
4
|
# A command for performing batch updates.
|
5
5
|
class Batch < Chimps::Command
|
6
6
|
|
7
|
-
|
7
|
+
USAGE = "usage: chimps batch [OPTIONS] [INPUT_PATH] ..."
|
8
8
|
HELP = <<EOF
|
9
9
|
|
10
10
|
Perform a batch operation on Infochimps by reading YAML input files.
|
@@ -26,40 +26,12 @@ The format of the YAML input files is given at
|
|
26
26
|
http://infochimps.org/api
|
27
27
|
EOF
|
28
28
|
|
29
|
-
# A path to store the intermediate batch response. Useful for
|
30
|
-
# debugging.
|
31
|
-
attr_accessor :output_path
|
32
|
-
|
33
|
-
# The data format to annotate the upload with.
|
34
|
-
#
|
35
|
-
# Chimps will try to guess if this isn't given.
|
36
|
-
attr_reader :fmt
|
37
|
-
|
38
|
-
# Whether to continue to upload even if some of the resources
|
39
|
-
# had errors on update/create.
|
40
|
-
attr_accessor :upload_even_if_errors
|
41
|
-
|
42
29
|
include Chimps::Utils::UsesYamlData
|
43
30
|
|
44
|
-
def define_options
|
45
|
-
on_tail("-o", "--output PATH", "Store the response from the server at PATH") do |o|
|
46
|
-
@output_path = File.expand_path(o)
|
47
|
-
end
|
48
|
-
|
49
|
-
on_tail("-e", "--force", "Attempt to upload data even when there were errors in the batch update request") do |e|
|
50
|
-
@upload_even_if_errors = e
|
51
|
-
end
|
52
|
-
|
53
|
-
on_tail("-f", "--format FORMAT", "Data format to annotate EACH upload with. Tries to guess if not given.") do |f|
|
54
|
-
@fmt = f
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
31
|
# Perform the batch update and upload.
|
60
32
|
def execute!
|
61
33
|
ensure_data_is_present!
|
62
|
-
Chimps::Workflows::BatchUpdater.new(data, :output_path =>
|
34
|
+
Chimps::Workflows::BatchUpdater.new(data, :output_path => config[:output], :upload_even_if_errors => config[:force], :fmt => config[:format]).execute!
|
63
35
|
end
|
64
36
|
|
65
37
|
end
|
@@ -5,7 +5,7 @@ module Chimps
|
|
5
5
|
# Infochimps.
|
6
6
|
class Create < Chimps::Command
|
7
7
|
|
8
|
-
|
8
|
+
USAGE = "usage: chimps create [OPTIONS] [PROP=VALUE] ..."
|
9
9
|
HELP = <<EOF
|
10
10
|
|
11
11
|
Create a single resource (defaults to a dataset) using the properties
|
@@ -16,8 +16,6 @@ from an input YAML file, or multiple YAML documents streamed in via
|
|
16
16
|
STDIN, in order of decreasing precedence.
|
17
17
|
EOF
|
18
18
|
|
19
|
-
# Models this command applies to (default first)
|
20
|
-
MODELS = %w[dataset source license]
|
21
19
|
include Chimps::Utils::UsesModel
|
22
20
|
include Chimps::Utils::UsesYamlData
|
23
21
|
|
@@ -5,7 +5,7 @@ module Chimps
|
|
5
5
|
# Infochimps.
|
6
6
|
class Destroy < Chimps::Command
|
7
7
|
|
8
|
-
|
8
|
+
USAGE = "usage: chimps destroy [OPTIONS] ID_OR_HANDLE"
|
9
9
|
HELP = <<EOF
|
10
10
|
|
11
11
|
Destroys a resource of a given type (defaults to dataset) identified
|
@@ -13,8 +13,6 @@ by ID_OR_HANDLE.
|
|
13
13
|
|
14
14
|
EOF
|
15
15
|
|
16
|
-
# Models this command applies to (default first)
|
17
|
-
MODELS = %w[dataset package source license]
|
18
16
|
include Chimps::Utils::UsesModel
|
19
17
|
|
20
18
|
# Issue the DELETE request.
|
@@ -4,7 +4,7 @@ module Chimps
|
|
4
4
|
# A command to download data from Infochimps.
|
5
5
|
class Download < Chimps::Command
|
6
6
|
|
7
|
-
|
7
|
+
USAGE = "usage: chimps download [OPTIONS] ID_OR_HANDLE"
|
8
8
|
HELP = <<EOF
|
9
9
|
|
10
10
|
Download a dataset identified by the given ID_OR_HANDLE to the current
|
@@ -14,60 +14,30 @@ If the dataset isn't freely downloadable, you'll have to have
|
|
14
14
|
purchased it first via the Web.
|
15
15
|
EOF
|
16
16
|
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
# The chosen package format.
|
21
|
-
attr_reader :pkg_fmt
|
22
|
-
|
23
|
-
# The local path to download the data to.
|
24
|
-
attr_reader :local_path
|
25
|
-
|
26
|
-
# Set the format for the download token.
|
27
|
-
#
|
28
|
-
# Will try to normalize the input somewhat (downcasing,
|
29
|
-
# stripping leading periods)
|
30
|
-
#
|
31
|
-
# @param [String] new_fmt
|
32
|
-
def fmt= new_fmt
|
33
|
-
@fmt = new_fmt.downcase.strip.gsub(/^\./, '')
|
34
|
-
end
|
35
|
-
|
36
|
-
# Set the package format for the download token.
|
37
|
-
#
|
38
|
-
# Will try to normalize the input somewhat (downcasing,
|
39
|
-
# stripping leading periods)
|
17
|
+
# Return the given string downcased and stripped of leading
|
18
|
+
# periods.
|
40
19
|
#
|
41
|
-
# @param [String]
|
42
|
-
|
43
|
-
|
20
|
+
# @param [String] string
|
21
|
+
# @return [String, nil]
|
22
|
+
def normalize string
|
23
|
+
return string if string.blank?
|
24
|
+
string.downcase.strip.gsub(/^\./, '')
|
44
25
|
end
|
45
26
|
|
46
27
|
# The ID of the package to download.
|
47
28
|
def dataset
|
48
|
-
raise CLIError.new("Must provide an ID or handle of a dataset to download.") if argv.first.blank?
|
49
|
-
argv.first
|
29
|
+
raise CLIError.new("Must provide an ID or handle of a dataset to download.") if config.argv.first.blank?
|
30
|
+
config.argv.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def local_path
|
34
|
+
config[:output].blank? ? config[:output] : File.expand_path(config[:output])
|
50
35
|
end
|
51
36
|
|
52
37
|
# Issue the request for the token and the request for the
|
53
38
|
# download.
|
54
39
|
def execute!
|
55
|
-
Chimps::Workflows::Downloader.new(:dataset => dataset, :fmt =>
|
56
|
-
end
|
57
|
-
|
58
|
-
def define_options
|
59
|
-
on_tail("-o", "--output PATH", "Path to download file to") do |o|
|
60
|
-
@local_path = File.expand_path(o)
|
61
|
-
end
|
62
|
-
|
63
|
-
on_tail("-f", "--format FORMAT", "Choose a particular data format (csv, tsv, excel, &c.)") do |f|
|
64
|
-
self.fmt = f
|
65
|
-
end
|
66
|
-
|
67
|
-
on_tail("-p", "--package PACKAGE", "Choose a particular package type (zip or tar.bz2)") do |p|
|
68
|
-
self.pkg_fmt = p
|
69
|
-
end
|
70
|
-
|
40
|
+
Chimps::Workflows::Downloader.new(:dataset => dataset, :fmt => normalize(config[:format]), :pkg_fmt => normalize(config[:pkg_fmt]), :local_path => local_path).execute!
|
71
41
|
end
|
72
42
|
|
73
43
|
end
|
data/lib/chimps/commands/help.rb
CHANGED
@@ -2,7 +2,8 @@ module Chimps
|
|
2
2
|
module Commands
|
3
3
|
class Help < Chimps::Command
|
4
4
|
|
5
|
-
|
5
|
+
USAGE = "usage: chimps help [OPTIONS] [COMMAND]"
|
6
|
+
|
6
7
|
HELP = <<EOF
|
7
8
|
|
8
9
|
This is the Infochimps command-line client. You can use it to search,
|
@@ -58,7 +59,7 @@ for any of the commands above.
|
|
58
59
|
= Setup
|
59
60
|
|
60
61
|
Once you have obtained an API key and secret from Infochimps, place
|
61
|
-
them in a file Chimps::
|
62
|
+
them in a file Chimps::Config[:config] in your home directory
|
62
63
|
with the following format
|
63
64
|
|
64
65
|
---
|
@@ -74,12 +75,22 @@ with the following format
|
|
74
75
|
:key: zei7eeloShoah3Ce
|
75
76
|
:secret: eixairaichaxaaRe8eeya5moh8Uthahf0pi4eig7SoirohPhei6sai8aereu0yuepiefeipoozoegahchaeheedee8uphohoo9moongae8Fa0aih4BooSeiM
|
76
77
|
EOF
|
78
|
+
|
79
|
+
|
80
|
+
def fake_command name
|
81
|
+
Chimps::Commands.class_for(name).new(Chimps::Config.commands[name][:config])
|
82
|
+
end
|
77
83
|
|
78
84
|
def execute!
|
79
|
-
if argv.first
|
80
|
-
|
85
|
+
if Chimps::Config.command?(config.argv.first)
|
86
|
+
command = fake_command(config.argv.first)
|
87
|
+
$stderr.puts command.class::USAGE
|
88
|
+
$stderr.puts command.class::HELP
|
89
|
+
command.config.dump_basic_help
|
90
|
+
Chimps::Config.dump_basic_help
|
81
91
|
else
|
82
|
-
puts Chimps::
|
92
|
+
$stderr.puts Chimps::Config.usage
|
93
|
+
Chimps::Config.dump_help
|
83
94
|
end
|
84
95
|
end
|
85
96
|
|
data/lib/chimps/commands/list.rb
CHANGED
@@ -5,7 +5,7 @@ module Chimps
|
|
5
5
|
# at Infochimps.
|
6
6
|
class List < Chimps::Command
|
7
7
|
|
8
|
-
|
8
|
+
USAGE = "usage: chimps list [OPTIONS]"
|
9
9
|
HELP = <<EOF
|
10
10
|
|
11
11
|
List resources of a given type (defaults to dataset).
|
@@ -14,24 +14,11 @@ Lists your resources by default but see options below.
|
|
14
14
|
|
15
15
|
EOF
|
16
16
|
|
17
|
-
# Models that can be indexed (default first)
|
18
|
-
MODELS = %w[dataset license source]
|
19
17
|
include Chimps::Utils::UsesModel
|
20
18
|
|
21
|
-
def define_options
|
22
|
-
on_tail("-a", "--all", "List all resources, not just those owned by you.") do |a|
|
23
|
-
@all = a
|
24
|
-
end
|
25
|
-
|
26
|
-
on_tail("-s", "--[no-]skip-column-names", "Don't print column names in output.") do |s|
|
27
|
-
@skip_column_names = s
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
19
|
# List all resources or just those owned by the Chimps user?
|
33
20
|
def all?
|
34
|
-
|
21
|
+
config[:all]
|
35
22
|
end
|
36
23
|
|
37
24
|
# Parameters to include in the query.
|
@@ -45,7 +32,7 @@ EOF
|
|
45
32
|
|
46
33
|
# Issue the GET request.
|
47
34
|
def execute!
|
48
|
-
Request.new(models_path, :params => params).get.print(:skip_column_names =>
|
35
|
+
Request.new(models_path, :params => params).get.print(:skip_column_names => config[:skip_column_names])
|
49
36
|
end
|
50
37
|
|
51
38
|
end
|
@@ -5,7 +5,7 @@ module Chimps
|
|
5
5
|
# query API.
|
6
6
|
class Query < Chimps::Command
|
7
7
|
|
8
|
-
|
8
|
+
USAGE = "usage: chimps query [OPTIONS] DATASET [PROP=VALUE] ..."
|
9
9
|
HELP = <<EOF
|
10
10
|
|
11
11
|
Make a query of the given DATASET on the Infochimps paid query API
|
@@ -34,8 +34,8 @@ EOF
|
|
34
34
|
#
|
35
35
|
# @return [String]
|
36
36
|
def dataset
|
37
|
-
raise CLIError.new("Must provide a dataset to query.") if argv.first.blank?
|
38
|
-
argv.first
|
37
|
+
raise CLIError.new("Must provide a dataset to query.") if config.argv.first.blank?
|
38
|
+
config.argv.first
|
39
39
|
end
|
40
40
|
|
41
41
|
# The path on the Infochimps query API to query.
|
@@ -49,20 +49,14 @@ EOF
|
|
49
49
|
#
|
50
50
|
# @return [true, nil]
|
51
51
|
def pretty_print?
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
# Define options for queries.
|
56
|
-
def define_query_options
|
57
|
-
on_tail("-p", "--[no-]pretty-print", "Pretty print the output.") do |p|
|
58
|
-
@pretty_print = p
|
59
|
-
end
|
52
|
+
config[:pretty_print]
|
60
53
|
end
|
61
54
|
|
62
55
|
# The requests that will be sent to the server.
|
63
56
|
#
|
64
57
|
# @return [Array<Chimps::QueryRequest>]
|
65
58
|
def requests
|
59
|
+
ensure_data_is_present!
|
66
60
|
if data.is_a?(Hash)
|
67
61
|
[QueryRequest.new(path, :query_params => data, :authenticate => true)]
|
68
62
|
else # it's an Array, see Chimps::Utils::UsesYamlData
|