scout-essentials 1.6.2 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a682bf691d2d27784726f6eb108223abc0cc62a3a289f5580ef3ec9a850daffa
4
- data.tar.gz: ac4409c3954aeaa68bfb45844de8701c265b3e896fbe77bb51dfae953ad47035
3
+ metadata.gz: 733fb62cfc8f1119cc35567f30bec3f569856a2c10e7fa4ab8dcb54fb39cf737
4
+ data.tar.gz: abc7a2a0ffa9c524da167c1f2132efb557a6ebd7debe267e014bba1269a31661
5
5
  SHA512:
6
- metadata.gz: a9db53026e267d734499b85a2673933c43a7e549497fa76420872dff237fb2858da535fcd654c30153f5b78e4afc9568b884db0ca656f70f1a936d89cff570ab
7
- data.tar.gz: 6868e8baf1d445bfc2aeebee9a0e0cb0c0f9e481e41ef87f3c670d2f9b628445fb8502b7a27a39decb445dabd4ff571145562f16fd0b477ae426d63e1a23d61b
6
+ metadata.gz: cdd5c50d28fa8ffac0c5f1660ab5ff8b0e63c3df7d27966cb98c78928161c78270b3bab72732c5eeb5c37a1824fc101fdb2b569567b3af977404f540fb5912de
7
+ data.tar.gz: c4f4e5f5f7b276d20ea65ef22d8447c0499606a3b9c590768517808f6f226c137361b38f1dc56c5e90f2a7652d8519f9cfc591438f939ed2345de2c999f05139
data/.vimproject CHANGED
@@ -34,6 +34,11 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
34
34
  color_class.rb
35
35
  fingerprint.rb
36
36
  progress.rb
37
+ progress=progress{
38
+ report.rb
39
+ util.rb
40
+ }
41
+
37
42
  trap.rb
38
43
  }
39
44
  tmpfile.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.2
1
+ 1.6.4
@@ -34,7 +34,11 @@ module Annotation
34
34
  end
35
35
  obj = block if obj.nil?
36
36
  return nil if obj.nil?
37
- obj.extend self unless self === obj
37
+ begin
38
+ obj.extend self unless self === obj
39
+ rescue TypeError
40
+ return obj
41
+ end
38
42
  attrs = self.instance_variable_get("@annotations")
39
43
 
40
44
  return obj if attrs.nil? || attrs.empty?
@@ -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
@@ -33,8 +34,17 @@ module AnnotatedArray
33
34
 
34
35
  def each_with_index(&block)
35
36
  super do |item,i|
36
- block.call annotate_item(item, i)
37
+ block.call annotate_item(item, i), i
38
+ end
39
+ end
40
+
41
+ def select(&block)
42
+ selected = []
43
+ each do |item|
44
+ selected << item if block.call(item)
37
45
  end
46
+
47
+ self.annotate(selected)
38
48
  end
39
49
 
40
50
  def each(&block)
@@ -60,6 +70,14 @@ module AnnotatedArray
60
70
  end
61
71
  end
62
72
 
73
+ def subset(list)
74
+ self.annotate(self & list)
75
+ end
76
+
77
+ def remove(list)
78
+ self.annotate(self - list)
79
+ end
80
+
63
81
  %w(compact uniq flatten reverse sort_by).each do |method|
64
82
 
65
83
  self.define_method(method) do |*args,&block|
data/lib/scout/cmd.rb CHANGED
@@ -41,7 +41,10 @@ module CMD
41
41
  if claim
42
42
  claim.produce
43
43
  else
44
- block.call
44
+ res = block.call
45
+ if Hash === res
46
+ Resource.install res, tool.to_s
47
+ end
45
48
  end
46
49
  end
47
50
  version_txt = ""
@@ -51,7 +51,7 @@ module ConcurrentStream
51
51
  end
52
52
  end
53
53
 
54
- stream.filename = filename.nil? ? stream.inspect.split(":").last[0..-2] : 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
@@ -92,5 +92,12 @@ module IndiferentHash
92
92
  end
93
93
  IndiferentHash.setup(super(*ext_list))
94
94
  end
