scout-essentials 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.vimproject +78 -0
  4. data/Gemfile +14 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +18 -0
  7. data/Rakefile +47 -0
  8. data/VERSION +1 -0
  9. data/lib/scout/cmd.rb +348 -0
  10. data/lib/scout/concurrent_stream.rb +284 -0
  11. data/lib/scout/config.rb +168 -0
  12. data/lib/scout/exceptions.rb +77 -0
  13. data/lib/scout/indiferent_hash/case_insensitive.rb +30 -0
  14. data/lib/scout/indiferent_hash/options.rb +115 -0
  15. data/lib/scout/indiferent_hash.rb +96 -0
  16. data/lib/scout/log/color.rb +224 -0
  17. data/lib/scout/log/color_class.rb +269 -0
  18. data/lib/scout/log/fingerprint.rb +69 -0
  19. data/lib/scout/log/progress/report.rb +244 -0
  20. data/lib/scout/log/progress/util.rb +173 -0
  21. data/lib/scout/log/progress.rb +106 -0
  22. data/lib/scout/log/trap.rb +107 -0
  23. data/lib/scout/log.rb +441 -0
  24. data/lib/scout/meta_extension.rb +100 -0
  25. data/lib/scout/misc/digest.rb +63 -0
  26. data/lib/scout/misc/filesystem.rb +25 -0
  27. data/lib/scout/misc/format.rb +255 -0
  28. data/lib/scout/misc/helper.rb +31 -0
  29. data/lib/scout/misc/insist.rb +56 -0
  30. data/lib/scout/misc/monitor.rb +66 -0
  31. data/lib/scout/misc/system.rb +73 -0
  32. data/lib/scout/misc.rb +10 -0
  33. data/lib/scout/named_array.rb +138 -0
  34. data/lib/scout/open/lock/lockfile.rb +587 -0
  35. data/lib/scout/open/lock.rb +68 -0
  36. data/lib/scout/open/remote.rb +135 -0
  37. data/lib/scout/open/stream.rb +491 -0
  38. data/lib/scout/open/util.rb +244 -0
  39. data/lib/scout/open.rb +170 -0
  40. data/lib/scout/path/find.rb +204 -0
  41. data/lib/scout/path/tmpfile.rb +8 -0
  42. data/lib/scout/path/util.rb +127 -0
  43. data/lib/scout/path.rb +51 -0
  44. data/lib/scout/persist/open.rb +17 -0
  45. data/lib/scout/persist/path.rb +15 -0
  46. data/lib/scout/persist/serialize.rb +157 -0
  47. data/lib/scout/persist.rb +104 -0
  48. data/lib/scout/resource/open.rb +8 -0
  49. data/lib/scout/resource/path.rb +80 -0
  50. data/lib/scout/resource/produce/rake.rb +69 -0
  51. data/lib/scout/resource/produce.rb +151 -0
  52. data/lib/scout/resource/scout.rb +3 -0
  53. data/lib/scout/resource/software.rb +178 -0
  54. data/lib/scout/resource/util.rb +59 -0
  55. data/lib/scout/resource.rb +40 -0
  56. data/lib/scout/simple_opt/accessor.rb +54 -0
  57. data/lib/scout/simple_opt/doc.rb +126 -0
  58. data/lib/scout/simple_opt/get.rb +57 -0
  59. data/lib/scout/simple_opt/parse.rb +67 -0
  60. data/lib/scout/simple_opt/setup.rb +26 -0
  61. data/lib/scout/simple_opt.rb +5 -0
  62. data/lib/scout/tmpfile.rb +129 -0
  63. data/lib/scout-essentials.rb +10 -0
  64. data/scout-essentials.gemspec +143 -0
  65. data/share/color/color_names +507 -0
  66. data/share/color/diverging_colors.hex +12 -0
  67. data/share/software/install_helpers +523 -0
  68. data/test/scout/indiferent_hash/test_case_insensitive.rb +16 -0
  69. data/test/scout/indiferent_hash/test_options.rb +46 -0
  70. data/test/scout/log/test_color.rb +0 -0
  71. data/test/scout/log/test_progress.rb +108 -0
  72. data/test/scout/misc/test_digest.rb +30 -0
  73. data/test/scout/misc/test_filesystem.rb +30 -0
  74. data/test/scout/misc/test_insist.rb +13 -0
  75. data/test/scout/misc/test_system.rb +21 -0
  76. data/test/scout/open/test_lock.rb +52 -0
  77. data/test/scout/open/test_remote.rb +25 -0
  78. data/test/scout/open/test_stream.rb +676 -0
  79. data/test/scout/open/test_util.rb +73 -0
  80. data/test/scout/path/test_find.rb +110 -0
  81. data/test/scout/path/test_util.rb +22 -0
  82. data/test/scout/persist/test_open.rb +37 -0
  83. data/test/scout/persist/test_path.rb +37 -0
  84. data/test/scout/persist/test_serialize.rb +114 -0
  85. data/test/scout/resource/test_path.rb +58 -0
  86. data/test/scout/resource/test_produce.rb +94 -0
  87. data/test/scout/resource/test_software.rb +24 -0
  88. data/test/scout/resource/test_util.rb +38 -0
  89. data/test/scout/simple_opt/test_doc.rb +16 -0
  90. data/test/scout/simple_opt/test_get.rb +11 -0
  91. data/test/scout/simple_opt/test_parse.rb +10 -0
  92. data/test/scout/simple_opt/test_setup.rb +77 -0
  93. data/test/scout/test_cmd.rb +85 -0
  94. data/test/scout/test_concurrent_stream.rb +29 -0
  95. data/test/scout/test_config.rb +66 -0
  96. data/test/scout/test_indiferent_hash.rb +26 -0
  97. data/test/scout/test_log.rb +32 -0
  98. data/test/scout/test_meta_extension.rb +80 -0
  99. data/test/scout/test_misc.rb +6 -0
  100. data/test/scout/test_named_array.rb +43 -0
  101. data/test/scout/test_open.rb +146 -0
  102. data/test/scout/test_path.rb +54 -0
  103. data/test/scout/test_persist.rb +186 -0
  104. data/test/scout/test_resource.rb +26 -0
  105. data/test/scout/test_tmpfile.rb +53 -0
  106. data/test/test_helper.rb +50 -0
  107. metadata +247 -0
