specify_cli 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +17 -0
  5. data/Gemfile.lock +117 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.rdoc +43 -0
  8. data/Rakefile +15 -0
  9. data/bin/specify_cli +248 -0
  10. data/lib/specify.rb +45 -0
  11. data/lib/specify/branch_parser.rb +85 -0
  12. data/lib/specify/cli.rb +11 -0
  13. data/lib/specify/cli/database_setup.rb +46 -0
  14. data/lib/specify/cli/stubs.rb +63 -0
  15. data/lib/specify/cli/viewset.rb +21 -0
  16. data/lib/specify/configuration.rb +12 -0
  17. data/lib/specify/configuration/config.rb +120 -0
  18. data/lib/specify/configuration/db_config.rb +162 -0
  19. data/lib/specify/configuration/host_config.rb +37 -0
  20. data/lib/specify/database.rb +140 -0
  21. data/lib/specify/models.rb +43 -0
  22. data/lib/specify/models/accession.rb +33 -0
  23. data/lib/specify/models/agent.rb +138 -0
  24. data/lib/specify/models/app_resource_data.rb +32 -0
  25. data/lib/specify/models/app_resource_dir.rb +43 -0
  26. data/lib/specify/models/auto_numbering_scheme.rb +94 -0
  27. data/lib/specify/models/collecting_event.rb +38 -0
  28. data/lib/specify/models/collection.rb +67 -0
  29. data/lib/specify/models/collection_object.rb +127 -0
  30. data/lib/specify/models/createable.rb +21 -0
  31. data/lib/specify/models/determination.rb +63 -0
  32. data/lib/specify/models/discipline.rb +61 -0
  33. data/lib/specify/models/division.rb +26 -0
  34. data/lib/specify/models/geography.rb +5 -0
  35. data/lib/specify/models/geography/administrative_division.rb +32 -0
  36. data/lib/specify/models/geography/geographic_name.rb +66 -0
  37. data/lib/specify/models/geography/geography.rb +23 -0
  38. data/lib/specify/models/institution.rb +13 -0
  39. data/lib/specify/models/locality.rb +50 -0
  40. data/lib/specify/models/preparation.rb +53 -0
  41. data/lib/specify/models/preparation_type.rb +30 -0
  42. data/lib/specify/models/record_set.rb +55 -0
  43. data/lib/specify/models/record_set_item.rb +29 -0
  44. data/lib/specify/models/taxonomy.rb +6 -0
  45. data/lib/specify/models/taxonomy/common_name.rb +14 -0
  46. data/lib/specify/models/taxonomy/rank.rb +31 -0
  47. data/lib/specify/models/taxonomy/taxon.rb +54 -0
  48. data/lib/specify/models/taxonomy/taxonomy.rb +21 -0
  49. data/lib/specify/models/tree_queryable.rb +55 -0
  50. data/lib/specify/models/updateable.rb +20 -0
  51. data/lib/specify/models/user.rb +104 -0
  52. data/lib/specify/models/view_set_object.rb +32 -0
  53. data/lib/specify/number_format.rb +60 -0
  54. data/lib/specify/services.rb +18 -0
  55. data/lib/specify/services/service.rb +51 -0
  56. data/lib/specify/services/stub_generator.rb +291 -0
  57. data/lib/specify/services/view_loader.rb +177 -0
  58. data/lib/specify/session.rb +77 -0
  59. data/lib/specify/user_type.rb +61 -0
  60. data/lib/specify/version.rb +19 -0
  61. data/man/specify_cli-database.1 +60 -0
  62. data/man/specify_cli-database.1.html +137 -0
  63. data/man/specify_cli-database.1.ronn +53 -0
  64. data/man/specify_cli-repository.1 +55 -0
  65. data/man/specify_cli-repository.1.html +128 -0
  66. data/man/specify_cli-repository.1.ronn +42 -0
  67. data/man/specify_cli-stubs.1 +177 -0
  68. data/man/specify_cli-stubs.1.html +239 -0
  69. data/man/specify_cli-stubs.1.ronn +147 -0
  70. data/man/specify_cli-viewset.1 +92 -0
  71. data/man/specify_cli-viewset.1.html +154 -0
  72. data/man/specify_cli-viewset.1.ronn +72 -0
  73. data/man/specify_cli.1 +213 -0
  74. data/man/specify_cli.1.html +252 -0
  75. data/man/specify_cli.1.ronn +157 -0
  76. data/spec/branch_parser_spec.rb +94 -0
  77. data/spec/cli/stubs_spec.rb +44 -0
  78. data/spec/configuration/config_spec.rb +269 -0
  79. data/spec/configuration/db_config_spec.rb +299 -0
  80. data/spec/configuration/host_config_spec.rb +64 -0
  81. data/spec/database_spec.rb +83 -0
  82. data/spec/examples.txt +217 -0
  83. data/spec/helpers.rb +15 -0
  84. data/spec/models/app_resource_data_spec.rb +38 -0
  85. data/spec/models/app_resource_dir_spec.rb +8 -0
  86. data/spec/models/auto_numbering_scheme_spec.rb +78 -0
  87. data/spec/models/collection_object_spec.rb +92 -0
  88. data/spec/models/collection_spec.rb +32 -0
  89. data/spec/models/discipline_spec.rb +31 -0
  90. data/spec/models/record_set_spec.rb +18 -0
  91. data/spec/models/user_spec.rb +182 -0
  92. data/spec/models/view_set_object_spec.rb +70 -0
  93. data/spec/number_format_spec.rb +43 -0
  94. data/spec/services/stub_generator_spec.rb +635 -0
  95. data/spec/services/view_loader_spec.rb +436 -0
  96. data/spec/session_spec.rb +105 -0
  97. data/spec/spec_helper.rb +116 -0
  98. data/spec/support/db.yml +12 -0
  99. data/spec/support/stub.yaml +17 -0
  100. data/spec/support/stub_locality.yaml +19 -0
  101. data/spec/support/viewsets/paleo.views.xml +30 -0
  102. data/spec/support/viewsets/paleo.xml +30 -0
  103. data/spec/user_type_spec.rb +79 -0
  104. data/specify_cli.gemspec +27 -0
  105. data/specify_cli.rdoc +1 -0
  106. metadata +246 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8799a93ccc9c189a5c81529dc68373ed22ca8c073ac9589c1b2016a6cb09e352
