scout-essentials 1.6.1 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vimproject +2 -0
- data/VERSION +1 -1
- data/lib/scout/annotation/array.rb +10 -0
- data/lib/scout/cmd.rb +4 -1
- data/lib/scout/concurrent_stream.rb +5 -1
- data/lib/scout/log.rb +1 -1
- data/lib/scout/misc/digest.rb +1 -9
- data/lib/scout/misc/format.rb +1 -3
- data/lib/scout/misc/helper.rb +12 -3
- data/lib/scout/misc/monitor.rb +1 -0
- data/lib/scout/named_array.rb +2 -2
- data/lib/scout/open/stream.rb +8 -3
- data/lib/scout/open/util.rb +7 -1
- data/lib/scout/open.rb +3 -3
- data/lib/scout/path/digest.rb +13 -0
- data/lib/scout/path.rb +1 -0
- data/lib/scout/persist/serialize.rb +2 -0
- data/scout-essentials.gemspec +5 -3
- data/test/scout/misc/test_helper.rb +5 -0
- data/test/scout/open/test_stream.rb +28 -0
- data/test/scout/open/test_util.rb +16 -1
- data/test/scout/path/test_digest.rb +20 -0
- data/test/scout/test_named_array.rb +6 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ff597b1b0d5a5a8582e92677aa951559d3ddf2f56cec76bbbfd5f0c90ea180e
|
4
|
+
data.tar.gz: 298441b06d0c2d048732fa7fb525a51c4ff93a31e39b1882211048f06978c1b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c63f92b747ea2c39b291430b8a63a7db63bf28465eb66b5d7cceda88f07ceaefef1c7718a589bd5f8f040ff082f9a90232edfa16d4c28a5ba75877ac5a34b9
|
7
|
+
data.tar.gz: 10d3e562974232b7fe87954a6970cc9008799e341d2bb01e454406d3ceec5386bb27542dcc8b6622a27fd5382d29320561766b1abfd0467eee939d7c82af0a84
|
data/.vimproject
CHANGED
@@ -50,6 +50,7 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
|
|
50
50
|
find.rb
|
51
51
|
tmpfile.rb
|
52
52
|
util.rb
|
53
|
+
digest.rb
|
53
54
|
}
|
54
55
|
concurrent_stream.rb
|
55
56
|
cmd.rb
|
@@ -59,6 +60,7 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
|
|
59
60
|
remote.rb
|
60
61
|
stream.rb
|
61
62
|
util.rb
|
63
|
+
bgzf.rb
|
62
64
|
}
|
63
65
|
resource.rb
|
64
66
|
resource=resource{
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.3
|
@@ -9,6 +9,7 @@ module AnnotatedArray
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def annotate_item(obj, position = nil)
|
12
|
+
return obj if obj.nil?
|
12
13
|
obj = obj.dup if obj.frozen?
|
13
14
|
obj.extend AnnotatedArray if Array === obj
|
14
15
|
obj.extend AnnotatedArrayItem
|
@@ -37,6 +38,15 @@ module AnnotatedArray
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
41
|
+
def select(&block)
|
42
|
+
selected = []
|
43
|
+
each do |item|
|
44
|
+
selected << item if block.call(item)
|
45
|
+
end
|
46
|
+
|
47
|
+
self.annotate(selected)
|
48
|
+
end
|
49
|
+
|
40
50
|
def each(&block)
|
41
51
|
i = 0
|
42
52
|
super do |item|
|
data/lib/scout/cmd.rb
CHANGED
@@ -51,7 +51,7 @@ module ConcurrentStream
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
stream.filename = filename
|
54
|
+
stream.filename = filename if filename
|
55
55
|
|
56
56
|
stream.lock = lock unless lock.nil?
|
57
57
|
|
@@ -60,6 +60,10 @@ module ConcurrentStream
|
|
60
60
|
stream
|
61
61
|
end
|
62
62
|
|
63
|
+
def filename
|
64
|
+
@filename || self.inspect.split(":").last[0..-2]
|
65
|
+
end
|
66
|
+
|
63
67
|
def annotate(stream)
|
64
68
|
ConcurrentStream.setup(stream, :threads => threads, :pids => pids, :callback => callback, :abort_callback => abort_callback, :filename => filename, :autojoin => autojoin, :lock => lock)
|
65
69
|
stream
|
data/lib/scout/log.rb
CHANGED
data/lib/scout/misc/digest.rb
CHANGED
@@ -1,19 +1,11 @@
|
|
1
1
|
module Misc
|
2
2
|
MAX_ARRAY_DIGEST_LENGTH = 100_000
|
3
|
+
|
3
4
|
def self.digest_str(obj)
|
4
5
|
if obj.respond_to?(:digest_str)
|
5
6
|
obj.digest_str
|
6
7
|
else
|
7
8
|
case obj
|
8
|
-
when Path
|
9
|
-
case
|
10
|
-
when File.directory?(obj)
|
11
|
-
"Directory MD5: #{digest_str(Dir.glob(File.join(obj, "*")))}"
|
12
|
-
when obj.located? && File.exist?(obj)
|
13
|
-
"File MD5: #{Misc.digest_file(obj)}"
|
14
|
-
else
|
15
|
-
'\'' << obj << '\''
|
16
|
-
end
|
17
9
|
when String
|
18
10
|
if Path.is_filename?(obj) && Open.exists?(obj)
|
19
11
|
if File.directory?(obj)
|
data/lib/scout/misc/format.rb
CHANGED
@@ -36,9 +36,7 @@ module Misc
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
MAX_TTY_LINE_WIDTH = 100
|
39
|
+
MAX_TTY_LINE_WIDTH = 160
|
42
40
|
def self.format_paragraph(text, size = nil, indent = nil, offset = nil)
|
43
41
|
size ||= Log.tty_size || MAX_TTY_LINE_WIDTH
|
44
42
|
size = MAX_TTY_LINE_WIDTH if size > MAX_TTY_LINE_WIDTH
|
data/lib/scout/misc/helper.rb
CHANGED
@@ -28,14 +28,23 @@ module Misc
|
|
28
28
|
counts
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
# Divides the array into chunks of size +size+ by taking
|
32
|
+
# consecutive elements. If a block is given it runs it
|
33
|
+
# instead of returning the chunks
|
34
|
+
def self.chunk(array, size)
|
32
35
|
total = array.length
|
33
36
|
current = 0
|
37
|
+
res = [] unless block_given?
|
34
38
|
while current < total
|
35
|
-
last = current +
|
36
|
-
|
39
|
+
last = current + size - 1
|
40
|
+
if block_given?
|
41
|
+
yield array[current..last]
|
42
|
+
else
|
43
|
+
res << array[current..last]
|
44
|
+
end
|
37
45
|
current = last + 1
|
38
46
|
end
|
47
|
+
block_given? ? nil : res
|
39
48
|
end
|
40
49
|
|
41
50
|
# Divides the array into +num+ chunks of the same size by placing one
|
data/lib/scout/misc/monitor.rb
CHANGED
data/lib/scout/named_array.rb
CHANGED
data/lib/scout/open/stream.rb
CHANGED
@@ -440,7 +440,7 @@ module Open
|
|
440
440
|
# StringIO.new stream.read.split("\n").sort.uniq * "\n"
|
441
441
|
#end
|
442
442
|
|
443
|
-
def self.collapse_stream(s, line: nil, sep: "\t", header: nil, &block)
|
443
|
+
def self.collapse_stream(s, line: nil, sep: "\t", header: nil, compact: false, &block)
|
444
444
|
sep ||= "\t"
|
445
445
|
Open.open_pipe do |sin|
|
446
446
|
|
@@ -458,8 +458,13 @@ module Open
|
|
458
458
|
current_key = key
|
459
459
|
when current_key == key
|
460
460
|
parts.each_with_index do |part,i|
|
461
|
-
if
|
462
|
-
|
461
|
+
next if compact and part.nil? || part.empty?
|
462
|
+
if current_parts[i].nil? || current_parts[i].empty?
|
463
|
+
if compact
|
464
|
+
current_parts[i] = part.dup
|
465
|
+
else
|
466
|
+
current_parts[i] = "|" << part
|
467
|
+
end
|
463
468
|
else
|
464
469
|
current_parts[i] = current_parts[i] << "|" << part
|
465
470
|
end
|
data/lib/scout/open/util.rb
CHANGED
@@ -11,7 +11,7 @@ module Open
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.grep(stream, grep, invert = false, fixed = nil)
|
14
|
+
def self.grep(stream, grep, invert = false, fixed = nil, options = {})
|
15
15
|
case
|
16
16
|
when Array === grep
|
17
17
|
TmpFile.with_file(grep * "\n", false) do |f|
|
@@ -236,11 +236,17 @@ module Open
|
|
236
236
|
begin
|
237
237
|
Open.ln(source, target, options)
|
238
238
|
rescue
|
239
|
+
Log.debug "Could not make regular link, trying symbolic: #{Misc.fingerprint(source)} -> #{Misc.fingerprint(target)}"
|
239
240
|
Open.ln_s(source, target, options)
|
240
241
|
end
|
241
242
|
nil
|
242
243
|
end
|
243
244
|
|
245
|
+
def self.link_dir(source, target)
|
246
|
+
Log.debug "Copy with hard-links #{Log.fingerprint source}->#{Log.fingerprint target}"
|
247
|
+
FileUtils.cp_lr(source, target)
|
248
|
+
end
|
249
|
+
|
244
250
|
def self.list(file)
|
245
251
|
file = file.produce_and_find if Path === file
|
246
252
|
Open.read(file).split("\n")
|
data/lib/scout/open.rb
CHANGED
@@ -31,13 +31,13 @@ module Open
|
|
31
31
|
File.open(file, mode)
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.file_open(file, grep = false, mode = 'r', invert_grep = false, options = {})
|
34
|
+
def self.file_open(file, grep = false, mode = 'r', invert_grep = false, fixed_grep = true, options = {})
|
35
35
|
Open.mkdir File.dirname(file) if mode.include? 'w'
|
36
36
|
|
37
37
|
stream = get_stream(file, mode, options)
|
38
38
|
|
39
39
|
if grep
|
40
|
-
grep(stream, grep, invert_grep)
|
40
|
+
grep(stream, grep, invert_grep, fixed_grep)
|
41
41
|
else
|
42
42
|
stream
|
43
43
|
end
|
@@ -72,7 +72,7 @@ module Open
|
|
72
72
|
|
73
73
|
options[:noz] = true if mode.include? "w"
|
74
74
|
|
75
|
-
io = file_open(file, options[:grep], mode, options[:invert_grep], options)
|
75
|
+
io = file_open(file, options[:grep], mode, options[:invert_grep], options[:fixed_grep], options)
|
76
76
|
|
77
77
|
io = unzip(io) if ((String === file and zip?(file)) and not options[:noz]) or options[:zip]
|
78
78
|
io = gunzip(io) if ((String === file and gzip?(file)) and not options[:noz]) or options[:gzip]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../misc/digest'
|
2
|
+
module Path
|
3
|
+
def digest_str
|
4
|
+
case
|
5
|
+
when File.directory?(self)
|
6
|
+
"Directory MD5: #{Misc.digest_str(Dir.glob(File.join(self, "*")))}"
|
7
|
+
when self.located? && File.exist?(self)
|
8
|
+
"File MD5: #{Misc.digest_file(self)}"
|
9
|
+
else
|
10
|
+
'\'' << self << '\''
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/scout/path.rb
CHANGED
data/scout-essentials.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: scout-essentials 1.6.
|
5
|
+
# stub: scout-essentials 1.6.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "scout-essentials".freeze
|
9
|
-
s.version = "1.6.
|
9
|
+
s.version = "1.6.3".freeze
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Miguel Vazquez".freeze]
|
14
|
-
s.date = "2024-
|
14
|
+
s.date = "2024-10-04"
|
15
15
|
s.description = "Things a scout can use anywhere".freeze
|
16
16
|
s.email = "mikisvaz@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
"lib/scout/open/stream.rb",
|
64
64
|
"lib/scout/open/util.rb",
|
65
65
|
"lib/scout/path.rb",
|
66
|
+
"lib/scout/path/digest.rb",
|
66
67
|
"lib/scout/path/find.rb",
|
67
68
|
"lib/scout/path/tmpfile.rb",
|
68
69
|
"lib/scout/path/util.rb",
|
@@ -106,6 +107,7 @@ Gem::Specification.new do |s|
|
|
106
107
|
"test/scout/open/test_remote.rb",
|
107
108
|
"test/scout/open/test_stream.rb",
|
108
109
|
"test/scout/open/test_util.rb",
|
110
|
+
"test/scout/path/test_digest.rb",
|
109
111
|
"test/scout/path/test_find.rb",
|
110
112
|
"test/scout/path/test_util.rb",
|
111
113
|
"test/scout/persist/test_open.rb",
|
@@ -6,6 +6,11 @@ class TestMiscHelper < Test::Unit::TestCase
|
|
6
6
|
assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_chunk
|
10
|
+
assert_equal %w(1 2), Misc.chunk(%w(1 2 3 4 5 6 7 8 9),2)[0]
|
11
|
+
end
|
12
|
+
|
13
|
+
|
9
14
|
def test_ordered_divide
|
10
15
|
assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
11
16
|
end
|
@@ -393,6 +393,34 @@ row2 aa bb cc
|
|
393
393
|
s = StringIO.new text
|
394
394
|
assert Open.collapse_stream(s, sep: " ").read =~ /\|cc$/
|
395
395
|
end
|
396
|
+
|
397
|
+
def test_collapse_stream_compact
|
398
|
+
text=<<-EOF
|
399
|
+
row1 A B C
|
400
|
+
row1 a b c
|
401
|
+
row2 BB CC
|
402
|
+
row2 aa bb cc
|
403
|
+
row2 aaa ccc
|
404
|
+
EOF
|
405
|
+
|
406
|
+
s = StringIO.new text
|
407
|
+
stream = Open.collapse_stream(s, sep: "\t", compact: false)
|
408
|
+
txt = stream.read
|
409
|
+
assert_include txt, "A|a"
|
410
|
+
assert_include txt, "B|b"
|
411
|
+
assert_include txt, "C|c"
|
412
|
+
assert_include txt, "|aa"
|
413
|
+
|
414
|
+
s = StringIO.new text
|
415
|
+
stream = Open.collapse_stream(s, sep: "\t", compact: true)
|
416
|
+
txt = stream.read
|
417
|
+
assert_include txt, "A|a"
|
418
|
+
assert_include txt, "B|b"
|
419
|
+
assert_include txt, "C|c"
|
420
|
+
assert_not_include txt, "|aa\t"
|
421
|
+
assert_not_include txt, "bb|"
|
422
|
+
end
|
423
|
+
|
396
424
|
#
|
397
425
|
#
|
398
426
|
# def test_paste_stream
|
@@ -63,10 +63,25 @@ class TestOpenUtil < Test::Unit::TestCase
|
|
63
63
|
file1 = directory.subdir1.file
|
64
64
|
file2 = directory.subdir2.file
|
65
65
|
Open.write(file1, "TEST")
|
66
|
-
Open.
|
66
|
+
Open.ln_h file1, file2
|
67
|
+
assert_equal "TEST", Open.read(file2)
|
68
|
+
Open.write(file1, "TEST2")
|
69
|
+
assert_equal "TEST2", Open.read(file2)
|
70
|
+
assert_equal File.stat(file1).ino, File.stat(file2).ino
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_ln_recursive
|
75
|
+
TmpFile.with_file do |directory|
|
76
|
+
Path.setup(directory)
|
77
|
+
file1 = directory.subdir1.file
|
78
|
+
file2 = directory.subdir2.file
|
79
|
+
Open.write(file1, "TEST")
|
80
|
+
Open.link_dir directory.subdir1, directory.subdir2
|
67
81
|
assert_equal "TEST", Open.read(file2)
|
68
82
|
Open.write(file1, "TEST2")
|
69
83
|
assert_equal "TEST2", Open.read(file2)
|
84
|
+
assert_equal File.stat(file1).ino, File.stat(file2).ino
|
70
85
|
end
|
71
86
|
end
|
72
87
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
|
+
|
4
|
+
class TestClass < Test::Unit::TestCase
|
5
|
+
def test_digest_path
|
6
|
+
TmpFile.with_path("TEXT") do |file|
|
7
|
+
assert_include file.digest_str, "File MD5"
|
8
|
+
end
|
9
|
+
|
10
|
+
TmpFile.with_path do |dir|
|
11
|
+
Open.write(dir.test, "TEXT")
|
12
|
+
assert_include dir.digest_str, "Directory"
|
13
|
+
end
|
14
|
+
|
15
|
+
TmpFile.with_path do |file|
|
16
|
+
assert_include "'#{file}'", file.digest_str
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/scout/open/stream.rb
|
161
161
|
- lib/scout/open/util.rb
|
162
162
|
- lib/scout/path.rb
|
163
|
+
- lib/scout/path/digest.rb
|
163
164
|
- lib/scout/path/find.rb
|
164
165
|
- lib/scout/path/tmpfile.rb
|
165
166
|
- lib/scout/path/util.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- test/scout/open/test_remote.rb
|
204
205
|
- test/scout/open/test_stream.rb
|
205
206
|
- test/scout/open/test_util.rb
|
207
|
+
- test/scout/path/test_digest.rb
|
206
208
|
- test/scout/path/test_find.rb
|
207
209
|
- test/scout/path/test_util.rb
|
208
210
|
- test/scout/persist/test_open.rb
|