@@ -0,0 +1,67 @@
1
+ module SOPT
2
+ def self.fix_shortcut(short, long)
3
+ return short unless short and shortcuts.include?(short)
4
+
5
+ current = shortcuts.select{|s,l| l == long}.collect{|s,l| s }.first
6
+ return current if current
7
+
8
+ chars = long.chars.to_a
9
+ current = [chars.shift]
10
+ short = current * ""
11
+
12
+ if (shortcuts.include?(short) and not shortcuts[short] == long)
13
+ if long.index "-" or long.index "_"
14
+ parts = long.split(/[_-]/)
15
+ acc = parts.collect{|s| s[0] } * ""
16
+ return acc unless shortcuts.include? acc
17
+ elsif m = long.match(/(\d+)/)
18
+ n = m[0]
19
+ acc = long[0] + n
20
+ return acc unless shortcuts.include? acc
21
+ end
22
+ end
23
+
24
+ while shortcuts.include?(short) && shortcuts[short] != long
25
+ next_letter = chars.shift
26
+ next_letter = chars.shift while %w(. - _).include?(next_letter)
27
+ return nil if next_letter.nil?
28
+ current << next_letter
29
+ short = current * ""
30
+ end
31
+
32
+ return nil if shortcuts.include? short
33
+
34
+ short
35
+ end
36
+
37
+ def self.register(short, long, asterisk, description)
38
+ short = fix_shortcut(short, long)
39
+ shortcuts[short] = long if short
40
+ inputs << long
41
+ input_shortcuts[long] = short
42
+ input_descriptions[long] = description
43
+ input_types[long] = asterisk ? :string : :boolean
44
+ end
45
+
46
+ def self.parse(opt_str)
47
+ inputs = []
48
+
49
+ if opt_str.include? "\n"
50
+ re = /\n+/
51
+ else
52
+ re = /:/
53
+ end
54
+
55
+ opt_str.split(re).each do |entry|
56
+ entry.strip!
57
+ next if entry.empty?
58
+ names, _sep, description = entry.partition(/\s+/)
59
+ short, long, asterisk = names.match(/\s*(?:-(.+))?(?:--(.+?))([*])?$/).values_at 1,2,3
60
+
61
+ inputs << long
62
+ register short, long, asterisk, description
63
+ end
64
+
65
+ inputs
66
+ end
67
+ end
@@ -0,0 +1,26 @@
1
+ module SOPT
2
+
3
+ def self.setup(str)
4
+ parts = str.split(/\n\n+/)
5
+
6
+ summary = parts.shift unless parts.first =~ /^\s*\$-/
7
+ synopsys = parts.shift if parts.first =~ /^\s*\$/
8
+
9
+ description = []
10
+ while parts.first and parts.first !~ /^\s*-/
11
+ description << parts.shift
12
+ end
13
+ description = description * "\n\n"
14
+
15
+ options = parts.collect{|part| part.split("\n").select{|l| l=~ /^\s*-/ } }.flatten.compact * "\n"
16
+
17
+ synopsys.sub!(/^\$\s+/,'') if synopsys
18
+
19
+ SOPT.summary = summary.strip if summary
20
+ SOPT.synopsys = synopsys.strip if synopsys
21
+ SOPT.description = description.strip if description
22
+ SOPT.parse options if options
23
+
24
+ SOPT.consume
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'simple_opt/accessor'
2
+ require_relative 'simple_opt/parse'
3
+ require_relative 'simple_opt/doc'
4
+ require_relative 'simple_opt/get'
5
+ require_relative 'simple_opt/setup'
@@ -0,0 +1,129 @@
1
+ require_relative 'misc'
2
+ require_relative 'log'
3
+ require 'fileutils'
4
+
5
+ module TmpFile
6
+ MAX_FILE_LENGTH = 150
7
+
8
+ def self.user_tmp(subdir = nil)
9
+ if subdir
10
+ File.join(ENV["HOME"],"/tmp/scout", subdir)
11
+ else
12
+ File.join(ENV["HOME"],"/tmp/scout")
13
+ end
14
+ end
15
+
16
+ def self.tmpdir=(tmpdir)
17
+ @tmpdir = tmpdir
18
+ end
19
+
20
+ def self.tmpdir
21
+ @tmpdir ||= self.user_tmp('tmpfiles')
22
+ end
23
+
24
+ # Creates a random file name, with the given suffix and a random number
25
+ # up to +max+
26
+ def self.random_name(prefix = 'tmp-', max = 1_000_000_000)
27
+ n = rand(max)
28
+ prefix + n.to_s
29
+ end
30
+
31
+ # Creates a random filename in the temporary directory
32
+ def self.tmp_file(prefix = 'tmp-', max = 1_000_000_000, dir = nil)
33
+ dir ||= TmpFile.tmpdir
34
+ File.expand_path(File.join(dir, random_name(prefix, max)))
35
+ end
36
+
37
+ def self.with_file(content = nil, erase = true, options = {})
38
+ if content.is_a?(Hash)
39
+ options = content
40
+ content = nil
41
+ erase = true
42
+ end
43
+ if erase.is_a?(Hash)
44
+ options = erase
45
+ erase = true
46
+ end
47
+
48
+ prefix = options[:prefix] || 'tmp-'
49
+ tmpdir = options[:tmpdir] || TmpFile.tmpdir
50
+ max = options[:max] || 1_000_000_000
51
+ tmpfile = tmp_file prefix, max, tmpdir
52
+ tmpfile += ".#{options[:extension]}" if options[:extension]
53
+
54
+ FileUtils.mkdir_p tmpdir
55
+ if IO === content
56
+ File.open(tmpfile, 'wb') do |f|
57
+ begin
58
+ while c = content.readpartial(1024)
59
+ f << c
60
+ end
61
+ rescue EOFError
62
+ end
63
+ end
64
+ elsif !content.nil?
65
+ File.open(tmpfile, 'w') { |f| f.write content }
66
+ end
67
+
68
+ result = yield(tmpfile)
69
+
70
+ FileUtils.rm_rf tmpfile if File.exist?(tmpfile) && erase
71
+
72
+ result
73
+ end
74
+
75
+ def self.with_dir(erase = true, options = {})
76
+ prefix = options[:prefix] || 'tmpdir-'
77
+ tmpdir = tmp_file prefix
78
+
79
+ FileUtils.mkdir_p tmpdir
80
+
81
+ result = yield(tmpdir)
82
+
83
+ FileUtils.rm_rf tmpdir if File.exist?(tmpdir) && erase
84
+
85
+ result
86
+ end
87
+
88
+ def self.in_dir(*args)
89
+ with_dir(*args) do |dir|
90
+ Misc.in_dir dir do
91
+ yield dir
92
+ end
93
+ end
94
+ end
95
+
96
+ SLASH_REPLACE = '·'
97
+ def self.tmp_for_file(file, tmp_options = {}, other_options = {})
98
+ tmp_for_file, prefix, key, persistence_dir = IndiferentHash.process_options tmp_options, :file, :prefix, :key, :dir
99
+ return tmp_for_file unless tmp_for_file.nil?
100
+
101
+ if prefix.nil?
102
+ perfile = file.to_s.sub(/\.b?gz$/,'')
103
+ else
104
+ perfile = prefix.to_s + ":" + file.to_s.sub(/\.b?gz$/,'')
105
+ end
106
+
107
+ perfile += "[#{ key }]" if key
108
+
109
+ if other_options.include? :filters
110
+ other_options[:filters].each do |match,value|
111
+ perfile = perfile + "&F[#{match}=#{Misc.digest(value)}]"
112
+ end
113
+ end
114
+
115
+ persistence_dir = TmpFile.tmpdir if persistence_dir.nil?
116
+ Path.setup(persistence_dir) unless Path === persistence_dir
117
+
118
+ filename = perfile.gsub(/\s/,'_').gsub('/', SLASH_REPLACE)
119
+ clean_options = other_options.dup
120
+ clean_options.delete :unnamed
121
+ clean_options.delete "unnamed"
122
+
123
+ filename = filename[0..MAX_FILE_LENGTH] << Misc.digest(filename[MAX_FILE_LENGTH+1..-1]) if filename.length > MAX_FILE_LENGTH + 10
124
+
125
+ filename += ":" << Misc.digest(clean_options) unless clean_options.empty?
126
+
127
+ persistence_dir[filename]
128
+ end
129
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'scout/exceptions'
2
+ require_relative 'scout/indiferent_hash'
3
+ require_relative 'scout/tmpfile'
4
+ require_relative 'scout/log'
5
+ require_relative 'scout/path'
6
+ require_relative 'scout/simple_opt'
7
+ require_relative 'scout/resource'
8
+ require_relative 'scout/resource/scout'
9
+ require_relative 'scout/persist'
10
+ require_relative 'scout/config'
@@ -0,0 +1,143 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: scout-essentials 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "scout-essentials".freeze
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Miguel Vazquez".freeze]
14
+ s.date = "2023-07-04"
15
+ s.description = "Things a scout can use anywhere".freeze
16
+ s.email = "mikisvaz@gmail.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".vimproject",
24
+ "Gemfile",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/scout-essentials.rb",
30
+ "lib/scout/cmd.rb",
31
+ "lib/scout/concurrent_stream.rb",
32
+ "lib/scout/config.rb",
33
+ "lib/scout/exceptions.rb",
34
+ "lib/scout/indiferent_hash.rb",
35
+ "lib/scout/indiferent_hash/case_insensitive.rb",
36
+ "lib/scout/indiferent_hash/options.rb",
37
+ "lib/scout/log.rb",
38
+ "lib/scout/log/color.rb",
39
+ "lib/scout/log/color_class.rb",
40
+ "lib/scout/log/fingerprint.rb",
41
+ "lib/scout/log/progress.rb",
42
+ "lib/scout/log/progress/report.rb",
43
+ "lib/scout/log/progress/util.rb",
44
+ "lib/scout/log/trap.rb",
45
+ "lib/scout/meta_extension.rb",
46
+ "lib/scout/misc.rb",
47
+ "lib/scout/misc/digest.rb",
48
+ "lib/scout/misc/filesystem.rb",
49
+ "lib/scout/misc/format.rb",
50
+ "lib/scout/misc/helper.rb",
51
+ "lib/scout/misc/insist.rb",
52
+ "lib/scout/misc/monitor.rb",
53
+ "lib/scout/misc/system.rb",
54
+ "lib/scout/named_array.rb",
55
+ "lib/scout/open.rb",
56
+ "lib/scout/open/lock.rb",
57
+ "lib/scout/open/lock/lockfile.rb",
58
+ "lib/scout/open/remote.rb",
59
+ "lib/scout/open/stream.rb",
60
+ "lib/scout/open/util.rb",
61
+ "lib/scout/path.rb",
62
+ "lib/scout/path/find.rb",
63
+ "lib/scout/path/tmpfile.rb",
64
+ "lib/scout/path/util.rb",
65
+ "lib/scout/persist.rb",
66
+ "lib/scout/persist/open.rb",
67
+ "lib/scout/persist/path.rb",
68
+ "lib/scout/persist/serialize.rb",
69
+ "lib/scout/resource.rb",
70
+ "lib/scout/resource/open.rb",
71
+ "lib/scout/resource/path.rb",
72
+ "lib/scout/resource/produce.rb",
73
+ "lib/scout/resource/produce/rake.rb",
74
+ "lib/scout/resource/scout.rb",
75
+ "lib/scout/resource/software.rb",
76
+ "lib/scout/resource/util.rb",
77
+ "lib/scout/simple_opt.rb",
78
+ "lib/scout/simple_opt/accessor.rb",
79
+ "lib/scout/simple_opt/doc.rb",
80
+ "lib/scout/simple_opt/get.rb",
81
+ "lib/scout/simple_opt/parse.rb",
82
+ "lib/scout/simple_opt/setup.rb",
83
+ "lib/scout/tmpfile.rb",
84
+ "scout-essentials.gemspec",
85
+ "share/color/color_names",
86
+ "share/color/diverging_colors.hex",
87
+ "share/software/install_helpers",
88
+ "test/scout/indiferent_hash/test_case_insensitive.rb",
89
+ "test/scout/indiferent_hash/test_options.rb",
90
+ "test/scout/log/test_color.rb",
91
+ "test/scout/log/test_progress.rb",
92
+ "test/scout/misc/test_digest.rb",
93
+ "test/scout/misc/test_filesystem.rb",
94
+ "test/scout/misc/test_insist.rb",
95
+ "test/scout/misc/test_system.rb",
96
+ "test/scout/open/test_lock.rb",
97
+ "test/scout/open/test_remote.rb",
98
+ "test/scout/open/test_stream.rb",
99
+ "test/scout/open/test_util.rb",
100
+ "test/scout/path/test_find.rb",
101
+ "test/scout/path/test_util.rb",
102
+ "test/scout/persist/test_open.rb",
103
+ "test/scout/persist/test_path.rb",
104
+ "test/scout/persist/test_serialize.rb",
105
+ "test/scout/resource/test_path.rb",
106
+ "test/scout/resource/test_produce.rb",
107
+ "test/scout/resource/test_software.rb",
108
+ "test/scout/resource/test_util.rb",
109
+ "test/scout/simple_opt/test_doc.rb",
110
+ "test/scout/simple_opt/test_get.rb",
111
+ "test/scout/simple_opt/test_parse.rb",
112
+ "test/scout/simple_opt/test_setup.rb",
113
+ "test/scout/test_cmd.rb",
114
+ "test/scout/test_concurrent_stream.rb",
115
+ "test/scout/test_config.rb",
116
+ "test/scout/test_indiferent_hash.rb",
117
+ "test/scout/test_log.rb",
118
+ "test/scout/test_meta_extension.rb",
119
+ "test/scout/test_misc.rb",
120
+ "test/scout/test_named_array.rb",
121
+ "test/scout/test_open.rb",
122
+ "test/scout/test_path.rb",
123
+ "test/scout/test_persist.rb",
124
+ "test/scout/test_resource.rb",
125
+ "test/scout/test_tmpfile.rb",
126
+ "test/test_helper.rb"
127
+ ]
128
+ s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
129
+ s.licenses = ["MIT".freeze]
130
+ s.rubygems_version = "3.4.13".freeze
131
+ s.summary = "Scout essential tools".freeze
132
+
133
+ s.specification_version = 4
134
+
135
+ s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
136
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
137
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
138
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
139
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
140
+ s.add_runtime_dependency(%q<term-ansicolor>.freeze, [">= 0"])
141
+ s.add_runtime_dependency(%q<yaml>.freeze, [">= 0"])
142
+ end
143
+