4
+ data.tar.gz: 78d18d4eab1eda1afa972040348ca5d4ad0520ae26c7504f287ff165f80739ec
5
+ SHA512:
6
+ metadata.gz: e1dfe87fffb47d79d871908591f200ba265f335cf48dad313e9e3ca84a871c1ca5109cf5c71ce852d0cdf8207e399d152d515524f708ced5c5b6262cffd9cf5c
7
+ data.tar.gz: e3c08eb2cb4086ea1416e396a140d5b5b28ffdc72d02f3dc12519864a1e8d1273e24a568cd255598aa27afca99a4f7a46ac03eb020672467450fcc9c246d50da
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ tags
3
+ /pkg
4
+ /html
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # testing
8
+ gem 'pry'
9
+ gem 'rspec'
10
+ gem 'rubocop-rspec'
11
+ gem 'pry-byebug'
12
+
13
+ # documentation
14
+ gem 'gem-man'
15
+ gem 'ronn'
16
+
17
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ specify_cli (0.0.5)
5
+ gli (= 2.17.2)
6
+ mysql2 (= 0.5.2)
7
+ sequel (= 5.11.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ aruba (0.14.6)
13
+ childprocess (>= 0.6.3, < 0.10.0)
14
+ contracts (~> 0.9)
15
+ cucumber (>= 1.3.19)
16
+ ffi (~> 1.9.10)
17
+ rspec-expectations (>= 2.99)
18
+ thor (~> 0.19)
19
+ ast (2.4.0)
20
+ backports (3.11.4)
21
+ builder (3.2.3)
22
+ byebug (10.0.2)
23
+ childprocess (0.9.0)
24
+ ffi (~> 1.0, >= 1.0.11)
25
+ coderay (1.1.2)
26
+ contracts (0.16.0)
27
+ cucumber (3.1.2)
28
+ builder (>= 2.1.2)
29
+ cucumber-core (~> 3.2.0)
30
+ cucumber-expressions (~> 6.0.1)
31
+ cucumber-wire (~> 0.0.1)
32
+ diff-lcs (~> 1.3)
33
+ gherkin (~> 5.1.0)
34
+ multi_json (>= 1.7.5, < 2.0)
35
+ multi_test (>= 0.1.2)
36
+ cucumber-core (3.2.0)
37
+ backports (>= 3.8.0)
38
+ cucumber-tag_expressions (~> 1.1.0)
39
+ gherkin (>= 5.0.0)
40
+ cucumber-expressions (6.0.1)
41
+ cucumber-tag_expressions (1.1.1)
42
+ cucumber-wire (0.0.1)
43
+ diff-lcs (1.3)
44
+ ffi (1.9.25)
45
+ gem-man (0.3.0)
46
+ gherkin (5.1.0)
47
+ gli (2.17.2)
48
+ hpricot (0.8.6)
49
+ jaro_winkler (1.5.1)
50
+ method_source (0.9.0)
51
+ multi_json (1.13.1)
52
+ multi_test (0.1.2)
53
+ mustache (1.0.5)
54
+ mysql2 (0.5.2)
55
+ parallel (1.12.1)
56
+ parser (2.5.1.2)
57
+ ast (~> 2.4.0)
58
+ powerpack (0.1.2)
59
+ pry (0.11.3)
60
+ coderay (~> 1.1.0)
61
+ method_source (~> 0.9.0)
62
+ pry-byebug (3.6.0)
63
+ byebug (~> 10.0)
64
+ pry (~> 0.10)
65
+ rainbow (3.0.0)
66
+ rake (12.3.1)
67
+ rdiscount (2.2.0.1)
68
+ rdoc (6.0.4)
69
+ ronn (0.7.3)
70
+ hpricot (>= 0.8.2)
71
+ mustache (>= 0.7.0)
72
+ rdiscount (>= 1.5.8)
73
+ rspec (3.8.0)
74
+ rspec-core (~> 3.8.0)
75
+ rspec-expectations (~> 3.8.0)
76
+ rspec-mocks (~> 3.8.0)
77
+ rspec-core (3.8.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-expectations (3.8.1)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-mocks (3.8.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.8.0)
85
+ rspec-support (3.8.0)
86
+ rubocop (0.58.2)
87
+ jaro_winkler (~> 1.5.1)
88
+ parallel (~> 1.10)
89
+ parser (>= 2.5, != 2.5.1.1)
90
+ powerpack (~> 0.1)
91
+ rainbow (>= 2.2.2, < 4.0)
92
+ ruby-progressbar (~> 1.7)
93
+ unicode-display_width (~> 1.0, >= 1.0.1)
94
+ rubocop-rspec (1.29.0)
95
+ rubocop (>= 0.58.0)
96
+ ruby-progressbar (1.10.0)
97
+ sequel (5.11.0)
98
+ thor (0.20.0)
99
+ unicode-display_width (1.4.0)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ aruba
106
+ gem-man
107
+ pry
108
+ pry-byebug
109
+ rake
110
+ rdoc
111
+ ronn
112
+ rspec
113
+ rubocop-rspec
114
+ specify_cli!
115
+
116
+ BUNDLED WITH
117
+ 1.16.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Martin Stein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = specify_cli - A command line interface for _Specify_
2
+
3
+ Author:: Martin Stein
4
+ Copyright:: Copyright (c) 2018 by Martin Stein
5
+ License:: Distributes under the MIT License, see LICENSE.txt in the source
6
+ distribution
7
+
8
+ specify_cli is a tool that allows certain tasks in a Specify database
9
+ (http://www.sustain.specifysoftware.org) to be carried out from the command
10
+ line.
11
+ Currently supported tasks:
12
+ - upload of views to the database
13
+ - generation of stub records
14
+
15
+ == Install
16
+
17
+ Install:
18
+
19
+ Build with
20
+
21
+ rake package
22
+
23
+ Then install the gem.
24
+
25
+ == Use
26
+
27
+ For more help:
28
+
29
+ specify_cli --help
30
+ gem man specify_cli
31
+
32
+ == For developers
33
+
34
+ Install bundler:
35
+
36
+ gem install bundler
37
+
38
+ Install development dependencies
39
+
40
+ bundle install
41
+
42
+ :include:specify_cli.rdoc
43
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ Rake::RDocTask.new do |rd|
6
+ rd.main = "README.rdoc"
7
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
8
+ rd.title = 'Your application title'
9
+ end
10
+
11
+ spec = eval(File.read('specify_cli.gemspec'))
12
+
13
+ Gem::PackageTask.new(spec) do |pkg|
14
+ end
15
+ task :default => :package
data/bin/specify_cli ADDED
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'gli'
5
+ require 'specify'
6
+
7
+ include GLI::App
8
+
9
+ program_desc Specify::DESCRIPTION
10
+
11
+ version Specify::VERSION
12
+
13
+ subcommand_option_handling :normal
14
+ arguments :strict
15
+
16
+ sessions = []
17
+ script_dir = Dir.pwd
18
+
19
+ desc 'Connect to host.'
20
+ arg_name '[name]'
21
+ default_value 'localhost'
22
+ flag %i[H host]
23
+
24
+ desc 'Port number to use for connection.'
25
+ arg_name '[number]'
26
+ default_value '3306'
27
+ flag %i[p port]
28
+
29
+ desc 'MySQL/MariaDB user for login.'
30
+ arg_name '[name]'
31
+ flag %i[u user]
32
+
33
+ desc 'Password to use when connecting to server. Omit for password prompt.'
34
+ arg_name '[name]'
35
+ flag %i[P password]
36
+
37
+ desc 'Database to use.'
38
+ arg_name '[name]'
39
+ flag %i[D database]
40
+
41
+ desc 'Specify User used for the session.'
42
+ arg_name '[name]'
43
+ flag %i[U specify_user]
44
+
45
+ desc 'YAML File with settings for database connections and directory mappings.'
46
+ arg_name '[path]'
47
+ default_value File.expand_path('~/.specify_dbs.rc.yaml')
48
+ flag %i[c db_config]
49
+
50
+ desc 'Add a database configuration.'
51
+ long_desc <<~HEREDOC
52
+ Add information to work with a Specify database. Use the global option -H to
53
+ provide the host.
54
+ HEREDOC
55
+ arg_name '[database]'
56
+ command [:database, :d] do |c|
57
+ c.action do |global_options, options, args|
58
+ host = global_options[:host]
59
+ database = args.shift
60
+
61
+ file = File.expand_path(global_options[:db_config])
62
+
63
+ Specify::CLI.db_config! file, global_options
64
+
65
+ db_config = Specify::Configuration::DBConfig.new host, database, file
66
+
67
+ if db_config.known?
68
+ STDERR.puts "#{database} on #{host} is already configured"
69
+ exit 0
70
+ else
71
+ unless db_config.host?
72
+ exit 1 unless Specify::CLI.configure_host(db_config)
73
+ end
74
+ Specify::CLI.configure_database db_config
75
+ end
76
+ end
77
+ end
78
+
79
+ desc 'Map a git repository to a host for automatic target resolution.'
80
+ long_desc <<~HEREDOC
81
+ Maps the path of a directory containing a Git repository with Specify resource
82
+ files to a hostname.
83
+ HEREDOC
84
+ arg_name '[repository_name]'
85
+ command [:repository, :r] do |c|
86
+ c.desc 'Map the current directory/repository to the host'
87
+ c.switch %i[c current]
88
+
89
+ c.action do |global_options, options, args|
90
+ host = global_options[:host]
91
+ dir = options[:current] ? Dir.pwd : File.expand_path(args.shift)
92
+
93
+ file = File.expand_path(global_options[:db_config])
94
+
95
+ Specify::CLI.db_config! file, global_options
96
+
97
+ host_config = Specify::Configuration::HostConfig.new file
98
+
99
+ unless host_config.directory? dir
100
+ host_config.map_directory dir, host
101
+ host_config.save
102
+ end
103
+ end
104
+ end
105
+
106
+ desc 'Create stub records'
107
+ long_desc <<~HEREDOC
108
+ The stubs command creates n stub records (where n is the number passed as the
109
+ [count] argument) in the collection passed as the [collection] argument.
110
+ Provide host, database, and connection information using global options.
111
+ HEREDOC
112
+ arg_name '[collection] [count]'
113
+ command [:stubs, :s] do |c|
114
+ c.desc 'Load stub record information from a YAML file.'
115
+ c.arg_name '[yaml_file]'
116
+ c.flag %i[f file]
117
+
118
+ c.desc 'Specify user appearing as cataloger and owner of the record set.'
119
+ c.arg_name '[name]'
120
+ c.flag %i[c cataloger]
121
+
122
+ c.desc 'Name of the datas set (record set) generated.'
123
+ c.arg_name '[name]'
124
+ c.flag %i[d dataset]
125
+
126
+ c.desc 'Accession number for the accession to which the stub records belong.'
127
+ c.arg_name '[accession_number]'
128
+ c.flag %i[a accession]
129
+
130
+ c.desc 'Geographic and locality information for the stub records.'
131
+ c.arg_name '[geography]'
132
+ c.flag %i[g geography]
133
+
134
+ c.desc 'Default locality name if geographic information has no locality.'
135
+ c.arg_name '[name]'
136
+ c.flag %i[l locality]
137
+
138
+ c.desc 'Taxon to which stub records are determined.'
139
+ c.arg_name 'taxon'
140
+ c.flag %i[t taxon]
141
+
142
+ c.desc 'Preparation type for the stub records, if they have preparations.'
143
+ c.arg_name '[name]'
144
+ c.flag %i[p preptype]
145
+
146
+ c.desc 'Number of preparation items (requires --preptype to be set).'
147
+ c.arg_name '[number]'
148
+ c.flag %i[n prepcount]
149
+
150
+ c.action do |global_options, options, args|
151
+ count = args.pop.to_i
152
+ params = if options[:file]
153
+ file = File.expand_path(options[:file])
154
+ Psych.load_file(file)
155
+ else
156
+ Specify::CLI.wrap_args(global_options, args, options.compact)
157
+ end
158
+
159
+ stub_generator = Specify::Service::StubGenerator.unwrap params
160
+
161
+ sessions << stub_generator.session
162
+
163
+ Specify::CLI.make_stubs stub_generator, count
164
+ end
165
+ end
166
+
167
+ desc 'Upload a view to the database.'
168
+ long_desc <<~HEREDOC
169
+ Uploads a view definition file (.views.xml) to the database. Viewsets can be
170
+ uploaded to either of the following levels: discipline, collection, user type,
171
+ user.
172
+ HEREDOC
173
+ arg_name '[collection] [file]'
174
+ command [:viewset, :vs] do |c|
175
+ c.desc 'Use current branch to resolve target.'
176
+ c.switch :b
177
+
178
+ c.desc 'Resolve target from branch name.'
179
+ c.arg_name '[name]'
180
+ c.flag %i[B branch]
181
+
182
+ c.desc 'Upload to collection level.'
183
+ c.switch :c
184
+
185
+ c.desc 'Upload to discipline level.'
186
+ c.switch :d
187
+
188
+ c.desc 'Upload to specific user type [name] in the collection.'
189
+ c.arg_name '[name]'
190
+ c.flag %i[t user_type]
191
+
192
+ c.desc 'Upload to specify user [name] in the collection.'
193
+ c.arg_name '[name]'
194
+ c.flag %i[u user]
195
+
196
+ c.action do |global_options, options, args|
197
+ file = File.expand_path(args.pop)
198
+ collection = args.shift
199
+ config = global_options[:db_config]
200
+ params = { host: global_options[:host],
201
+ database: global_options[:database],
202
+ collection: collection,
203
+ specify_user: global_options[:specify_user],
204
+ config: config }
205
+
206
+ view_loader = if options[:b] || options[:B]
207
+ path = File.dirname(File.expand_path(file))
208
+ Dir.chdir path unless script_dir == path
209
+ Specify::Service::ViewLoader.from_branch path: path,
210
+ name: options[:B],
211
+ config: config
212
+ else
213
+ raise 'collection required' unless collection
214
+ params[:level] = Specify::CLI.level options
215
+ Specify::Service::ViewLoader.new params
216
+ end
217
+ sessions << view_loader.session
218
+ view_loader.import file
219
+ end
220
+ end
221
+
222
+ pre do |global, command, options, args|
223
+ # Pre logic here
224
+ # Return true to proceed; false to abort and not call the
225
+ # chosen command
226
+ # Use skips_pre before a command to skip this block
227
+ # on that command only
228
+ true
229
+ end
230
+
231
+ post do |global, command, options, args|
232
+ # Post logic here
233
+ # Use skips_post before a command to skip this
234
+ # block on that command only
235
+ sessions.each(&:close)
236
+ Dir.chdir script_dir unless script_dir == Dir.pwd
237
+ end
238
+
239
+ on_error do |exception|
240
+ # Error logic here
241
+ # return false to skip default error handling
242
+
243
+ sessions.each(&:close)
244
+ Dir.chdir script_dir unless script_dir == Dir.pwd
245
+ true
246
+ end
247
+
248
+ exit run(ARGV)