fbtok 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/Manifest.txt +2 -1
- data/Rakefile +5 -2
- data/bin/fbt +167 -0
- data/bin/fbtok +133 -1
- data/bin/fbx +149 -0
- data/lib/fbtok.rb +6 -2
- metadata +8 -5
- data/lib/fbtok/fbtok.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82c6131cf108aae7a0d7284bba488be307c1cb81c099dad53960d500a8710483
|
4
|
+
data.tar.gz: ae5c2366e89ac5ef1a25567a0c328aafc12ddc21f826e43c927027dfa48e5f47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e43061028eb9eae6a3f0cc50eccdf111f41270c89189fc50e5a9f4c56da976ed3b858d2201b234367009dbf036c17747a4e53952eaab3f500787fb1b695e023a
|
7
|
+
data.tar.gz: 18a70dbed909e896b47ddfe63ea98d1ed5ed3fe37a9dee15418e713790465ccc2a4f3033110a32916924dcf1fab9eb5132e411c37792c37abcf8b54ed301b3f9
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
|
|
2
2
|
|
3
3
|
|
4
4
|
Hoe.spec 'fbtok' do
|
5
|
-
self.version = '0.0
|
5
|
+
self.version = '0.1.0'
|
6
6
|
|
7
7
|
self.summary = "fbtok - football.txt lint tools incl. tokenizer, parser & more"
|
8
8
|
self.description = summary
|
@@ -19,7 +19,10 @@ Hoe.spec 'fbtok' do
|
|
19
19
|
self.licenses = ['Public Domain']
|
20
20
|
|
21
21
|
self.extra_deps = [
|
22
|
-
|
22
|
+
# ['sportdb-parser', '>= 0.2.2'],
|
23
|
+
# ['sportdb-structs', '>= 0.5.0'],
|
24
|
+
# ['logutils', '>= 0.6.1'],
|
25
|
+
['sportdb-quick', '>= 0.3.0'],
|
23
26
|
]
|
24
27
|
|
25
28
|
self.spec_extras = {
|
data/bin/fbt
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib bin/fbt
|
5
|
+
## -or-
|
6
|
+
## ruby -I ../parser/lib -I ./lib bin/fbt
|
7
|
+
## -or-
|
8
|
+
## ruby -I ../parser/lib -I ../sportdb-structs/lib -I ./lib bin/fbt
|
9
|
+
|
10
|
+
|
11
|
+
## our own code
|
12
|
+
require 'fbtok'
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
## read textfile
|
17
|
+
## and dump tokens
|
18
|
+
##
|
19
|
+
## fbt ../openfootball/.../euro.txt
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
args = ARGV
|
25
|
+
opts = { debug: false,
|
26
|
+
file: nil,
|
27
|
+
}
|
28
|
+
|
29
|
+
parser = OptionParser.new do |parser|
|
30
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
31
|
+
|
32
|
+
##
|
33
|
+
## check if git has a offline option?? (use same)
|
34
|
+
## check for other tools - why? why not?
|
35
|
+
# parser.on( "-q", "--quiet",
|
36
|
+
# "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
37
|
+
# opts[:debug] = false
|
38
|
+
# end
|
39
|
+
parser.on( "--verbose", "--debug",
|
40
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
41
|
+
opts[:debug] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
parser.on( "-f FILE", "--file FILE",
|
45
|
+
"read datafiles (pathspecs) via .csv file") do |file|
|
46
|
+
opts[:file] = file
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
parser.parse!( args )
|
52
|
+
|
53
|
+
puts "OPTS:"
|
54
|
+
p opts
|
55
|
+
puts "ARGV:"
|
56
|
+
p args
|
57
|
+
|
58
|
+
|
59
|
+
## todo/check - use packs or projects or such
|
60
|
+
## instead of specs - why? why not?
|
61
|
+
specs = []
|
62
|
+
if opts[:file]
|
63
|
+
recs = read_csv( opts[:file] )
|
64
|
+
pp recs
|
65
|
+
## note - make pathspecs relative to passed in file arg!!!
|
66
|
+
basedir = File.dirname( opts[:file] )
|
67
|
+
recs.each do |rec|
|
68
|
+
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
69
|
+
specs << [paths, rec]
|
70
|
+
end
|
71
|
+
else
|
72
|
+
paths = if args.empty?
|
73
|
+
[
|
74
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
75
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
76
|
+
]
|
77
|
+
else
|
78
|
+
## check for directories
|
79
|
+
## and auto-expand
|
80
|
+
SportDb::Parser::Opts.expand_args( args )
|
81
|
+
end
|
82
|
+
specs << [paths, {}]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
if opts[:debug]
|
87
|
+
SportDb::QuickMatchReader.debug = true
|
88
|
+
SportDb::MatchParser.debug = true
|
89
|
+
else
|
90
|
+
SportDb::QuickMatchReader.debug = false
|
91
|
+
SportDb::MatchParser.debug = false
|
92
|
+
LogUtils::Logger.root.level = :info
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
specs.each_with_index do |(paths, rec),i|
|
97
|
+
errors = []
|
98
|
+
paths.each_with_index do |path,j|
|
99
|
+
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
100
|
+
quick = SportDb::QuickMatchReader.new( read_text( path ) )
|
101
|
+
matches = quick.parse
|
102
|
+
|
103
|
+
if quick.errors?
|
104
|
+
puts "!! #{quick.errors.size} error(s):"
|
105
|
+
pp quick.errors
|
106
|
+
|
107
|
+
quick.errors.each do |err|
|
108
|
+
errors << [ path, *err ] # note: use splat (*) to add extra values (starting with msg)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
puts " #{matches.size} match(es)"
|
112
|
+
end
|
113
|
+
|
114
|
+
if errors.size > 0
|
115
|
+
puts
|
116
|
+
puts "!! #{errors.size} PARSE ERRORS in #{paths.size} datafile(s)"
|
117
|
+
pp errors
|
118
|
+
else
|
119
|
+
puts
|
120
|
+
puts " OK - no parse errors in #{paths.size} datafile(s)"
|
121
|
+
end
|
122
|
+
|
123
|
+
## add errors to rec via rec['errors'] to allow
|
124
|
+
## for further processing/reporting
|
125
|
+
rec['errors'] = errors
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
###
|
131
|
+
## generate a report if --file option used
|
132
|
+
if opts[:file]
|
133
|
+
|
134
|
+
buf = String.new
|
135
|
+
|
136
|
+
buf << "# fbt summary report - #{specs.size} dataset(s)\n\n"
|
137
|
+
|
138
|
+
specs.each_with_index do |(paths, rec),i|
|
139
|
+
errors = rec['errors']
|
140
|
+
|
141
|
+
if errors.size > 0
|
142
|
+
buf << "!! #{errors.size} ERROR(S) "
|
143
|
+
else
|
144
|
+
buf << " OK "
|
145
|
+
end
|
146
|
+
buf << "%-20s" % rec['path']
|
147
|
+
buf << " - #{paths.size} datafile(s)"
|
148
|
+
buf << "\n"
|
149
|
+
|
150
|
+
if errors.size > 0
|
151
|
+
buf << errors.pretty_inspect
|
152
|
+
buf << "\n"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
puts
|
157
|
+
puts "SUMMARY:"
|
158
|
+
puts buf
|
159
|
+
|
160
|
+
# maybe write out in the future?
|
161
|
+
# basedir = File.dirname( opts[:file] )
|
162
|
+
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
puts "bye"
|
167
|
+
|
data/bin/fbtok
CHANGED
@@ -5,9 +5,141 @@
|
|
5
5
|
|
6
6
|
require 'fbtok'
|
7
7
|
|
8
|
+
args = ARGV
|
9
|
+
|
8
10
|
|
9
|
-
|
11
|
+
opts = {
|
12
|
+
debug: true,
|
13
|
+
metal: false,
|
14
|
+
file: nil,
|
15
|
+
}
|
10
16
|
|
17
|
+
parser = OptionParser.new do |parser|
|
18
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
|
19
|
+
|
20
|
+
|
21
|
+
parser.on( "-q", "--quiet",
|
22
|
+
"less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
23
|
+
opts[:debug] = false
|
24
|
+
end
|
25
|
+
parser.on( "--verbose", "--debug",
|
26
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
27
|
+
opts[:debug] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
parser.on( "--metal",
|
31
|
+
"turn off typed parse tree; show to the metal tokens"+
|
32
|
+
" (default: #{opts[:metal]})" ) do |metal|
|
33
|
+
opts[:metal] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
parser.on( "-f FILE", "--file FILE",
|
37
|
+
"read datafiles (pathspecs) via .csv file") do |file|
|
38
|
+
opts[:file] = file
|
39
|
+
## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
|
40
|
+
opts[:debug] = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
parser.parse!( args )
|
44
|
+
|
45
|
+
puts "OPTS:"
|
46
|
+
p opts
|
47
|
+
puts "ARGV:"
|
48
|
+
p args
|
49
|
+
|
50
|
+
|
51
|
+
## todo/check - use packs or projects or such
|
52
|
+
## instead of specs - why? why not?
|
53
|
+
specs = []
|
54
|
+
if opts[:file]
|
55
|
+
recs = read_csv( opts[:file] )
|
56
|
+
pp recs
|
57
|
+
## note - make pathspecs relative to passed in file arg!!!
|
58
|
+
basedir = File.dirname( opts[:file] )
|
59
|
+
recs.each do |rec|
|
60
|
+
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
61
|
+
specs << [paths, rec]
|
62
|
+
end
|
63
|
+
else
|
64
|
+
paths = if args.empty?
|
65
|
+
[
|
66
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
67
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
68
|
+
]
|
69
|
+
else
|
70
|
+
## check for directories
|
71
|
+
## and auto-expand
|
72
|
+
SportDb::Parser::Opts.expand_args( args )
|
73
|
+
end
|
74
|
+
specs << [paths, {}]
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
SportDb::Parser::Linter.debug = true if opts[:debug]
|
79
|
+
|
80
|
+
linter = SportDb::Parser::Linter.new
|
81
|
+
|
82
|
+
|
83
|
+
specs.each_with_index do |(paths, rec),i|
|
84
|
+
errors = []
|
85
|
+
|
86
|
+
paths.each_with_index do |path,j|
|
87
|
+
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
88
|
+
linter.read( path, parse: !opts[:metal] )
|
89
|
+
|
90
|
+
errors += linter.errors if linter.errors?
|
91
|
+
end
|
92
|
+
|
93
|
+
if errors.size > 0
|
94
|
+
puts
|
95
|
+
pp errors
|
96
|
+
puts
|
97
|
+
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
98
|
+
else
|
99
|
+
puts
|
100
|
+
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
101
|
+
end
|
102
|
+
|
103
|
+
## add errors to rec via rec['errors'] to allow
|
104
|
+
## for further processing/reporting
|
105
|
+
rec['errors'] = errors
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
###
|
110
|
+
## generate a report if --file option used
|
111
|
+
if opts[:file]
|
112
|
+
|
113
|
+
buf = String.new
|
114
|
+
|
115
|
+
buf << "# fbtok summary report - #{specs.size} dataset(s)\n\n"
|
116
|
+
|
117
|
+
specs.each_with_index do |(paths, rec),i|
|
118
|
+
errors = rec['errors']
|
119
|
+
|
120
|
+
if errors.size > 0
|
121
|
+
buf << "!! #{errors.size} ERROR(S) "
|
122
|
+
else
|
123
|
+
buf << " OK "
|
124
|
+
end
|
125
|
+
buf << "%-20s" % rec['path']
|
126
|
+
buf << " - #{paths.size} datafile(s)"
|
127
|
+
buf << "\n"
|
128
|
+
|
129
|
+
if errors.size > 0
|
130
|
+
buf << errors.pretty_inspect
|
131
|
+
buf << "\n"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
puts
|
136
|
+
puts "SUMMARY:"
|
137
|
+
puts buf
|
138
|
+
|
139
|
+
# maybe write out in the future?
|
140
|
+
# basedir = File.dirname( opts[:file] )
|
141
|
+
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
142
|
+
end
|
11
143
|
|
12
144
|
puts "bye"
|
13
145
|
|
data/bin/fbx
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib -I ../parser/lib bin/fbx
|
5
|
+
|
6
|
+
##
|
7
|
+
## todo/fix - use for testing
|
8
|
+
# reads textfile and dumps results in json
|
9
|
+
#
|
10
|
+
# check - keep fbx name or find a differnt name - why? why not?
|
11
|
+
|
12
|
+
|
13
|
+
## our own code
|
14
|
+
require 'fbtok'
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
## read textfile
|
19
|
+
## and dump match parse results
|
20
|
+
##
|
21
|
+
## fbt ../openfootball/.../euro.txt
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
args = ARGV
|
27
|
+
opts = { debug: false,
|
28
|
+
outline: false }
|
29
|
+
|
30
|
+
parser = OptionParser.new do |parser|
|
31
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
32
|
+
|
33
|
+
##
|
34
|
+
## check if git has a offline option?? (use same)
|
35
|
+
## check for other tools - why? why not?
|
36
|
+
|
37
|
+
|
38
|
+
parser.on( "--verbose", "--debug",
|
39
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
40
|
+
opts[:debug] = debug
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.on( "--outline",
|
44
|
+
"turn on outline (only) output (default: #{opts[:outline]})" ) do |outline|
|
45
|
+
opts[:outline] = outline
|
46
|
+
end
|
47
|
+
end
|
48
|
+
parser.parse!( args )
|
49
|
+
|
50
|
+
puts "OPTS:"
|
51
|
+
p opts
|
52
|
+
puts "ARGV:"
|
53
|
+
p args
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
paths = if args.empty?
|
60
|
+
[
|
61
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
62
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
63
|
+
]
|
64
|
+
else
|
65
|
+
## check for directories
|
66
|
+
## and auto-expand
|
67
|
+
|
68
|
+
SportDb::Parser::Opts.expand_args( args )
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
SportDb::MatchParser.debug = true if opts[:debug]
|
78
|
+
|
79
|
+
|
80
|
+
## errors = []
|
81
|
+
|
82
|
+
|
83
|
+
paths.each_with_index do |path,i|
|
84
|
+
puts "==> [#{i+1}/#{paths.size}] reading >#{path}<..."
|
85
|
+
|
86
|
+
txt = read_text( path )
|
87
|
+
secs = SportDb::LeagueOutlineReader.parse( txt )
|
88
|
+
## pp secs
|
89
|
+
|
90
|
+
secs.each_with_index do |sec,j| ## sec(tion)s
|
91
|
+
season = sec[:season]
|
92
|
+
league = sec[:league]
|
93
|
+
stage = sec[:stage]
|
94
|
+
lines = sec[:lines]
|
95
|
+
|
96
|
+
puts " section #{j+1}/#{secs.size} - #{league.name} #{season}, #{stage} - #{lines.size} line(s)"
|
97
|
+
|
98
|
+
next if opts[:outline]
|
99
|
+
|
100
|
+
=begin
|
101
|
+
### check if event info availabe - use start_date;
|
102
|
+
## otherwise we have to guess (use a "synthetic" start_date)
|
103
|
+
event_info = catalog.events.find_by( season: season,
|
104
|
+
league: league )
|
105
|
+
|
106
|
+
start = if event_info && event_info.start_date
|
107
|
+
puts "event info found:"
|
108
|
+
puts " using start date from event: "
|
109
|
+
pp event_info
|
110
|
+
pp event_info.start_date
|
111
|
+
event_info.start_date
|
112
|
+
else
|
113
|
+
=end
|
114
|
+
start = if season.year?
|
115
|
+
Date.new( season.start_year, 1, 1 )
|
116
|
+
else
|
117
|
+
Date.new( season.start_year, 7, 1 )
|
118
|
+
end
|
119
|
+
|
120
|
+
parser = SportDb::MatchParser.new( lines,
|
121
|
+
start ) ## note: keep season start_at date for now (no need for more specific stage date need for now)
|
122
|
+
|
123
|
+
auto_conf_teams, matches, rounds, groups = parser.parse
|
124
|
+
|
125
|
+
puts ">>> #{auto_conf_teams.size} teams:"
|
126
|
+
pp auto_conf_teams
|
127
|
+
puts ">>> #{matches.size} matches:"
|
128
|
+
## pp matches
|
129
|
+
puts ">>> #{rounds.size} rounds:"
|
130
|
+
pp rounds
|
131
|
+
puts ">>> #{groups.size} groups:"
|
132
|
+
pp groups
|
133
|
+
end # each secs
|
134
|
+
end # each paths
|
135
|
+
|
136
|
+
=begin
|
137
|
+
if errors.size > 0
|
138
|
+
puts
|
139
|
+
pp errors
|
140
|
+
puts
|
141
|
+
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
142
|
+
else
|
143
|
+
puts
|
144
|
+
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
145
|
+
end
|
146
|
+
=end
|
147
|
+
|
148
|
+
puts "bye"
|
149
|
+
|
data/lib/fbtok.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
|
2
|
-
require 'sportdb/
|
2
|
+
require 'sportdb/quick'
|
3
|
+
|
4
|
+
|
5
|
+
## more stdlibs
|
6
|
+
require 'optparse' ## check - already auto-required in cocos? keep? why? why not?
|
3
7
|
|
4
8
|
|
5
9
|
## our own code
|
6
10
|
require_relative 'fbtok/opts'
|
7
|
-
require_relative 'fbtok/
|
11
|
+
require_relative 'fbtok/linter'
|
8
12
|
|
9
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbtok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -11,19 +11,19 @@ cert_chain: []
|
|
11
11
|
date: 2025-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: sportdb-
|
14
|
+
name: sportdb-quick
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3.
|
26
|
+
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +61,9 @@ dependencies:
|
|
61
61
|
description: fbtok - football.txt lint tools incl. tokenizer, parser & more
|
62
62
|
email: gerald.bauer@gmail.com
|
63
63
|
executables:
|
64
|
+
- fbt
|
64
65
|
- fbtok
|
66
|
+
- fbx
|
65
67
|
extensions: []
|
66
68
|
extra_rdoc_files:
|
67
69
|
- CHANGELOG.md
|
@@ -72,9 +74,10 @@ files:
|
|
72
74
|
- Manifest.txt
|
73
75
|
- README.md
|
74
76
|
- Rakefile
|
77
|
+
- bin/fbt
|
75
78
|
- bin/fbtok
|
79
|
+
- bin/fbx
|
76
80
|
- lib/fbtok.rb
|
77
|
-
- lib/fbtok/fbtok.rb
|
78
81
|
- lib/fbtok/linter.rb
|
79
82
|
- lib/fbtok/opts.rb
|
80
83
|
homepage: https://github.com/sportdb/footty
|
data/lib/fbtok/fbtok.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
|
2
|
-
module Fbtok
|
3
|
-
def self.main( args=ARGV )
|
4
|
-
|
5
|
-
opts = {
|
6
|
-
debug: true,
|
7
|
-
metal: false,
|
8
|
-
file: nil,
|
9
|
-
}
|
10
|
-
|
11
|
-
parser = OptionParser.new do |parser|
|
12
|
-
parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
|
13
|
-
|
14
|
-
|
15
|
-
parser.on( "-q", "--quiet",
|
16
|
-
"less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
17
|
-
opts[:debug] = false
|
18
|
-
end
|
19
|
-
parser.on( "--verbose", "--debug",
|
20
|
-
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
21
|
-
opts[:debug] = true
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.on( "--metal",
|
25
|
-
"turn off typed parse tree; show to the metal tokens"+
|
26
|
-
" (default: #{opts[:metal]})" ) do |metal|
|
27
|
-
opts[:metal] = true
|
28
|
-
end
|
29
|
-
|
30
|
-
parser.on( "-f FILE", "--file FILE",
|
31
|
-
"read datafiles (pathspecs) via .csv file") do |file|
|
32
|
-
opts[:file] = file
|
33
|
-
## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
|
34
|
-
opts[:debug] = false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
parser.parse!( args )
|
38
|
-
|
39
|
-
puts "OPTS:"
|
40
|
-
p opts
|
41
|
-
puts "ARGV:"
|
42
|
-
p args
|
43
|
-
|
44
|
-
|
45
|
-
## todo/check - use packs or projects or such
|
46
|
-
## instead of specs - why? why not?
|
47
|
-
specs = []
|
48
|
-
if opts[:file]
|
49
|
-
recs = read_csv( opts[:file] )
|
50
|
-
pp recs
|
51
|
-
## note - make pathspecs relative to passed in file arg!!!
|
52
|
-
basedir = File.dirname( opts[:file] )
|
53
|
-
recs.each do |rec|
|
54
|
-
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
55
|
-
specs << [paths, rec]
|
56
|
-
end
|
57
|
-
else
|
58
|
-
paths = if args.empty?
|
59
|
-
[
|
60
|
-
'../../../openfootball/euro/2021--europe/euro.txt',
|
61
|
-
'../../../openfootball/euro/2024--germany/euro.txt',
|
62
|
-
]
|
63
|
-
else
|
64
|
-
## check for directories
|
65
|
-
## and auto-expand
|
66
|
-
SportDb::Parser::Opts.expand_args( args )
|
67
|
-
end
|
68
|
-
specs << [paths, {}]
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
SportDb::Parser::Linter.debug = true if opts[:debug]
|
73
|
-
|
74
|
-
linter = SportDb::Parser::Linter.new
|
75
|
-
|
76
|
-
|
77
|
-
specs.each_with_index do |(paths, rec),i|
|
78
|
-
errors = []
|
79
|
-
|
80
|
-
paths.each_with_index do |path,j|
|
81
|
-
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
82
|
-
linter.read( path, parse: !opts[:metal] )
|
83
|
-
|
84
|
-
errors += linter.errors if linter.errors?
|
85
|
-
end
|
86
|
-
|
87
|
-
if errors.size > 0
|
88
|
-
puts
|
89
|
-
pp errors
|
90
|
-
puts
|
91
|
-
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
92
|
-
else
|
93
|
-
puts
|
94
|
-
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
95
|
-
end
|
96
|
-
|
97
|
-
## add errors to rec via rec['errors'] to allow
|
98
|
-
## for further processing/reporting
|
99
|
-
rec['errors'] = errors
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
###
|
104
|
-
## generate a report if --file option used
|
105
|
-
if opts[:file]
|
106
|
-
|
107
|
-
buf = String.new
|
108
|
-
|
109
|
-
buf << "# fbtok summary report - #{specs.size} dataset(s)\n\n"
|
110
|
-
|
111
|
-
specs.each_with_index do |(paths, rec),i|
|
112
|
-
errors = rec['errors']
|
113
|
-
|
114
|
-
if errors.size > 0
|
115
|
-
buf << "!! #{errors.size} ERROR(S) "
|
116
|
-
else
|
117
|
-
buf << " OK "
|
118
|
-
end
|
119
|
-
buf << "%-20s" % rec['path']
|
120
|
-
buf << " - #{paths.size} datafile(s)"
|
121
|
-
buf << "\n"
|
122
|
-
|
123
|
-
if errors.size > 0
|
124
|
-
buf << errors.pretty_inspect
|
125
|
-
buf << "\n"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
puts
|
130
|
-
puts "SUMMARY:"
|
131
|
-
puts buf
|
132
|
-
|
133
|
-
# maybe write out in the future?
|
134
|
-
# basedir = File.dirname( opts[:file] )
|
135
|
-
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end # method self.main
|
141
|
-
end # module Fbtok
|