judges 0.0.29 → 0.0.31
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/Gemfile.lock +3 -3
- data/Rakefile +1 -0
- data/bin/judges +3 -1
- data/features/import.feature +1 -1
- data/features/print.feature +9 -4
- data/judges.gemspec +2 -2
- data/lib/judges/commands/eval.rb +11 -11
- data/lib/judges/commands/import.rb +14 -11
- data/lib/judges/commands/join.rb +7 -4
- data/lib/judges/commands/print.rb +24 -14
- data/lib/judges/commands/test.rb +21 -24
- data/lib/judges/commands/trim.rb +5 -7
- data/lib/judges/commands/update.rb +37 -33
- data/lib/judges/elapsed.rb +32 -0
- data/lib/judges/pack.rb +3 -1
- data/test/commands/test_print.rb +15 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c9e50999193ddf009d02379799add455856fae20b4f47e67a1760d56d7de3b0
|
|
4
|
+
data.tar.gz: af70fa8273042c07df059589181795769518c94d54c4430cf9fe9d2999da799a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce9ee17c4b5cf1aadc125678bde1e0a7b4bd07a6e1cb2e54696e5e478a68371f9e4c7a6c18f7961be77f056903a1e49eb943d4c9d949fedb96db71ed2f23350e
|
|
7
|
+
data.tar.gz: fbadf8ca9127b21114b483b7a7f5e6b109d8c804f101a27fe6140c6a77e68a0f522bda5b32a366415b946d1c59c01130ab509a22e9f5c95037dbf605414d7667
|
data/Gemfile.lock
CHANGED
|
@@ -3,7 +3,7 @@ PATH
|
|
|
3
3
|
specs:
|
|
4
4
|
judges (0.0.0)
|
|
5
5
|
backtrace (~> 0.3)
|
|
6
|
-
factbase (~> 0.0.
|
|
6
|
+
factbase (~> 0.0.30)
|
|
7
7
|
gli (~> 2.21)
|
|
8
8
|
loog (~> 0.2)
|
|
9
9
|
nokogiri (~> 1.10)
|
|
@@ -74,7 +74,7 @@ GEM
|
|
|
74
74
|
docile (1.4.0)
|
|
75
75
|
drb (2.2.1)
|
|
76
76
|
erubi (1.12.0)
|
|
77
|
-
factbase (0.0.
|
|
77
|
+
factbase (0.0.30)
|
|
78
78
|
json (~> 2.7)
|
|
79
79
|
loog (~> 0.2)
|
|
80
80
|
nokogiri (~> 1.10)
|
|
@@ -112,7 +112,7 @@ GEM
|
|
|
112
112
|
racc
|
|
113
113
|
psych (5.1.2)
|
|
114
114
|
stringio
|
|
115
|
-
racc (1.
|
|
115
|
+
racc (1.8.0)
|
|
116
116
|
rack (3.0.11)
|
|
117
117
|
rack-session (2.0.0)
|
|
118
118
|
rack (>= 3.0.0)
|
data/Rakefile
CHANGED
data/bin/judges
CHANGED
|
@@ -32,7 +32,7 @@ Encoding.default_internal = Encoding::UTF_8
|
|
|
32
32
|
class App
|
|
33
33
|
extend GLI::App
|
|
34
34
|
|
|
35
|
-
ver = '0.0.
|
|
35
|
+
ver = '0.0.31'
|
|
36
36
|
|
|
37
37
|
loog = Loog::REGULAR
|
|
38
38
|
|
|
@@ -115,6 +115,8 @@ class App
|
|
|
115
115
|
c.switch([:auto], default_value: false)
|
|
116
116
|
c.desc 'Only the facts that match the expression are printed'
|
|
117
117
|
c.flag([:query], default_value: '()')
|
|
118
|
+
c.desc 'Print even if target file already exists and is older than the factbase'
|
|
119
|
+
c.switch([:force], default_value: false)
|
|
118
120
|
c.action do |global, options, args|
|
|
119
121
|
require_relative '../lib/judges/commands/print'
|
|
120
122
|
Judges::Print.new(loog).run(options, args)
|
data/features/import.feature
CHANGED
data/features/print.feature
CHANGED
|
@@ -4,7 +4,6 @@ Feature: Print
|
|
|
4
4
|
Scenario: Simple print of a small factbase, to YAML
|
|
5
5
|
Given I make a temp directory
|
|
6
6
|
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
|
|
7
|
-
Then I run bin/judges with "update . simple.fb"
|
|
8
7
|
Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
|
|
9
8
|
Then Stdout contains "printed"
|
|
10
9
|
And Exit code is zero
|
|
@@ -12,7 +11,6 @@ Feature: Print
|
|
|
12
11
|
Scenario: Simple print of a small factbase, to JSON
|
|
13
12
|
Given I make a temp directory
|
|
14
13
|
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
|
|
15
|
-
Then I run bin/judges with "update . simple.fb"
|
|
16
14
|
Then I run bin/judges with "print --format=json simple.fb simple.json"
|
|
17
15
|
Then Stdout contains "printed"
|
|
18
16
|
And Exit code is zero
|
|
@@ -20,7 +18,6 @@ Feature: Print
|
|
|
20
18
|
Scenario: Simple print of a small factbase, to XML
|
|
21
19
|
Given I make a temp directory
|
|
22
20
|
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
|
|
23
|
-
Then I run bin/judges with "update . simple.fb"
|
|
24
21
|
Then I run bin/judges with "print --format=xml --auto simple.fb"
|
|
25
22
|
Then Stdout contains "printed"
|
|
26
23
|
And Exit code is zero
|
|
@@ -29,7 +26,15 @@ Feature: Print
|
|
|
29
26
|
Given I make a temp directory
|
|
30
27
|
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
|
|
31
28
|
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 43'"
|
|
32
|
-
Then I run bin/judges with "update . simple.fb"
|
|
33
29
|
Then I run bin/judges with "print '--query=(eq foo 43)' --auto simple.fb"
|
|
34
30
|
Then Stdout contains "printed"
|
|
35
31
|
And Exit code is zero
|
|
32
|
+
|
|
33
|
+
Scenario: Print twice, without --force
|
|
34
|
+
Given I make a temp directory
|
|
35
|
+
Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
|
|
36
|
+
Then I run bin/judges with "print --auto simple.fb"
|
|
37
|
+
Then Stdout contains "printed"
|
|
38
|
+
Then I run bin/judges with "print --auto simple.fb"
|
|
39
|
+
Then Stdout contains "No need to print"
|
|
40
|
+
And Exit code is zero
|
data/judges.gemspec
CHANGED
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
27
27
|
s.required_ruby_version = '>=3.2'
|
|
28
28
|
s.name = 'judges'
|
|
29
|
-
s.version = '0.0.
|
|
29
|
+
s.version = '0.0.31'
|
|
30
30
|
s.license = 'MIT'
|
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
|
32
32
|
s.description = '
|
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
|
42
42
|
s.rdoc_options = ['--charset=UTF-8']
|
|
43
43
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
|
44
44
|
s.add_runtime_dependency 'backtrace', '~> 0.3'
|
|
45
|
-
s.add_runtime_dependency 'factbase', '~>0.0.
|
|
45
|
+
s.add_runtime_dependency 'factbase', '~>0.0.30'
|
|
46
46
|
s.add_runtime_dependency 'gli', '~>2.21'
|
|
47
47
|
s.add_runtime_dependency 'loog', '~>0.2'
|
|
48
48
|
s.add_runtime_dependency 'nokogiri', '~> 1.10'
|
data/lib/judges/commands/eval.rb
CHANGED
|
@@ -20,13 +20,10 @@
|
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
# SOFTWARE.
|
|
22
22
|
|
|
23
|
-
require 'backtrace'
|
|
24
23
|
require 'factbase/looged'
|
|
25
24
|
require_relative '../../judges'
|
|
26
|
-
require_relative '../../judges/to_rel'
|
|
27
|
-
require_relative '../../judges/packs'
|
|
28
|
-
require_relative '../../judges/options'
|
|
29
25
|
require_relative '../../judges/impex'
|
|
26
|
+
require_relative '../../judges/elapsed'
|
|
30
27
|
|
|
31
28
|
# Eval.
|
|
32
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -40,12 +37,15 @@ class Judges::Eval
|
|
|
40
37
|
def run(_opts, args)
|
|
41
38
|
raise 'Exactly two arguments required' unless args.size == 2
|
|
42
39
|
impex = Judges::Impex.new(@loog, args[0])
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
elapsed(@loog) do
|
|
41
|
+
$fb = impex.import(strict: false)
|
|
42
|
+
$fb = Factbase::Looged.new($fb, @loog)
|
|
43
|
+
expr = args[1]
|
|
44
|
+
# rubocop:disable Security/Eval
|
|
45
|
+
eval(expr)
|
|
46
|
+
# rubocop:enable Security/Eval
|
|
47
|
+
impex.export($fb)
|
|
48
|
+
throw :'Evaluated successfully'
|
|
49
|
+
end
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -25,6 +25,7 @@ require 'factbase/looged'
|
|
|
25
25
|
require_relative '../../judges'
|
|
26
26
|
require_relative '../../judges/impex'
|
|
27
27
|
require_relative '../../judges/to_rel'
|
|
28
|
+
require_relative '../../judges/elapsed'
|
|
28
29
|
|
|
29
30
|
# Import.
|
|
30
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -38,18 +39,20 @@ class Judges::Import
|
|
|
38
39
|
def run(_opts, args)
|
|
39
40
|
raise 'Exactly two arguments required' unless args.size == 2
|
|
40
41
|
raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
elapsed(@loog) do
|
|
43
|
+
yaml = YAML.load_file(args[0], permitted_classes: [Time])
|
|
44
|
+
@loog.info("YAML loaded from #{args[0].to_rel} (#{yaml.size} facts)")
|
|
45
|
+
impex = Judges::Impex.new(@loog, args[1])
|
|
46
|
+
fb = impex.import(strict: false)
|
|
47
|
+
fb = Factbase::Looged.new(fb, @loog)
|
|
48
|
+
yaml.each do |i|
|
|
49
|
+
f = fb.insert
|
|
50
|
+
i.each do |p, v|
|
|
51
|
+
f.send("#{p}=", v)
|
|
52
|
+
end
|
|
50
53
|
end
|
|
54
|
+
impex.export(fb)
|
|
55
|
+
throw :"Import of #{yaml.size} facts finished"
|
|
51
56
|
end
|
|
52
|
-
impex.export(fb)
|
|
53
|
-
@loog.info("Import finished in #{format('%.02f', Time.now - start)}s")
|
|
54
57
|
end
|
|
55
58
|
end
|
data/lib/judges/commands/join.rb
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
require_relative '../../judges'
|
|
24
24
|
require_relative '../../judges/impex'
|
|
25
|
+
require_relative '../../judges/elapsed'
|
|
25
26
|
|
|
26
27
|
# Join.
|
|
27
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -36,9 +37,11 @@ class Judges::Join
|
|
|
36
37
|
raise 'Exactly two arguments required' unless args.size == 2
|
|
37
38
|
master = Judges::Impex.new(@loog, args[0])
|
|
38
39
|
slave = Judges::Impex.new(@loog, args[1])
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
elapsed(@loog) do
|
|
41
|
+
fb = master.import
|
|
42
|
+
slave.import_to(fb)
|
|
43
|
+
master.export(fb)
|
|
44
|
+
throw :'Two factbases joined'
|
|
45
|
+
end
|
|
43
46
|
end
|
|
44
47
|
end
|
|
@@ -24,6 +24,7 @@ require 'fileutils'
|
|
|
24
24
|
require 'factbase'
|
|
25
25
|
require_relative '../../judges'
|
|
26
26
|
require_relative '../../judges/impex'
|
|
27
|
+
require_relative '../../judges/elapsed'
|
|
27
28
|
|
|
28
29
|
# Update.
|
|
29
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -36,29 +37,38 @@ class Judges::Print
|
|
|
36
37
|
|
|
37
38
|
def run(opts, args)
|
|
38
39
|
raise 'At lease one argument required' if args.empty?
|
|
39
|
-
o = args[1]
|
|
40
40
|
f = args[0]
|
|
41
41
|
fb = Judges::Impex.new(@loog, f).import
|
|
42
42
|
fb.query("(not #{opts['query']})").delete! unless opts['query'].nil?
|
|
43
|
+
o = args[1]
|
|
43
44
|
if o.nil?
|
|
44
45
|
raise 'Either provide output file name or use --auto' unless opts[:auto]
|
|
45
46
|
o = File.join(File.dirname(f), File.basename(f).gsub(/\.[^.]*$/, ''))
|
|
46
47
|
o = "#{o}.#{opts[:format]}"
|
|
47
48
|
end
|
|
48
49
|
FileUtils.mkdir_p(File.dirname(o))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Factbase::ToYAML.new(fb).yaml
|
|
54
|
-
when 'json'
|
|
55
|
-
require 'factbase/to_json'
|
|
56
|
-
Factbase::ToJSON.new(fb).json
|
|
57
|
-
when 'xml'
|
|
58
|
-
require 'factbase/to_xml'
|
|
59
|
-
Factbase::ToXML.new(fb).xml
|
|
50
|
+
if !opts['force'] && File.exist?(o)
|
|
51
|
+
if File.mtime(f) < File.mtime(o)
|
|
52
|
+
@loog.info("No need to print to #{o.to_rel}, since it's up to date (#{File.size(o)} bytes)")
|
|
53
|
+
return
|
|
60
54
|
end
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
@loog.debug("The factbase #{f.to_rel} is younger than the target #{o.to_rel}, need to print")
|
|
56
|
+
end
|
|
57
|
+
elapsed(@loog) do
|
|
58
|
+
output =
|
|
59
|
+
case opts[:format].downcase
|
|
60
|
+
when 'yaml'
|
|
61
|
+
require 'factbase/to_yaml'
|
|
62
|
+
Factbase::ToYAML.new(fb).yaml
|
|
63
|
+
when 'json'
|
|
64
|
+
require 'factbase/to_json'
|
|
65
|
+
Factbase::ToJSON.new(fb).json
|
|
66
|
+
when 'xml'
|
|
67
|
+
require 'factbase/to_xml'
|
|
68
|
+
Factbase::ToXML.new(fb).xml
|
|
69
|
+
end
|
|
70
|
+
File.binwrite(o, output)
|
|
71
|
+
throw :"Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)"
|
|
72
|
+
end
|
|
63
73
|
end
|
|
64
74
|
end
|
data/lib/judges/commands/test.rb
CHANGED
|
@@ -29,6 +29,7 @@ require_relative '../../judges'
|
|
|
29
29
|
require_relative '../../judges/to_rel'
|
|
30
30
|
require_relative '../../judges/packs'
|
|
31
31
|
require_relative '../../judges/options'
|
|
32
|
+
require_relative '../../judges/elapsed'
|
|
32
33
|
|
|
33
34
|
# Test.
|
|
34
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -46,33 +47,29 @@ class Judges::Test
|
|
|
46
47
|
errors = []
|
|
47
48
|
done = 0
|
|
48
49
|
global = {}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
elapsed(@loog) do
|
|
51
|
+
Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
|
|
52
|
+
local = {}
|
|
53
|
+
next unless include?(opts, p.name)
|
|
54
|
+
@loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
|
|
55
|
+
p.tests.each do |f|
|
|
56
|
+
yaml = YAML.load_file(f, permitted_classes: [Time])
|
|
57
|
+
@loog.info("Testing #{f.to_rel}:")
|
|
58
|
+
begin
|
|
59
|
+
test_one(p, global, local, yaml)
|
|
60
|
+
rescue StandardError => e
|
|
61
|
+
@loog.warn(Backtrace.new(e))
|
|
62
|
+
errors << f
|
|
63
|
+
end
|
|
62
64
|
end
|
|
65
|
+
done += 1
|
|
63
66
|
end
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if done.zero?
|
|
68
|
-
raise 'No judges tested :(' unless opts['quiet']
|
|
69
|
-
@loog.warn("\n👍 No judges tested #{lapse}")
|
|
70
|
-
elsif errors.empty?
|
|
71
|
-
@loog.info("\n👍 All #{done} judge(s) tested successfully #{lapse}")
|
|
72
|
-
else
|
|
73
|
-
@loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed #{lapse}")
|
|
74
|
-
raise "#{errors.size} tests failed" unless opts['quiet']
|
|
67
|
+
throw :'👍 No judges tested' if done.zero?
|
|
68
|
+
throw :"👍 All #{done} judge(s) tested successfully" if errors.empty?
|
|
69
|
+
throw :"❌ #{done} judge(s) tested, #{errors.size} of them failed"
|
|
75
70
|
end
|
|
71
|
+
raise "#{errors.size} tests failed" unless opts['quiet'] || errors.empty?
|
|
72
|
+
raise 'No judges tested :(' unless opts['quiet'] || !done.zero?
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
private
|
data/lib/judges/commands/trim.rb
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
require 'time'
|
|
24
24
|
require_relative '../../judges'
|
|
25
25
|
require_relative '../../judges/impex'
|
|
26
|
+
require_relative '../../judges/elapsed'
|
|
26
27
|
|
|
27
28
|
# Trim.
|
|
28
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -46,14 +47,11 @@ class Judges::Trim
|
|
|
46
47
|
else
|
|
47
48
|
raise 'Specify either --days or --query' unless opts['days'].nil?
|
|
48
49
|
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if deleted.zero?
|
|
53
|
-
@loog.info("No facts deleted #{lapse}")
|
|
54
|
-
else
|
|
55
|
-
@loog.info("🗑 #{deleted} fact(s) deleted #{lapse}")
|
|
50
|
+
elapsed(@loog) do
|
|
51
|
+
deleted = fb.query(query).delete!
|
|
52
|
+
throw :'No facts deleted' if deleted.zero?
|
|
56
53
|
impex.export(fb)
|
|
54
|
+
throw :"🗑 #{deleted} fact(s) deleted"
|
|
57
55
|
end
|
|
58
56
|
end
|
|
59
57
|
end
|
|
@@ -27,6 +27,7 @@ require_relative '../../judges/to_rel'
|
|
|
27
27
|
require_relative '../../judges/packs'
|
|
28
28
|
require_relative '../../judges/options'
|
|
29
29
|
require_relative '../../judges/impex'
|
|
30
|
+
require_relative '../../judges/elapsed'
|
|
30
31
|
|
|
31
32
|
# Update.
|
|
32
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
@@ -48,23 +49,27 @@ class Judges::Update
|
|
|
48
49
|
@loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
|
|
49
50
|
packs = Judges::Packs.new(dir, opts['lib'], @loog)
|
|
50
51
|
c = 0
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
break
|
|
52
|
+
elapsed(@loog) do
|
|
53
|
+
loop do
|
|
54
|
+
c += 1
|
|
55
|
+
if c > 1
|
|
56
|
+
@loog.info("\n\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...")
|
|
57
|
+
end
|
|
58
|
+
diff = cycle(opts, packs, fb, options)
|
|
59
|
+
impex.export(fb)
|
|
60
|
+
break if diff.zero?
|
|
61
|
+
if !opts['max-cycles'].nil? && c >= opts['max-cycles']
|
|
62
|
+
@loog.info('Too many cycles already, as set by --max-cycles, breaking')
|
|
63
|
+
break
|
|
64
|
+
end
|
|
65
|
+
@loog.info(
|
|
66
|
+
"By #{diff} facts the factbase " \
|
|
67
|
+
"#{diff.positive? ? 'increased' : 'decreased'} " \
|
|
68
|
+
"its size at the cycle ##{c}"
|
|
69
|
+
)
|
|
60
70
|
end
|
|
61
|
-
|
|
62
|
-
"By #{diff} facts the factbase " \
|
|
63
|
-
"#{diff.positive? ? 'increased' : 'decreased'} " \
|
|
64
|
-
"its size at the cycle ##{c}"
|
|
65
|
-
)
|
|
71
|
+
throw :"Update finished: #{c} cycles"
|
|
66
72
|
end
|
|
67
|
-
@loog.info("Update finished: #{c} cycles in #{format('%.02f', Time.now - start)}s")
|
|
68
73
|
end
|
|
69
74
|
|
|
70
75
|
private
|
|
@@ -73,26 +78,25 @@ class Judges::Update
|
|
|
73
78
|
errors = []
|
|
74
79
|
diff = 0
|
|
75
80
|
global = {}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
elapsed(@loog) do
|
|
82
|
+
done = packs.each_with_index do |p, i|
|
|
83
|
+
local = {}
|
|
84
|
+
@loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
|
|
85
|
+
before = fb.size
|
|
86
|
+
begin
|
|
87
|
+
p.run(fb, global, local, options)
|
|
88
|
+
rescue StandardError => e
|
|
89
|
+
@loog.warn(Backtrace.new(e))
|
|
90
|
+
errors << p.script
|
|
91
|
+
end
|
|
92
|
+
after = fb.size
|
|
93
|
+
@loog.info("👍 The judge #{p.dir.to_rel} added #{after - before} facts") if after > before
|
|
94
|
+
diff += after - before
|
|
85
95
|
end
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
diff += after - before
|
|
89
|
-
end
|
|
90
|
-
if errors.empty?
|
|
91
|
-
@loog.info("👍 #{done} judge(s) processed")
|
|
92
|
-
else
|
|
93
|
-
@loog.info("❌ #{done} judge(s) processed with #{errors.size} errors")
|
|
94
|
-
raise "Failed to update correctly (#{errors.size} errors)" unless opts['quiet']
|
|
96
|
+
throw :"👍 #{done} judge(s) processed" if errors.empty?
|
|
97
|
+
throw :"❌ #{done} judge(s) processed with #{errors.size} errors"
|
|
95
98
|
end
|
|
99
|
+
raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty? || opts['quiet']
|
|
96
100
|
diff
|
|
97
101
|
end
|
|
98
102
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
|
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.
|
|
22
|
+
|
|
23
|
+
def elapsed(loog)
|
|
24
|
+
start = Time.now
|
|
25
|
+
begin
|
|
26
|
+
yield
|
|
27
|
+
rescue UncaughtThrowError => e
|
|
28
|
+
tag = e.tag
|
|
29
|
+
throw e unless tag.is_a?(Symbol)
|
|
30
|
+
loog.info("#{tag} in #{format('%.02f', Time.now - start)}s")
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/judges/pack.rb
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
require_relative '../judges'
|
|
24
24
|
require_relative '../judges/to_rel'
|
|
25
|
+
require_relative '../judges/elapsed'
|
|
25
26
|
require_relative '../judges/fb/once'
|
|
26
27
|
require_relative '../judges/fb/if_absent'
|
|
27
28
|
|
|
@@ -55,8 +56,9 @@ class Judges::Pack
|
|
|
55
56
|
end
|
|
56
57
|
s = File.join(@dir, script)
|
|
57
58
|
raise "Can't load '#{s}'" unless File.exist?(s)
|
|
58
|
-
|
|
59
|
+
elapsed(@loog) do
|
|
59
60
|
load(s, true)
|
|
61
|
+
throw :"#{name} finished"
|
|
60
62
|
ensure
|
|
61
63
|
$fb = $judge = $options = $loog = nil
|
|
62
64
|
end
|
data/test/commands/test_print.rb
CHANGED
|
@@ -44,4 +44,19 @@ class TestPrint < Minitest::Test
|
|
|
44
44
|
assert_equal(1, YAML.load_file(y)['facts'].size)
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
def test_print_twice
|
|
49
|
+
Dir.mktmpdir do |d|
|
|
50
|
+
f = File.join(d, 'base.fb')
|
|
51
|
+
fb = Factbase.new
|
|
52
|
+
fb.insert
|
|
53
|
+
File.binwrite(f, fb.export)
|
|
54
|
+
Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
|
|
55
|
+
y = File.join(d, 'base.yaml')
|
|
56
|
+
assert(File.exist?(y))
|
|
57
|
+
mtime = File.mtime(y)
|
|
58
|
+
Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
|
|
59
|
+
assert_equal(mtime, File.mtime(y))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
47
62
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: judges
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.31
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-05-
|
|
11
|
+
date: 2024-05-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.0.
|
|
33
|
+
version: 0.0.30
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.0.
|
|
40
|
+
version: 0.0.30
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: gli
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -137,6 +137,7 @@ files:
|
|
|
137
137
|
- lib/judges/commands/test.rb
|
|
138
138
|
- lib/judges/commands/trim.rb
|
|
139
139
|
- lib/judges/commands/update.rb
|
|
140
|
+
- lib/judges/elapsed.rb
|
|
140
141
|
- lib/judges/fb/if_absent.rb
|
|
141
142
|
- lib/judges/fb/once.rb
|
|
142
143
|
- lib/judges/impex.rb
|