sportdb 1.6.17 → 1.6.18

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,7 +11,88 @@
11
11
 
12
12
  ## Usage
13
13
 
14
- TBD
14
+ The sportdb gem lets you load fixtures in plain text into your sports database (also includes schema & models for easy reuse)
15
+
16
+ ~~~
17
+ SYNOPSIS
18
+ sportdb [global options] command [command options] [arguments...]
19
+
20
+ VERSION
21
+ 1.6
22
+
23
+ GLOBAL OPTIONS
24
+ -d, --dbpath=PATH - Database path (default: .)
25
+ -n, --dbname=NAME - Database name (default: sport.db)
26
+ --verbose - (Debug) Show debug messages
27
+ --version - Show version
28
+
29
+ COMMANDS
30
+ create - Create DB schema
31
+ setup, s - Create DB schema 'n' load all world and sports data
32
+ update, up, u - Update all sports data
33
+ load, l - Load sports fixtures
34
+ logs - Show logs
35
+ props - Show props
36
+ stats - Show stats
37
+ test - (Debug) Test command suite
38
+ help - Shows a list of commands or help for one command
39
+ ~~~
40
+
41
+
42
+ ### `setup` Command
43
+
44
+ ~~~
45
+ NAME
46
+ setup - Create DB schema 'n' load all world and sports data
47
+
48
+ SYNOPSIS
49
+ sportdb [global options] setup [command options] NAME
50
+
51
+ COMMAND OPTIONS
52
+ -i, --include=PATH - Sports data path (default: .)
53
+ --worldinclude=PATH - World data path (default: none)
54
+
55
+ EXAMPLES
56
+ sportdb setup --include ./at-austria --worldinclude ./world.db
57
+ sportdb setup 2013_14 --include ./at-austria --worldinclude ./world.db
58
+ ~~~
59
+
60
+
61
+ ### `update` Command
62
+
63
+ ~~~
64
+ NAME
65
+ update - Update all sports data
66
+
67
+ SYNOPSIS
68
+ sportdb [global options] update [command options] NAME
69
+
70
+ COMMAND OPTIONS
71
+ --delete - Delete all sports data records
72
+ -i, --include=PATH - Sports data path (default: .)
73
+
74
+ EXAMPLES
75
+ sportdb update --include ./at-austria
76
+ sportdb update --include ./at-austria --delete
77
+ sportdb update 2013_14 --include ./at-austria --delete
78
+ ~~~
79
+
80
+ ### `load` Command
81
+
82
+ ~~~
83
+ NAME
84
+ load - Load sports fixtures
85
+
86
+ SYNOPSIS
87
+ sportdb [global options] load [command options] NAME
88
+
89
+ COMMAND OPTIONS
90
+ --delete - Delete all sports data records
91
+
92
+ EXAMPLES
93
+ sportdb load --include ./at-austria 2013_14/bl
94
+ sportdb load --include ./at-austria 2013_14/bl 2013_14/cup
95
+ ~~~
15
96
 
16
97
 
17
98
  ## Install
@@ -21,6 +102,20 @@ Just install the gem:
21
102
  $ gem install sportdb
22
103
 
23
104
 
