unclekryon 0.4.9.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +34 -0
  3. data/Gemfile.lock +43 -0
  4. data/LICENSE +674 -0
  5. data/README.md +55 -0
  6. data/Rakefile +59 -0
  7. data/bin/unclekryon +30 -0
  8. data/iso/can_provs_terrs.yaml +54 -0
  9. data/iso/countries.yaml +3050 -0
  10. data/iso/iso.yaml +8 -0
  11. data/iso/languages.yaml +5641 -0
  12. data/iso/regions.yaml +42 -0
  13. data/iso/subregions.yaml +6 -0
  14. data/iso/usa_states.yaml +230 -0
  15. data/lib/unclekryon.rb +384 -0
  16. data/lib/unclekryon/data/album_data.rb +147 -0
  17. data/lib/unclekryon/data/artist_data.rb +109 -0
  18. data/lib/unclekryon/data/artist_data_data.rb +146 -0
  19. data/lib/unclekryon/data/aum_data.rb +75 -0
  20. data/lib/unclekryon/data/base_data.rb +79 -0
  21. data/lib/unclekryon/data/pic_data.rb +76 -0
  22. data/lib/unclekryon/data/release_data.rb +57 -0
  23. data/lib/unclekryon/data/social_data.rb +39 -0
  24. data/lib/unclekryon/data/timespan_data.rb +70 -0
  25. data/lib/unclekryon/dev_opts.rb +41 -0
  26. data/lib/unclekryon/hacker.rb +327 -0
  27. data/lib/unclekryon/iso.rb +341 -0
  28. data/lib/unclekryon/iso/base_iso.rb +196 -0
  29. data/lib/unclekryon/iso/can_prov_terr.rb +113 -0
  30. data/lib/unclekryon/iso/country.rb +133 -0
  31. data/lib/unclekryon/iso/language.rb +241 -0
  32. data/lib/unclekryon/iso/region.rb +53 -0
  33. data/lib/unclekryon/iso/subregion.rb +53 -0
  34. data/lib/unclekryon/iso/usa_state.rb +106 -0
  35. data/lib/unclekryon/jsoner.rb +124 -0
  36. data/lib/unclekryon/log.rb +111 -0
  37. data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +499 -0
  38. data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +413 -0
  39. data/lib/unclekryon/server.rb +29 -0
  40. data/lib/unclekryon/trainer.rb +231 -0
  41. data/lib/unclekryon/uploader.rb +29 -0
  42. data/lib/unclekryon/util.rb +228 -0
  43. data/lib/unclekryon/version.rb +26 -0
  44. data/unclekryon.gemspec +67 -0
  45. metadata +189 -0
data/iso/regions.yaml ADDED
@@ -0,0 +1,42 @@
1
+ ---
2
+ Regions:
3
+ Africa: !ruby/object:UncleKryon::Region
4
+ updated_on: '2018-06-11 17:35:28'
5
+ name: Africa
6
+ code: Africa
7
+ Antarctica: !ruby/object:UncleKryon::Region
8
+ updated_on: '2018-06-11 17:35:28'
9
+ name: Antarctica
10
+ code: Antarctica
11
+ Asia: !ruby/object:UncleKryon::Region
12
+ updated_on: '2018-06-11 17:35:28'
13
+ name: Asia
14
+ code: Asia
15
+ Australia: !ruby/object:UncleKryon::Region
16
+ updated_on: '2018-06-11 17:35:28'
17
+ name: Australia
18
+ code: Australia
19
+ Europe: !ruby/object:UncleKryon::Region
20
+ updated_on: '2018-06-11 17:35:28'
21
+ name: Europe
22
+ code: Europe
23
+ North America: !ruby/object:UncleKryon::Region
24
+ updated_on: '2018-06-11 17:35:28'
25
+ name: North America
26
+ code: North America
27
+ Oceania: !ruby/object:UncleKryon::Region
28
+ updated_on: '2018-06-11 17:35:28'
29
+ name: Oceania
30
+ code: Oceania
31
+ South America: !ruby/object:UncleKryon::Region
32
+ updated_on: '2018-06-11 17:35:28'
33
+ name: South America
34
+ code: South America
35
+ Western Mediterranean: !ruby/object:UncleKryon::Region
36
+ updated_on: '2018-06-11 17:35:28'
37
+ name: Western Mediterranean
38
+ code: Western Mediterranean
39
+ World: !ruby/object:UncleKryon::Region
40
+ updated_on: '2018-06-11 17:35:28'
41
+ name: World
42
+ code: World
@@ -0,0 +1,6 @@
1
+ ---
2
+ Subregions:
3
+ Pantagonia: !ruby/object:UncleKryon::Subregion
4
+ updated_on: '2019-07-26 11:11:11'
5
+ name: Pantagonia
6
+ code: Pantagonia
@@ -0,0 +1,230 @@
1
+ ---
2
+ USA States:
3
+ AK: !ruby/object:UncleKryon::UsaState
4
+ updated_on: '2018-06-11 17:31:44'
5
+ name: Alaska
6
+ code: AK
7
+ AL: !ruby/object:UncleKryon::UsaState
8
+ updated_on: '2018-06-11 17:31:44'
9
+ name: Alabama
10
+ code: AL
11
+ AR: !ruby/object:UncleKryon::UsaState
12
+ updated_on: '2018-06-11 17:31:44'
13
+ name: Arkansas
14
+ code: AR
15
+ AS: !ruby/object:UncleKryon::UsaState
16
+ updated_on: '2018-06-11 17:31:44'
17
+ name: American Samoa
18
+ code: AS
19
+ AZ: !ruby/object:UncleKryon::UsaState
20
+ updated_on: '2018-06-11 17:31:44'
21
+ name: Arizona
22
+ code: AZ
23
+ CA: !ruby/object:UncleKryon::UsaState
24
+ updated_on: '2018-06-11 17:31:44'
25
+ name: California
26
+ code: CA
27
+ CO: !ruby/object:UncleKryon::UsaState
28
+ updated_on: '2018-06-11 17:31:44'
29
+ name: Colorado
30
+ code: CO
31
+ CT: !ruby/object:UncleKryon::UsaState
32
+ updated_on: '2018-06-11 17:31:44'
33
+ name: Connecticut
34
+ code: CT
35
+ DC: !ruby/object:UncleKryon::UsaState
36
+ updated_on: '2018-06-11 17:31:44'
37
+ name: District of Columbia
38
+ code: DC
39
+ DE: !ruby/object:UncleKryon::UsaState
40
+ updated_on: '2018-06-11 17:31:44'
41
+ name: Delaware
42
+ code: DE
43
+ FL: !ruby/object:UncleKryon::UsaState
44
+ updated_on: '2018-06-11 17:31:44'
45
+ name: Florida
46
+ code: FL
47
+ GA: !ruby/object:UncleKryon::UsaState
48
+ updated_on: '2018-06-11 17:31:44'
49
+ name: Georgia
50
+ code: GA
51
+ GU: !ruby/object:UncleKryon::UsaState
52
+ updated_on: '2018-06-11 17:31:44'
53
+ name: Guam
54
+ code: GU
55
+ HI: !ruby/object:UncleKryon::UsaState
56
+ updated_on: '2018-06-11 17:31:44'
57
+ name: Hawaii
58
+ code: HI
59
+ IA: !ruby/object:UncleKryon::UsaState
60
+ updated_on: '2018-06-11 17:31:44'
61
+ name: Iowa
62
+ code: IA
63
+ ID: !ruby/object:UncleKryon::UsaState
64
+ updated_on: '2018-06-11 17:31:44'
65
+ name: Idaho
66
+ code: ID
67
+ IL: !ruby/object:UncleKryon::UsaState
68
+ updated_on: '2018-06-11 17:31:44'
69
+ name: Illinois
70
+ code: IL
71
+ IN: !ruby/object:UncleKryon::UsaState
72
+ updated_on: '2018-06-11 17:31:44'
73
+ name: Indiana
74
+ code: IN
75
+ KS: !ruby/object:UncleKryon::UsaState
76
+ updated_on: '2018-06-11 17:31:44'
77
+ name: Kansas
78
+ code: KS
79
+ KY: !ruby/object:UncleKryon::UsaState
80
+ updated_on: '2018-06-11 17:31:44'
81
+ name: Kentucky
82
+ code: KY
83
+ LA: !ruby/object:UncleKryon::UsaState
84
+ updated_on: '2018-06-11 17:31:44'
85
+ name: Louisiana
86
+ code: LA
87
+ MA: !ruby/object:UncleKryon::UsaState
88
+ updated_on: '2018-06-11 17:31:44'
89
+ name: Massachusetts
90
+ code: MA
91
+ MD: !ruby/object:UncleKryon::UsaState
92
+ updated_on: '2018-06-11 17:31:44'
93
+ name: Maryland
94
+ code: MD
95
+ ME: !ruby/object:UncleKryon::UsaState
96
+ updated_on: '2018-06-11 17:31:44'
97
+ name: Maine
98
+ code: ME
99
+ MI: !ruby/object:UncleKryon::UsaState
100
+ updated_on: '2018-06-11 17:31:44'
101
+ name: Michigan
102
+ code: MI
103
+ MN: !ruby/object:UncleKryon::UsaState
104
+ updated_on: '2018-06-11 17:31:44'
105
+ name: Minnesota
106
+ code: MN
107
+ MO: !ruby/object:UncleKryon::UsaState
108
+ updated_on: '2018-06-11 17:31:44'
109
+ name: Missouri
110
+ code: MO
111
+ MP: !ruby/object:UncleKryon::UsaState
112
+ updated_on: '2018-06-11 17:31:44'
113
+ name: Northern Mariana Islands
114
+ code: MP
115
+ MS: !ruby/object:UncleKryon::UsaState
116
+ updated_on: '2018-06-11 17:31:44'
117
+ name: Mississippi
118
+ code: MS
119
+ MT: !ruby/object:UncleKryon::UsaState
120
+ updated_on: '2018-06-11 17:31:44'
121
+ name: Montana
122
+ code: MT
123
+ NC: !ruby/object:UncleKryon::UsaState
124
+ updated_on: '2018-06-11 17:31:44'
125
+ name: North Carolina
126
+ code: NC
127
+ ND: !ruby/object:UncleKryon::UsaState
128
+ updated_on: '2018-06-11 17:31:44'
129
+ name: North Dakota
130
+ code: ND
131
+ NE: !ruby/object:UncleKryon::UsaState
132
+ updated_on: '2018-06-11 17:31:44'
133
+ name: Nebraska
134
+ code: NE
135
+ NH: !ruby/object:UncleKryon::UsaState
136
+ updated_on: '2018-06-11 17:31:44'
137
+ name: New Hampshire
138
+ code: NH
139
+ NJ: !ruby/object:UncleKryon::UsaState
140
+ updated_on: '2018-06-11 17:31:44'
141
+ name: New Jersey
142
+ code: NJ
143
+ NM: !ruby/object:UncleKryon::UsaState
144
+ updated_on: '2018-06-11 17:31:44'
145
+ name: New Mexico
146
+ code: NM
147
+ NV: !ruby/object:UncleKryon::UsaState
148
+ updated_on: '2018-06-11 17:31:44'
149
+ name: Nevada
150
+ code: NV
151
+ NY: !ruby/object:UncleKryon::UsaState
152
+ updated_on: '2018-06-11 17:31:44'
153
+ name: New York
154
+ code: NY
155
+ OH: !ruby/object:UncleKryon::UsaState
156
+ updated_on: '2018-06-11 17:31:44'
157
+ name: Ohio
158
+ code: OH
159
+ OK: !ruby/object:UncleKryon::UsaState
160
+ updated_on: '2018-06-11 17:31:44'
161
+ name: Oklahoma
162
+ code: OK
163
+ OR: !ruby/object:UncleKryon::UsaState
164
+ updated_on: '2018-06-11 17:31:44'
165
+ name: Oregon
166
+ code: OR
167
+ PA: !ruby/object:UncleKryon::UsaState
168
+ updated_on: '2018-06-11 17:31:44'
169
+ name: Pennsylvania
170
+ code: PA
171
+ PR: !ruby/object:UncleKryon::UsaState
172
+ updated_on: '2018-06-11 17:31:44'
173
+ name: Puerto Rico
174
+ code: PR
175
+ RI: !ruby/object:UncleKryon::UsaState
176
+ updated_on: '2018-06-11 17:31:44'
177
+ name: Rhode Island
178
+ code: RI
179
+ SC: !ruby/object:UncleKryon::UsaState
180
+ updated_on: '2018-06-11 17:31:44'
181
+ name: South Carolina
182
+ code: SC
183
+ SD: !ruby/object:UncleKryon::UsaState
184
+ updated_on: '2018-06-11 17:31:44'
185
+ name: South Dakota
186
+ code: SD
187
+ TN: !ruby/object:UncleKryon::UsaState
188
+ updated_on: '2018-06-11 17:31:44'
189
+ name: Tennessee
190
+ code: TN
191
+ TX: !ruby/object:UncleKryon::UsaState
192
+ updated_on: '2018-06-11 17:31:44'
193
+ name: Texas
194
+ code: TX
195
+ UM: !ruby/object:UncleKryon::UsaState
196
+ updated_on: '2018-06-11 17:31:44'
197
+ name: United States Minor Outlying Islands
198
+ code: UM
199
+ UT: !ruby/object:UncleKryon::UsaState
200
+ updated_on: '2018-06-11 17:31:44'
201
+ name: Utah
202
+ code: UT
203
+ VA: !ruby/object:UncleKryon::UsaState
204
+ updated_on: '2018-06-11 17:31:44'
205
+ name: Virginia
206
+ code: VA
207
+ VI: !ruby/object:UncleKryon::UsaState
208
+ updated_on: '2018-06-11 17:31:44'
209
+ name: Virgin Islands, U.S.
210
+ code: VI
211
+ VT: !ruby/object:UncleKryon::UsaState
212
+ updated_on: '2018-06-11 17:31:44'
213
+ name: Vermont
214
+ code: VT
215
+ WA: !ruby/object:UncleKryon::UsaState
216
+ updated_on: '2018-06-11 17:31:44'
217
+ name: Washington
218
+ code: WA
219
+ WI: !ruby/object:UncleKryon::UsaState
220
+ updated_on: '2018-06-11 17:31:44'
221
+ name: Wisconsin
222
+ code: WI
223
+ WV: !ruby/object:UncleKryon::UsaState
224
+ updated_on: '2018-06-11 17:31:44'
225
+ name: West Virginia
226
+ code: WV
227
+ WY: !ruby/object:UncleKryon::UsaState
228
+ updated_on: '2018-06-11 17:31:44'
229
+ name: Wyoming
230
+ code: WY
data/lib/unclekryon.rb ADDED
@@ -0,0 +1,384 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of UncleKryon-server.
7
+ # Copyright (c) 2017-2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # UncleKryon-server is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # UncleKryon-server is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'rubygems'
25
+ require 'bundler/setup'
26
+
27
+ require 'optparse'
28
+
29
+ require 'unclekryon/dev_opts'
30
+ require 'unclekryon/hacker'
31
+ require 'unclekryon/iso'
32
+ require 'unclekryon/jsoner'
33
+ require 'unclekryon/log'
34
+ require 'unclekryon/server'
35
+ require 'unclekryon/trainer'
36
+ require 'unclekryon/uploader'
37
+ require 'unclekryon/util'
38
+ require 'unclekryon/version'
39
+
40
+ require 'unclekryon/data/album_data'
41
+ require 'unclekryon/data/artist_data'
42
+ require 'unclekryon/data/artist_data_data'
43
+ require 'unclekryon/data/aum_data'
44
+ require 'unclekryon/data/base_data'
45
+ require 'unclekryon/data/pic_data'
46
+ require 'unclekryon/data/release_data'
47
+ require 'unclekryon/data/social_data'
48
+ require 'unclekryon/data/timespan_data'
49
+
50
+ require 'unclekryon/iso/base_iso'
51
+ require 'unclekryon/iso/can_prov_terr'
52
+ require 'unclekryon/iso/country'
53
+ require 'unclekryon/iso/language'
54
+ require 'unclekryon/iso/region'
55
+ require 'unclekryon/iso/subregion'
56
+ require 'unclekryon/iso/usa_state'
57
+
58
+ require 'unclekryon/parsers/kryon_aum_year_album_parser'
59
+ require 'unclekryon/parsers/kryon_aum_year_parser'
60
+
61
+ module UncleKryon
62
+ class Main
63
+ OPT_HELP_UPDATED_ON = %Q^Change all "updated_*on" datetimes to <datetime> (e.g., #{Util.format_datetime(DateTime.now())})^
64
+
65
+ include Logging
66
+
67
+ def initialize(args)
68
+ @args = args
69
+ @cmd = nil
70
+ @did_cmd = false
71
+ @options = {}
72
+ @parsers = []
73
+ end
74
+
75
+ def run()
76
+ parser = OptionParser.new do |op|
77
+ op.program_name = 'unclekryon'
78
+ op.version = VERSION
79
+
80
+ op.banner = <<~EOS
81
+ Usage: #{op.program_name} [options] <sub_cmd> [options] <sub_cmd>...
82
+
83
+ Sub Commands:
84
+ hax kryon aum year
85
+ iso list
86
+
87
+ Options:
88
+ EOS
89
+
90
+ op.on('-d','--dev','Raise errors on missing data, etc.') do
91
+ DevOpts.instance.dev = true
92
+ end
93
+ op.on('-n','--no-clobber','No clobbering of files, dry run; prints to console') do
94
+ @options[:no_clobber] = true
95
+ end
96
+ op.on('-h','--help','Print help to console')
97
+ op.on('-t','--test','Fill in training data with random values, etc. for fast testing') do
98
+ DevOpts.instance.test = true
99
+ end
100
+ op.on('-v','--version','Print version to console')
101
+ end
102
+
103
+ @parsers.push(parser)
104
+ parser.order!(@args,into: @options)
105
+
106
+ if shift_args()
107
+ parse_hax_cmd()
108
+ parse_iso_cmd()
109
+ end
110
+
111
+ if !@did_cmd
112
+ if @options[:version]
113
+ puts "#{parser.program_name} v#{parser.version}"
114
+ else
115
+ @parsers.each do |p|
116
+ puts p
117
+ puts
118
+ end
119
+
120
+ s = <<~EOS
121
+ Examples:
122
+ | # To view all of the options for the sub commands:
123
+ | $ #{parser.program_name} hax kryon aum year
124
+ | $ #{parser.program_name} iso list
125
+ |
126
+ | <hax>:
127
+ | # Train the data 1st before haxing (if there is no training data)
128
+ | $ #{parser.program_name} -d hax -t kryon aum year -t 2017 -s
129
+ | $ #{parser.program_name} -d hax -t kryon aum year -t 2017 -a 2.2
130
+ |
131
+ | # Hax the data (even though --title is not required, it is recommended)
132
+ | $ #{parser.program_name} -d hax kryon aum year -t 2017 -s
133
+ | $ #{parser.program_name} -d hax kryon aum year -t 2017 -a 10.9
134
+ | $ #{parser.program_name} -d hax kryon aum year -a 2017.9.29
135
+ |
136
+ | # Hax the 2nd "6.4" album (if there are 2)
137
+ | $ #{parser.program_name} -d hax kryon aum year -t 2017 -a 6.4:2
138
+ |
139
+ | <iso>:
140
+ | $ #{parser.program_name} -n iso -u '2019-04-16 11:11:00'
141
+ | $ #{parser.program_name} iso list -r
142
+ EOS
143
+ puts s.gsub(/^\|/,'')
144
+ end
145
+ end
146
+ end
147
+
148
+ def shift_args()
149
+ return !@args.nil?() && !(@cmd = @args.shift()).nil?()
150
+ end
151
+
152
+ def parse_hax_cmd()
153
+ return if !cmd?('hax')
154
+
155
+ parser = OptionParser.new do |op|
156
+ op.banner = '<hax> options:'
157
+
158
+ op.on('-d','--dir <dir>',"Directory to save the hax data to (default: #{Hacker::HAX_DIRNAME})") do |dir|
159
+ @options[:hax_dirname] = dir
160
+ end
161
+ op.on('-t','--train','Train the data using machine learning')
162
+ op.on('-i','--train-dir <dir>',"Directory to save the training data to (default: #{Hacker::TRAIN_DIRNAME})") do |dir|
163
+ @options[:train_dirname] = dir
164
+ end
165
+ op.on('-u','--updated-on <datetime>',OPT_HELP_UPDATED_ON) do |datetime|
166
+ @options[:updated_on] = datetime
167
+ end
168
+ end
169
+
170
+ @parsers.push(parser)
171
+ parser.order!(@args,into: @options)
172
+
173
+ if do_cmd?()
174
+ if @options[:updated_on]
175
+ hax_dirname = @options[:hax_dirname] ? @options[:hax_dirname] : Hacker::HAX_DIRNAME
176
+ gsub_updated_on(hax_dirname,@options[:updated_on])
177
+
178
+ @did_cmd = true
179
+ end
180
+ end
181
+
182
+ if shift_args()
183
+ parse_hax_kryon_cmd()
184
+ end
185
+ end
186
+
187
+ def parse_hax_kryon_cmd()
188
+ return if !cmd?('kryon')
189
+
190
+ parser = OptionParser.new do |op|
191
+ op.banner = '<kryon> options:'
192
+
193
+ op.on('-f','--file <file>',"File to save the hax data to (default: #{Hacker::HAX_KRYON_FILENAME})") do |file|
194
+ @options[:hax_kryon_filename] = file
195
+ end
196
+ op.on('-t','--train-file <file>',"File to save the training data to (default: #{Hacker::TRAIN_KRYON_FILENAME})") do |file|
197
+ @options[:train_kryon_filename] = file
198
+ end
199
+ end
200
+
201
+ @parsers.push(parser)
202
+ parser.order!(@args,into: @options)
203
+
204
+ if shift_args()
205
+ parse_hax_kryon_aum_cmd()
206
+ end
207
+ end
208
+
209
+ def parse_hax_kryon_aum_cmd()
210
+ return if !cmd?('aum')
211
+
212
+ if shift_args()
213
+ parse_hax_kryon_aum_year_cmd()
214
+ end
215
+ end
216
+
217
+ def parse_hax_kryon_aum_year_cmd()
218
+ return if !cmd?('year')
219
+
220
+ parser = OptionParser.new do |op|
221
+ op.banner = '<year> options:'
222
+
223
+ op.on('-t','--title <title>','Title of year release to hack (e.g., 2017)')
224
+ op.on('-a','--album <album>','Album to hack (e.g., 2017.12.25, 1.10, 6.4:2)')
225
+ op.on('-s','--albums','Hack all albums')
226
+ op.on('-b','--begin-album <album>','Hack all albums starting from <album>') do |begin_album|
227
+ @options[:albums] = true
228
+ @options[:begin_album] = begin_album
229
+ end
230
+ end
231
+
232
+ @parsers.push(parser)
233
+ parser.order!(@args,into: @options)
234
+
235
+ if do_cmd?()
236
+ log_opts()
237
+
238
+ hacker = Hacker.new(@options)
239
+
240
+ if @options[:train]
241
+ if @options[:album]
242
+ hacker.train_kryon_aum_year_album(@options[:album],@options[:title])
243
+ @did_cmd = true
244
+ elsif @options[:title]
245
+ if @options[:albums]
246
+ hacker.train_kryon_aum_year_albums(@options[:title],@options[:begin_album])
247
+ else
248
+ hacker.train_kryon_aum_year(@options[:title])
249
+ end
250
+
251
+ @did_cmd = true
252
+ end
253
+ else
254
+ if @options[:album]
255
+ hacker.parse_kryon_aum_year_album(@options[:album],@options[:title])
256
+ @did_cmd = true
257
+ elsif @options[:title]
258
+ if @options[:albums]
259
+ hacker.parse_kryon_aum_year_albums(@options[:title],@options[:begin_album])
260
+ else
261
+ hacker.parse_kryon_aum_year(@options[:title])
262
+ end
263
+
264
+ @did_cmd = true
265
+ end
266
+ end
267
+ end
268
+ end
269
+
270
+ def parse_iso_cmd()
271
+ return if !cmd?('iso')
272
+
273
+ parser = OptionParser.new do |op|
274
+ op.banner = '<iso> options:'
275
+
276
+ op.on('-d','--dir <dir>',"Directory to read/write ISO data (default: #{BaseIsos::DEFAULT_DIR})") do |dir|
277
+ @options[:iso_dirname] = dir
278
+ end
279
+ op.on('-u','--updated-on <datetime>',OPT_HELP_UPDATED_ON) do |datetime|
280
+ @options[:updated_on] = datetime
281
+ end
282
+ end
283
+
284
+ @parsers.push(parser)
285
+ parser.order!(@args,into: @options)
286
+
287
+ if do_cmd?()
288
+ if @options[:updated_on]
289
+ iso_dirname = @options[:iso_dirname] ? @options[:iso_dirname] : BaseIsos::DEFAULT_DIR
290
+ gsub_updated_on(iso_dirname,@options[:updated_on])
291
+
292
+ @did_cmd = true
293
+ end
294
+ end
295
+
296
+ if shift_args()
297
+ parse_iso_list_cmd()
298
+ end
299
+ end
300
+
301
+ def parse_iso_list_cmd()
302
+ return if !cmd?('list')
303
+
304
+ parser = OptionParser.new do |op|
305
+ op.banner = '<list> options:'
306
+
307
+ op.on('-c','--canada','List Canadian provinces and territories')
308
+ op.on('-u','--usa','List USA states')
309
+ op.on('-o','--country','List countries')
310
+ op.on('-l','--language','List languages')
311
+ op.on('-r','--region','List regions (i.e., continents, etc.)')
312
+ op.on('-s','--subregion','List subregions')
313
+ end
314
+
315
+ @parsers.push(parser)
316
+ parser.order!(@args,into: @options)
317
+
318
+ if do_cmd?()
319
+ if @options[:canada]
320
+ puts Iso.can_provs_terrs
321
+ @did_cmd = true
322
+ elsif @options[:usa]
323
+ puts Iso.usa_states
324
+ @did_cmd = true
325
+ elsif @options[:country]
326
+ puts Iso.countries
327
+ @did_cmd = true
328
+ elsif @options[:language]
329
+ puts Iso.languages
330
+ @did_cmd = true
331
+ elsif @options[:region]
332
+ puts Iso.regions
333
+ @did_cmd = true
334
+ elsif @options[:subregion]
335
+ puts Iso.subregions
336
+ @did_cmd = true
337
+ end
338
+ end
339
+ end
340
+
341
+ def gsub_updated_on(dirname,updated_on)
342
+ updated_on = Util.parse_datetime_s(updated_on) # Raise errors on bad format
343
+ updated_on = Util.format_datetime(updated_on)
344
+
345
+ Dir.glob(File.join(dirname,'*.yaml')) do |filepath|
346
+ lines = IO.readlines(filepath)
347
+ update_count = 0
348
+
349
+ lines.each_with_index do |line,i|
350
+ if line =~ /\A\s*updated\_.*on\:.*\Z/i
351
+ line = line.split(':')[0] << ": '#{updated_on}'"
352
+ lines[i] = line
353
+ update_count += 1
354
+ end
355
+ end
356
+
357
+ if !@options[:no_clobber]
358
+ File.open(filepath,'w') do |file|
359
+ file.puts lines
360
+ end
361
+ end
362
+
363
+ puts %Q^"#{filepath}" updated_on: #{update_count}^
364
+ end
365
+ end
366
+
367
+ def log_opts()
368
+ log.info("Using options#{@options}")
369
+ end
370
+
371
+ def cmd?(cmd)
372
+ return !@did_cmd && !@cmd.nil?() && @cmd.match?(/\A[[:space:]]*#{Regexp.escape(cmd)}[[:space:]]*\z/i)
373
+ end
374
+
375
+ def do_cmd?()
376
+ return !@options[:help] && !@options[:version]
377
+ end
378
+ end
379
+ end
380
+
381
+ if $0 == __FILE__
382
+ main = UncleKryon::Main.new(ARGV)
383
+ main.run()
384
+ end