95
+
96
+ def keys_to_sym!
97
+ string_keys = keys.select{|k| String === k}
98
+ string_keys.each do |key|
99
+ self[key.to_sym] = self.delete(key)
100
+ end
101
+ end
95
102
  end
96
103
 
data/lib/scout/log.rb CHANGED
@@ -146,7 +146,7 @@ module Log
146
146
  else
147
147
  begin
148
148
  STDERR.write str
149
- rescue
149
+ rescue IOError
150
150
  end
151
151
  end
152
152
  end
@@ -252,14 +252,18 @@ module Log
252
252
  end
253
253
 
254
254
  def self.exception(e)
255
- stack = caller
255
+ return if e.message.include?("NOLOG")
256
+ last_caller = last_caller caller
257
+ message = e.message
258
+ message = Log.fingerprint(message) if String === message && message.length > 1000
256
259
  backtrace = e.backtrace || []
260
+ backtrace = [] if message.include?("NOSTACK")
257
261
  if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
258
- error([e.class.to_s, e.message].compact * ": " )
259
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace)*"\n")
262
+ error([e.class.to_s, message].compact * ": " )
263
+ error("BACKTRACE [#{Process.pid}]: " << last_caller << "\n" + color_stack(backtrace)*"\n")
260
264
  else
261
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace.reverse)*"\n")
262
- error([e.class.to_s, e.message].compact * ": " )
265
+ error("BACKTRACE [#{Process.pid}]: " << last_caller << "\n" + color_stack(backtrace.reverse)*"\n")
266
+ error([e.class.to_s, message].compact * ": " )
263
267
  end
264
268
  end
265
269
 
@@ -355,6 +359,7 @@ def ppp(message)
355
359
  stack = caller
356
360
  puts "#{Log.color :cyan, "PRINT:"} " << stack.first
357
361
  puts ""
362
+ message = message.prety_print if message.respond_to?(:prety_print)
358
363
  if message.length > 200 or message.include? "\n"
359
364
  puts Log.color(:cyan, "=>|") << "\n" << message.to_s
360
365
  else
@@ -6,15 +6,6 @@ module Misc
6
6
  obj.digest_str
7
7
  else
8
8
  case obj
9
- when Path
10
- case
11
- when File.directory?(obj)
12
- "Directory MD5: #{digest_str(Dir.glob(File.join(obj, "*")))}"
13
- when obj.located? && File.exist?(obj)
14
- "File MD5: #{Misc.digest_file(obj)}"
15
- else
16
- '\'' << obj << '\''
17
- end
18
9
  when String
19
10
  if Path.is_filename?(obj) && Open.exists?(obj)
20
11
  if File.directory?(obj)
@@ -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
@@ -74,7 +72,7 @@ module Misc
74
72
  end*""
75
73
  end
76
74
 
77
- def self.format_definition_list_item(dt, dd, indent = nil, size = nil, color = :yellow)
75
+ def self.format_definition_list_item(dt, dd, indent = nil, size = nil, color: :yellow)
78
76
  if size.nil?
79
77
  base_size = MAX_TTY_LINE_WIDTH
80
78
  base_indent = indent || (base_size / 3)
@@ -100,12 +98,12 @@ module Misc
100
98
  text
101
99
  end
102
100
 
103
- def self.format_definition_list(defs, indent = nil, size = nil, color = :yellow, sep = "\n\n")
101
+ def self.format_definition_list(defs, indent = nil, size = nil, color: :yellow, sep: "\n\n")
104
102
  indent ||= 30
105
103
  size ||= (Log.tty_size || MAX_TTY_LINE_WIDTH) - indent
106
104
  entries = []
107
105
  defs.each do |dt,dd|
108
- text = format_definition_list_item(dt,dd,indent, size,color)
106
+ text = format_definition_list_item(dt,dd,indent, size, color: color)
109
107
  entries << text
110
108
  end
111
109
  entries * sep
@@ -28,14 +28,23 @@ module Misc
28
28
  counts
29
29
  end
30
30
 
31
- def self.chunk(array, num)
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 + num - 1
36
- yield array[current..last]
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
@@ -100,8 +100,8 @@ module NamedArray
100
100
 
101
101
  def to_hash
102
102
  hash = {}
103
- self.fields.zip(self) do |field,value|
104
- hash[field] = value
103
+ self.fields.each do |field|
104
+ hash[field] = self[field]
105
105
  end
106
106
  IndiferentHash.setup hash
107
107
  end
@@ -158,4 +158,8 @@ module NamedArray
158
158
  return super(name, *args)
159
159
  end
160
160
  end
161
+
162
+ def prety_print
163
+ Misc.format_definition_list(self.to_hash, sep: "\n")
164
+ end
161
165
  end
@@ -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 current_parts[i].nil?
462
- current_parts[i] = "|" << part
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
@@ -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|
@@ -242,6 +242,11 @@ module Open
242
242
  nil
243
243
  end
244
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
+
245
250
  def self.list(file)
246
251
  file = file.produce_and_find if Path === file
247
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
@@ -68,11 +68,11 @@ module Open
68
68
 
69
69
  options = IndiferentHash.add_defaults options, :noz => false, :mode => 'r'
70
70
 
71
- mode = IndiferentHash.process_options options, :mode
71
+ mode, grep, invert_grep, fixed_grep = IndiferentHash.process_options options, :mode, :grep, :invert_grep, :fixed_grep
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, grep, mode, invert_grep, 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]
@@ -145,6 +145,8 @@ module Persist
145
145
  Open.marshal(file)
146
146
  when :stream
147
147
  Open.open(file)
148
+ when :path
149
+ Path === file ? file : Path.setup(file)
148
150
  when :file
149
151
  value = Open.read(file)
150
152
  value.sub!(/^\./, File.dirname(file)) if value.start_with?("./")
@@ -34,6 +34,7 @@ module Resource
34
34
  rake_dir = rake_dir.find(:user) if rake_dir.respond_to? :find
35
35
 
36
36
  begin
37
+ Thread.current["resource"] = self
37
38
  if Proc === rakefile
38
39
  ScoutRake.run(nil, rake_dir, task, &rakefile)
39
40
  else
data/lib/scout/tmpfile.rb CHANGED
@@ -31,6 +31,7 @@ module TmpFile
31
31
  # Creates a random filename in the temporary directory
32
32
  def self.tmp_file(prefix = 'tmp-', max = 1_000_000_000, dir = nil)
33
33
  dir ||= TmpFile.tmpdir
34
+ dir = dir.find if Path === dir
34
35
  File.expand_path(File.join(dir, random_name(prefix, max)))
35
36
  end
36
37
 
@@ -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.2 ruby lib
5
+ # stub: scout-essentials 1.6.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-essentials".freeze
9
- s.version = "1.6.2".freeze
9
+ s.version = "1.6.4".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-07-01"
14
+ s.date = "2024-12-10"
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 = [
@@ -138,7 +138,7 @@ Gem::Specification.new do |s|
138
138
  ]
139
139
  s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
140
140
  s.licenses = ["MIT".freeze]
141
- s.rubygems_version = "3.5.10".freeze
141
+ s.rubygems_version = "3.5.23".freeze
142
142
  s.summary = "Scout essential tools".freeze
143
143
 
144
144
  s.specification_version = 4
@@ -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.ln_s file1, file2
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
@@ -39,5 +39,10 @@ ValueB (Entity type)
39
39
  assert_equal 1, a.a
40
40
  assert_equal 2, a.b
41
41
  end
42
- end
43
42
 
43
+ def test_to_hash
44
+ a = NamedArray.setup([1,2], [:a, :b])
45
+ assert_equal 1, a.to_hash[:a]
46
+ assert_equal 2, a.to_hash[:b]
47
+ end
48
+ end
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.2
4
+ version: 1.6.4
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-07-01 00:00:00.000000000 Z
11
+ date: 2024-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  - !ruby/object:Gem::Version
252
252
  version: '0'
253
253
  requirements: []
254
- rubygems_version: 3.5.10
254
+ rubygems_version: 3.5.23
255
255
  signing_key:
256
256
  specification_version: 4
257
257
  summary: Scout essential tools