105
+ ## Free Open Public Domain Datasets
106
+
107
+ - [`football.db`](https://github.com/openfootball) - free open public domain football (soccer) data for use in any (programming) language
108
+ - [`formula1.db`](https://github.com/geraldb/formula1.db) - free open public domain Formula 1/Formula One data for use in any (programming) language
109
+ - [`sport.db`](https://github.com/geraldb/sport.db) - free open public domain sports data for use in any (programming) language
110
+ - [`ski.db`](https://github.com/geraldb/ski.db) - free open public domain Ski Alpin/Alpine Ski data for use in any (programming) language
111
+
112
+
113
+ ## Questions? Comments?
114
+
115
+ Send them along to the
116
+ [Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
117
+ Thanks!
118
+
24
119
  ## License
25
120
 
26
121
  The `sportdb` scripts are dedicated to the public domain.
data/Rakefile CHANGED
@@ -29,7 +29,7 @@ Hoe.spec 'sportdb' do
29
29
  # - textutils
30
30
 
31
31
  ## 3rd party
32
- ['commander', '~> 4.1.3'] # remove? -- already included as dep in worlddb
32
+ ['gli', '>= 2.5.6']
33
33
 
34
34
  ## ['activerecord', '~> 3.2'], # NB: will include activesupport,etc.
35
35
  ### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
@@ -9,26 +9,24 @@
9
9
  # --include ../../github/football.db
10
10
 
11
11
 
12
- require 'commander/import'
12
+ require 'gli'
13
+
14
+ include GLI::App
13
15
 
14
16
  # our own code / additional for cli only
15
17
 
16
18
  require 'logutils/db'
17
19
  require 'sportdb/cli/opts'
20
+
21
+
22
+ program_desc 'sport.db command line tool'
18
23
 
19
- LogUtils::Logger.root.level = :info # set logging level to info
20
-
21
- program :name, 'sportdb'
22
- program :version, SportDb::VERSION
23
- program :description, "sport.db command line tool, version #{SportDb::VERSION}"
24
-
24
+ version SportDb::VERSION
25
25
 
26
- # default_command :help
27
- default_command :load
28
26
 
29
- program :help_formatter, Commander::HelpFormatter::TerminalCompact
27
+ LogUtils::Logger.root.level = :info # set logging level to info
28
+ logger = LogUtils::Logger.root
30
29
 
31
- ## program :help, 'Examples', 'yada yada -try multi line later'
32
30
 
33
31
  =begin
34
32
  ### add to help use new sections
@@ -47,18 +45,28 @@ Further information:
47
45
 
48
46
 
49
47
  ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
50
- myopts = SportDb::Opts.new
48
+ opts = SportDb::Opts.new
51
49
 
52
50
  ### global option (required)
53
51
  ## todo: add check that path is valid?? possible?
54
52
 
55
- global_option '-i', '--include PATH', String, "Data path (default is #{myopts.data_path})"
56
- global_option '-d', '--dbpath PATH', String, "Database path (default is #{myopts.db_path})"
57
- global_option '-n', '--dbname NAME', String, "Database name (datault is #{myopts.db_name})"
58
53
 
59
- global_option '-q', '--quiet', "Only show warnings, errors and fatal messages"
60
- ### todo/fix: just want --debug/--verbose flag (no single letter option wanted) - fix
61
- global_option '-w', '--verbose', "Show debug messages"
54
+ desc 'Database path'
55
+ arg_name 'PATH'
56
+ default_value opts.db_path
57
+ flag [:d, :dbpath]
58
+
59
+ desc 'Database name'
60
+ arg_name 'NAME'
61
+ default_value opts.db_name
62
+ flag [:n, :dbname]
63
+
64
+ desc '(Debug) Show debug messages'
65
+ switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
66
+
67
+ desc 'Only show warnings, errors and fatal messages'
68
+ switch [:q, :quiet], negatable: false
69
+
62
70
 
63
71
 
64
72
  def connect_to_db( options )
@@ -80,16 +88,11 @@ def connect_to_db( options )
80
88
  end
81
89
 
82
90
 
83
- command :create do |c|
84
- c.syntax = 'sportdb create [options]'
85
- c.description = 'Create DB schema'
86
- c.action do |args, options|
91
+ desc 'Create DB schema'
92
+ command [:create] do |c|
93
+ c.action do |g,o,args|
87
94
 
88
- LogUtils::Logger.root.level = :warn if options.quiet.present?
89
- LogUtils::Logger.root.level = :debug if options.verbose.present?
90
-
91
- myopts.merge_commander_options!( options.__hash__ )
92
- connect_to_db( myopts )
95
+ connect_to_db( opts )
93
96
 
94
97
  LogDb.create
95
98
  WorldDb.create
@@ -98,108 +101,94 @@ command :create do |c|
98
101
  end # action
99
102
  end # command create
100
103
 
101
- command :setup do |c|
102
- c.syntax = 'sportdb setup [options]'
103
- c.description = "Create DB schema 'n' load all data"
104
104
 
105
- c.option '--world', 'Populate world tables'
106
- ## todo: use --world-include - how? find better name?
107
- c.option '--worldinclude PATH', String, 'World data path'
105
+ desc "Create DB schema 'n' load all world and sports data"
106
+ arg_name 'NAME' # optional setup profile name
107
+ command [:setup,:s] do |c|
108
108
 
109
- c.option '--sport', 'Populate sport tables'
110
- c.option '--delete', 'Delete all records'
109
+ c.desc 'Sports data path'
110
+ c.arg_name 'PATH'
111
+ c.default_value opts.data_path
112
+ c.flag [:i,:include]
111
113
 
112
- c.action do |args, options|
114
+ c.desc 'World data path'
115
+ c.arg_name 'PATH'
116
+ c.flag [:worldinclude] ## todo: use --world-include - how? find better name? add :'world-include' ???
113
117
 
114
- LogUtils::Logger.root.level = :warn if options.quiet.present?
115
- LogUtils::Logger.root.level = :debug if options.verbose.present?
118
+ c.action do |g,o,args|
116
119
 
117
- myopts.merge_commander_options!( options.__hash__ )
118
- connect_to_db( myopts )
120
+ connect_to_db( opts )
119
121
 
120
122
  ## todo: document optional setup profile arg (defaults to all)
121
123
  setup = args[0] || 'all'
122
124
 
123
- if options.world.present? || options.sport.present?
124
-
125
- ## todo: check order for reference integrity
126
- # not really possible to delete world data if sport data is present
127
- # delete sport first
128
-
129
- if options.delete.present?
130
- SportDb.delete! if options.sport.present?
131
- WorldDb.delete! if options.world.present?
132
- end
133
-
134
- if options.world.present?
135
- WorldDb.read_all( myopts.world_data_path )
136
- end
137
-
138
- if options.sport.present?
139
- SportDb.read_setup( "setups/#{setup}", myopts.data_path )
140
- end
141
-
142
- else # assume "plain" regular setup
143
- LogDb.create
144
- WorldDb.create
145
- SportDb.create
125
+ LogDb.create
126
+ WorldDb.create
127
+ SportDb.create
146
128
 
147
- WorldDb.read_all( myopts.world_data_path )
148
- SportDb.read_setup( "setups/#{setup}", myopts.data_path )
149
- end
129
+ WorldDb.read_all( opts.world_data_path )
130
+ SportDb.read_setup( "setups/#{setup}", opts.data_path )
150
131
  puts 'Done.'
151
132
  end # action
152
133
  end # command setup
153
134
 
154
- command :load do |c|
155
- ## todo: how to specify many fixutes <>... ??? in syntax
156
- c.syntax = 'sportdb load [options] FIXTURE...'
157
- c.description = 'Load fixtures'
158
135
 
159
- c.option '-e', '--event KEY', String, 'Event to load'
160
- c.option '--delete', 'Delete all records'
136
+ desc 'Update all sports data'
137
+ arg_name 'NAME' # optional setup profile name
138
+ command [:update,:up,:u] do |c|
139
+
140
+ c.desc 'Sports data path'
141
+ c.arg_name 'PATH'
142
+ c.default_value opts.data_path
143
+ c.flag [:i,:include]
144
+
145
+ c.desc 'Delete all sports data records'
146
+ c.switch [:delete], negatable: false
147
+
148
+ c.action do |g,o,args|
149
+
150
+ connect_to_db( opts )
151
+
152
+ ## todo: document optional setup profile arg (defaults to all)
153
+ setup = args[0] || 'all'
154
+
155
+ SportDb.delete! if o[:delete].present?
156
+
157
+ SportDb.read_setup( "setups/#{setup}", opts.data_path )
158
+ puts 'Done.'
159
+ end # action
160
+ end # command setup
161
161
 
162
- c.action do |args, options|
163
162
 
164
- LogUtils::Logger.root.level = :warn if options.quiet.present?
165
- LogUtils::Logger.root.level = :debug if options.verbose.present?
163
+ desc 'Load sports fixtures'
164
+ arg_name 'NAME' # multiple fixture names - todo/fix: use multiple option
165
+ command [:load, :l] do |c|
166
166
 
167
- myopts.merge_commander_options!( options.__hash__ )
168
- connect_to_db( myopts )
167
+ c.desc 'Delete all sports data records'
168
+ c.switch [:delete], negatable: false
169
+
170
+ c.action do |g,o,args|
171
+
172
+ connect_to_db( opts )
169
173
 
170
- SportDb.delete! if options.delete.present?
174
+ SportDb.delete! if o[:delete].present?
171
175
 
172
- reader = SportDb::Reader.new( myopts.data_path )
176
+ reader = SportDb::Reader.new( opts.data_path )
173
177
 
174
178
  args.each do |arg|
175
179
  name = arg # File.basename( arg, '.*' )
176
-
177
- if myopts.event.present?
178
- ## fix: rename to load_event_fixtures_w... or similar
179
- reader.load_fixtures( myopts.event, name )
180
- else
181
- ## fix> add a convenience method for loading single fixture
182
- ary = []
183
- ary << name
184
- reader.load( ary )
185
- end
180
+ reader.load( name )
186
181
  end # each arg
187
182
 
188
183
  puts 'Done.'
189
184
  end
190
185
  end # command load
191
186
 
192
-
187
+ desc 'Show logs'
193
188
  command :logs do |c|
194
- c.syntax = 'sportdb logs [options]'
195
- c.description = 'Show logs'
196
- c.action do |args, options|
189
+ c.action do |g,o,args|
197
190
 
198
- LogUtils::Logger.root.level = :warn if options.quiet.present?
199
- LogUtils::Logger.root.level = :debug if options.verbose.present?
200
-
201
- myopts.merge_commander_options!( options.__hash__ )
202
- connect_to_db( myopts )
191
+ connect_to_db( opts )
203
192
 
204
193
  LogDb::Models::Log.all.each do |log|
205
194
  puts "[#{log.level}] -- #{log.msg}"
@@ -210,16 +199,11 @@ command :logs do |c|
210
199
  end
211
200
 
212
201
 
202
+ desc 'Show stats'
213
203
  command :stats do |c|
214
- c.syntax = 'sportdb stats [options]'
215
- c.description = 'Show stats'
216
- c.action do |args, options|
217
-
218
- LogUtils::Logger.root.level = :warn if options.quiet.present?
219
- LogUtils::Logger.root.level = :debug if options.verbose.present?
204
+ c.action do |g,o,args|
220
205
 
221
- myopts.merge_commander_options!( options.__hash__ )
222
- connect_to_db( myopts )
206
+ connect_to_db( opts )
223
207
 
224
208
  SportDb.tables
225
209
 
@@ -228,16 +212,11 @@ command :stats do |c|
228
212
  end
229
213
 
230
214
 
215
+ desc 'Show props'
231
216
  command :props do |c|
232
- c.syntax = 'sportdb props [options]'
233
- c.description = 'Show props'
234
- c.action do |args, options|
235
-
236
- LogUtils::Logger.root.level = :warn if options.quiet.present?
237
- LogUtils::Logger.root.level = :debug if options.verbose.present?
217
+ c.action do |g,o,args|
238
218
 
239
- myopts.merge_commander_options!( options.__hash__ )
240
- connect_to_db( myopts )
219
+ connect_to_db( opts )
241
220
 
242
221
  SportDb.props
243
222
 
@@ -246,21 +225,17 @@ command :props do |c|
246
225
  end
247
226
 
248
227
 
228
+ desc '(Debug) Test command suite'
249
229
  command :test do |c|
250
- c.syntax = 'sportdb test [options]'
251
- c.description = 'Debug/test command suite'
252
- c.action do |args, options|
253
-
254
- LogUtils::Logger.root.level = :warn if options.quiet.present?
255
- LogUtils::Logger.root.level = :debug if options.verbose.present?
230
+ c.action do |g,o,args|
256
231
 
257
232
  puts "hello from test command"
258
233
  puts "args (#{args.class.name}):"
259
234
  pp args
260
- puts "options:"
261
- pp options
262
- puts "options.__hash__:"
263
- pp options.__hash__
235
+ puts "o (#{o.class.name}):"
236
+ pp o
237
+ puts "g (#{g.class.name}):"
238
+ pp g
264
239
 
265
240
  LogUtils::Logger.root.debug 'test debug msg'
266
241
  LogUtils::Logger.root.info 'test info msg'
@@ -269,3 +244,39 @@ command :test do |c|
269
244
  puts 'Done.'
270
245
  end
271
246
  end
247
+
248
+
249
+
250
+ pre do |g,c,o,args|
251
+ opts.merge_gli_options!( g )
252
+ opts.merge_gli_options!( o )
253
+
254
+ puts SportDb.banner
255
+
256
+ if opts.verbose?
257
+ LogUtils::Logger.root.level = :debug
258
+ end
259
+
260
+ logger.debug "Executing #{c.name}"
261
+ true
262
+ end
263
+
264
+ post do |global,c,o,args|
265
+ logger.debug "Executed #{c.name}"
266
+ true
267
+ end
268
+
269
+
270
+ on_error do |e|
271
+ puts
272
+ puts "*** error: #{e.message}"
273
+
274
+ if opts.verbose?
275
+ puts e.backtrace
276
+ end
277
+
278
+ false # skip default error handling
279
+ end
280
+
281
+
282
+ exit run(ARGV)
@@ -2,33 +2,34 @@ module SportDb
2
2
 
3
3
  class Opts
4
4
 
5
- def merge_commander_options!( options = {} )
5
+ def merge_gli_options!( options = {} )
6
6
  @db_path = options[:dbpath] if options[:dbpath].present?
7
7
  @db_name = options[:dbname] if options[:dbname].present?
8
8
 
9
- @data_path = options[:include] if options[:include].present?
10
- @event = options[:event] if options[:event].present?
9
+ @verbose = true if options[:verbose] == true
11
10
 
11
+ @data_path = options[:include] if options[:include].present?
12
12
  @world_data_path = options[:worldinclude] if options[:worldinclude].present?
13
13
  end
14
14
 
15
15
 
16
- def db_path
17
- @db_path || '.'
16
+ def verbose=(boolean) # add: alias for debug ??
17
+ @verbose = boolean
18
18
  end
19
19
 
20
- def db_name
21
- @db_name || 'sport.db'
20
+ def verbose?
21
+ return false if @verbose.nil? # default verbose/debug flag is false
22
+ @verbose == true
22
23
  end
23
24
 
24
- def event=(value)
25
- @event = value
26
- end
27
25
 
28
- def event
29
- @event # NB: option has no default; return nil ## || '.'
26
+ def db_path
27
+ @db_path || '.'
30
28
  end
31
29
 
30
+ def db_name
31
+ @db_name || 'sport.db'
32
+ end
32
33
 
33
34
  def data_path=(value)
34
35
  @data_path = value
@@ -68,7 +68,13 @@ class Reader
68
68
  load_records( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
69
69
  elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
70
70
  load_seasons( name )
71
- elsif name =~ /^leagues/
71
+ elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
72
+ # auto-add country code (from folder structure) for country-specific leagues
73
+ # e.g. at/leagues
74
+ country = Country.find_by_key!( country_key )
75
+ load_leagues( name, club: true, country_id: country.id )
76
+ end
77
+ elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
72
78
  if name =~ /club/
73
79
  # e.g. leagues_club
74
80
  load_leagues( name, club: true )
@@ -76,19 +82,13 @@ class Reader
76
82
  # e.g. leagues
77
83
  load_leagues( name )
78
84
  end
79
- elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
80
- # auto-add country code (from folder structure) for country-specific leagues
81
- # e.g. at/leagues
82
- country = Country.find_by_key!( country_key )
83
- load_leagues( name, club: true, country_id: country.id )
84
- end
85
85
  elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
86
86
  # auto-add country code (from folder structure) for country-specific teams
87
87
  # e.g. at/teams at/teams.2 de/teams etc.
88
88
  country = Country.find_by_key!( country_key )
89
89
  load_teams( name, club: true, country_id: country.id )
90
90
  end
91
- elsif name =~ /\/teams/
91
+ elsif name =~ /(?:^|\/)teams/
92
92
  if name =~ /club/
93
93
  # club teams (many countries)
94
94
  # e.g. club/europe/teams
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.17'
3
+ VERSION = '1.6.18'
4
4
  end
5
5
 
6
6
  ###########################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.17
4
+ version: 1.6.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-25 00:00:00.000000000Z
12
+ date: 2013-06-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &16188720 !ruby/object:Gem::Requirement
16
+ requirement: &13812420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16188720
24
+ version_requirements: *13812420
25
25
  - !ruby/object:Gem::Dependency
26
- name: commander
27
- requirement: &16188324 !ruby/object:Gem::Requirement
26
+ name: gli
27
+ requirement: &13812156 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ~>
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 4.1.3
32
+ version: 2.5.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16188324
35
+ version_requirements: *13812156
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &16187760 !ruby/object:Gem::Requirement
38
+ requirement: &13811748 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '4.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16187760
46
+ version_requirements: *13811748
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &16187424 !ruby/object:Gem::Requirement
49
+ requirement: &13811340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.6'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16187424
57
+ version_requirements: *13811340
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables: