vete 0.1.0 → 0.2.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/lib/vete.rb +49 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d1ef6e5614f544a633cfe36109f37ef7a37676b7ba276be48abcc40d6e9cf54
|
4
|
+
data.tar.gz: a0036c27a47eddba9385673345f4456fbae869fa816c8c2c0d46ce92a0866d82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f287195bba7b81a368560aa3f0694b60e7afe8292957b9d947ca820291b603bdfc3d231bd9432c175a4f3df88714eba91b7a41db5dea744154e063000d2e42
|
7
|
+
data.tar.gz: 0aeb6cfa54c5a55d6b822ce29e5045f78176b428bd2948fd039ea5dce5096d42a0d7dd6e8b04ce2c2631fb28bd02480f79e5c75fdb8a489e729f614ae191c428
|
data/lib/vete.rb
CHANGED
@@ -16,7 +16,7 @@ require "thread"
|
|
16
16
|
trap("INT" ) { print clear + go; abort "\n" }
|
17
17
|
|
18
18
|
OptionParser.new.instance_eval do
|
19
|
-
@version = "0.
|
19
|
+
@version = "0.2.0"
|
20
20
|
@banner = "usage: #{program_name} [options]"
|
21
21
|
|
22
22
|
on "-b", "--bar <width>" , "Progress bar width, in characters", Integer
|
@@ -30,10 +30,10 @@ OptionParser.new.instance_eval do
|
|
30
30
|
end.parse!(into: opts={}) rescue abort($!.message)
|
31
31
|
|
32
32
|
# populate CLI options
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
33
|
+
@char = opts[:char ] || "•"; @char = @char[0]
|
34
|
+
@nuke = opts[:reset ]
|
35
|
+
@wide = opts[:bar ] || 20
|
36
|
+
@work = opts[:workers] || 1
|
37
37
|
|
38
38
|
# define job directories
|
39
39
|
@vete = File.expand_path(".vete")
|
@@ -42,14 +42,34 @@ end.parse!(into: opts={}) rescue abort($!.message)
|
|
42
42
|
@done = File.join(@vete, "done")
|
43
43
|
@bomb = File.join(@vete, "bomb")
|
44
44
|
|
45
|
-
if @rmf
|
46
|
-
FileUtils.rm_rf @vete
|
47
|
-
exit
|
48
|
-
end
|
49
45
|
|
50
46
|
def move(path, dest)
|
51
47
|
dest = File.join(dest, File.basename(path))
|
52
|
-
FileUtils.mv(path, dest)
|
48
|
+
FileUtils.mv(path, dest, force: true, secure: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def nuke
|
52
|
+
FileUtils.rm_rf(@vete)
|
53
|
+
end
|
54
|
+
|
55
|
+
if @nuke
|
56
|
+
nuke
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
def vete_init
|
61
|
+
nuke
|
62
|
+
list = [@todo, @live, @done, @bomb]
|
63
|
+
list.each {|path| File.mkdir_p(path, force: true, secure: true) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def vete_retry
|
67
|
+
list = Dir.glob(File.join(@bomb, "*")).sort.each {|path| FileUtils.touch(path) }
|
68
|
+
move(list, @todo)
|
69
|
+
end
|
70
|
+
|
71
|
+
def vete_todo(path)
|
72
|
+
FileUtils.touch(path, force: true, secure: true)
|
53
73
|
end
|
54
74
|
|
55
75
|
# ==[ Drawing ]===============================================================
|
@@ -74,10 +94,10 @@ def draw(rows, done=0, live=0, bomb=0, jobs=0, info=nil)
|
|
74
94
|
unless info
|
75
95
|
print [
|
76
96
|
clear,
|
77
|
-
go(2 + rows, @len + 3) + "└" + "─" * (@
|
78
|
-
go(1 , @len + 3) + "┌" + "─" * (@
|
97
|
+
go(2 + rows, @len + 3) + "└" + "─" * (@wide + 2) + "┘\n",
|
98
|
+
go(1 , @len + 3) + "┌" + "─" * (@wide + 2) + "┐\n",
|
79
99
|
].join
|
80
|
-
rows.times {|i| print " %*d │ %*s │\n" % [@len, i + 1, @
|
100
|
+
rows.times {|i| print " %*d │ %*s │\n" % [@len, i + 1, @wide, ""] }
|
81
101
|
return
|
82
102
|
end
|
83
103
|
|
@@ -87,20 +107,20 @@ def draw(rows, done=0, live=0, bomb=0, jobs=0, info=nil)
|
|
87
107
|
most = info.values.max
|
88
108
|
info.each do |slot, this|
|
89
109
|
tpct = this.to_f / most
|
90
|
-
cols = dpct * tpct * @
|
91
|
-
print go(slot + 1, @len + 5) + bg("5383ec") + @
|
110
|
+
cols = dpct * tpct * @wide
|
111
|
+
print go(slot + 1, @len + 5) + bg("5383ec") + @char * cols
|
92
112
|
end
|
93
113
|
|
94
114
|
# summary bar
|
95
|
-
gcol = dpct * @
|
96
|
-
ycol = lpct * @
|
115
|
+
gcol = dpct * @wide
|
116
|
+
ycol = lpct * @wide
|
97
117
|
print [
|
98
118
|
go(rows + 3, @len + 5),
|
99
119
|
fg("fff"),
|
100
|
-
bg("58a65c") + @
|
101
|
-
bg("f1bf42") + @
|
102
|
-
bg("d85140") + " " * (@
|
103
|
-
go(rows + 3, @len + 5 + @
|
120
|
+
bg("58a65c") + @char * ( gcol ) , # green (done)
|
121
|
+
bg("f1bf42") + @char * ( ycol) , # yellow (live) <= Add live
|
122
|
+
bg("d85140") + " " * (@wide - gcol - ycol).ceil, # red (left)
|
123
|
+
go(rows + 3, @len + 5 + @wide + 3) + " %.1f%% done " % [dpct * 100],
|
104
124
|
bomb == 0 ? nil : (bg + " " + bg("f1bf42") + " #{bomb} bombed "),
|
105
125
|
].join
|
106
126
|
|
@@ -120,9 +140,9 @@ FileUtils.mkdir_p @bomb
|
|
120
140
|
|
121
141
|
# ==[ Configure workers ]=====================================================
|
122
142
|
|
123
|
-
@len = @
|
143
|
+
@len = @work.to_s.size
|
124
144
|
@mtx = Mutex.new
|
125
|
-
@que = Thread::Queue.new; @
|
145
|
+
@que = Thread::Queue.new; @work.times {|slot| @que << (slot + 1) }
|
126
146
|
|
127
147
|
begin
|
128
148
|
list = Dir[File.join(@todo, "*")]
|
@@ -132,7 +152,7 @@ begin
|
|
132
152
|
setup
|
133
153
|
|
134
154
|
cursor(false)
|
135
|
-
draw(@
|
155
|
+
draw(@work)
|
136
156
|
|
137
157
|
time = Time.now
|
138
158
|
done = 0
|
@@ -145,7 +165,7 @@ begin
|
|
145
165
|
live += 1
|
146
166
|
}
|
147
167
|
show = "Working on task " + File.basename(path)
|
148
|
-
print go(slot + 1, @len + 5 + @
|
168
|
+
print go(slot + 1, @len + 5 + @wide + 3) + show
|
149
169
|
if chld = fork # parent
|
150
170
|
Thread.new do
|
151
171
|
okay = Process.waitpid2(chld)[1] == 0
|
@@ -158,22 +178,22 @@ begin
|
|
158
178
|
info[slot] += 1
|
159
179
|
}
|
160
180
|
end
|
161
|
-
draw(@
|
181
|
+
draw(@work, done, live, bomb, jobs, info.dup)
|
162
182
|
else
|
163
183
|
perform(slot, path)
|
164
184
|
exit
|
165
185
|
end
|
166
186
|
end
|
167
187
|
end.join
|
168
|
-
draw(@
|
188
|
+
draw(@work, done, live, bomb, jobs, info)
|
169
189
|
secs = Time.now.to_f - time.to_f
|
170
190
|
|
171
191
|
# summary
|
172
192
|
print [
|
173
|
-
go(@
|
193
|
+
go(@work + 5, 1),
|
174
194
|
"%.2f secs" % secs,
|
175
195
|
" for #{jobs} jobs",
|
176
|
-
" by #{@
|
196
|
+
" by #{@work} workers",
|
177
197
|
" @ %.2f jobs/sec" % [jobs / secs]
|
178
198
|
].join + "\n\n"
|
179
199
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby CLI to spawn processes to get work done
|
14
14
|
email: steve.shreeve@gmail.com
|