scout-essentials 1.6.6 → 1.6.7
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/.vimproject +3 -1
- data/VERSION +1 -1
- data/lib/scout/annotation/annotation_module.rb +2 -1
- data/lib/scout/log/color.rb +1 -1
- data/lib/scout/misc/digest.rb +5 -1
- data/lib/scout/misc/hook.rb +45 -0
- data/lib/scout/open/final.rb +143 -0
- data/lib/scout/open/stream.rb +1 -1
- data/lib/scout/open/util.rb +0 -71
- data/lib/scout/open.rb +1 -71
- data/lib/scout/path/digest.rb +1 -1
- data/lib/scout/path/find.rb +5 -5
- data/lib/scout/path/util.rb +11 -3
- data/lib/scout/resource/produce/rake.rb +0 -1
- data/lib/scout/resource/util.rb +1 -1
- data/lib/scout/tmpfile.rb +8 -7
- data/scout-essentials.gemspec +6 -3
- data/test/scout/misc/test_hook.rb +42 -0
- data/test/scout/test_tmpfile.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 800981da332ab6cceb17244d49454560c59cdc86df7122b012c2b26b7ab7d427
|
4
|
+
data.tar.gz: 02c265335fd31c11f9b0161708c670d4dfdf1a989cfb6254d5f11c08118e6e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eff7851e6e63bf645d366c38e1cac85a3a6d4b0d34a00091d4c0cbb683361aab9b60a5da0e21fae5318d332bf559275b4748362520e66cc509f125988d7969a9
|
7
|
+
data.tar.gz: 74c799cbfdbf5458bc7e4e59a6e966a280cf39bc0af9bf4691ef8b4390303c78b360b56c81fafbf6465e5932af3eba43d08fba56723a13c32840254358bb658f
|
data/.vimproject
CHANGED
@@ -21,6 +21,7 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
|
|
21
21
|
monitor.rb
|
22
22
|
system.rb
|
23
23
|
math.rb
|
24
|
+
hook.rb
|
24
25
|
}
|
25
26
|
named_array.rb
|
26
27
|
indiferent_hash.rb
|
@@ -41,7 +42,6 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
|
|
41
42
|
|
42
43
|
trap.rb
|
43
44
|
}
|
44
|
-
tmpfile.rb
|
45
45
|
simple_opt.rb
|
46
46
|
simple_opt=simple_opt{
|
47
47
|
accessor.rb
|
@@ -61,12 +61,14 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
|
|
61
61
|
cmd.rb
|
62
62
|
open.rb
|
63
63
|
open=open{
|
64
|
+
final.rb
|
64
65
|
lock.rb
|
65
66
|
remote.rb
|
66
67
|
stream.rb
|
67
68
|
util.rb
|
68
69
|
bgzf.rb
|
69
70
|
}
|
71
|
+
tmpfile.rb
|
70
72
|
resource.rb
|
71
73
|
resource=resource{
|
72
74
|
open.rb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.7
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Annotation
|
2
2
|
module AnnotationModule
|
3
3
|
def annotation(*attrs)
|
4
|
-
self.instance_variable_get("@annotations")
|
4
|
+
annotations = self.instance_variable_get("@annotations")
|
5
|
+
annotations.concat attrs - annotations
|
5
6
|
attrs.each do |a|
|
6
7
|
self.attr_accessor a
|
7
8
|
end
|
data/lib/scout/log/color.rb
CHANGED
@@ -202,7 +202,7 @@ module Log
|
|
202
202
|
|
203
203
|
str = str.to_s unless str.nil?
|
204
204
|
return str if Symbol === color
|
205
|
-
color_str = reset ? Term::ANSIColor.reset : ""
|
205
|
+
color_str = reset ? Term::ANSIColor.reset.dup : ""
|
206
206
|
color_str << color if color
|
207
207
|
if str.nil?
|
208
208
|
color_str
|
data/lib/scout/misc/digest.rb
CHANGED
@@ -9,7 +9,11 @@ module Misc
|
|
9
9
|
when String
|
10
10
|
if Path.is_filename?(obj) && Open.exists?(obj)
|
11
11
|
if File.directory?(obj)
|
12
|
-
|
12
|
+
if Path === obj
|
13
|
+
"Directory MD5: #{digest_str(obj.glob("*"))}"
|
14
|
+
else
|
15
|
+
"Directory MD5: #{digest_str(Dir.glob(File.join(obj, "*")))}"
|
16
|
+
end
|
13
17
|
else
|
14
18
|
"File MD5: #{Misc.digest_file(obj)}"
|
15
19
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Hook
|
2
|
+
def self.extended(hook_class)
|
3
|
+
hook_class.class_variable_set(:@@prev_methods, hook_class.methods)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.apply(hook_class, base_class)
|
7
|
+
base_class.class_variable_set(:@@hooks, []) unless base_class.class_variables.include?([])
|
8
|
+
base_class.class_variable_get(:@@hooks).push hook_class
|
9
|
+
|
10
|
+
hook_class.singleton_methods.each do |method_name|
|
11
|
+
next unless base_class.singleton_methods.include? method_name
|
12
|
+
orig_name = ("orig_" + method_name.to_s).to_sym
|
13
|
+
if not base_class.singleton_methods.include?(orig_name)
|
14
|
+
base_class.singleton_class.alias_method orig_name, method_name
|
15
|
+
base_class.define_singleton_method method_name do |*args|
|
16
|
+
base_class.class_variable_get(:@@hooks).each do |hook|
|
17
|
+
next if hook.respond_to?(:claim) and not hook.claim(*args)
|
18
|
+
if hook.respond_to?(method_name)
|
19
|
+
return hook.send(method_name, *args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
return base_class.send(orig_name, *args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
hook_class.instance_methods.each do |method_name|
|
28
|
+
next unless base_class.instance_methods.include? method_name
|
29
|
+
orig_name = ("orig_" + method_name.to_s).to_sym
|
30
|
+
if not base_class.instance_methods.include?(orig_name)
|
31
|
+
base_class.alias_method orig_name, method_name
|
32
|
+
base_class.define_method method_name do |*args|
|
33
|
+
base_class.class_variable_get(:@@hooks).each do |hook|
|
34
|
+
next if hook.respond_to?(:claim) and not hook.claim(self, *args)
|
35
|
+
if hook.instance_methods.include?(method_name)
|
36
|
+
return hook.instance_method(method_name).bind(self).call *args
|
37
|
+
#return self.instance_exec *args, &hook.instance_method(method_name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return self.send(orig_name, *args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'scout/log'
|
2
|
+
module Open
|
3
|
+
def self.get_stream(file, mode = 'r', options = {})
|
4
|
+
return file if Open.is_stream?(file)
|
5
|
+
return file.stream if Open.has_stream?(file)
|
6
|
+
file = file.find if Path === file
|
7
|
+
|
8
|
+
return Open.ssh(file, options) if Open.ssh?(file)
|
9
|
+
return Open.wget(file, options) if Open.remote?(file)
|
10
|
+
|
11
|
+
File.open(file, mode)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.file_write(file, content, mode = 'w')
|
15
|
+
File.open(file, mode) do |f|
|
16
|
+
begin
|
17
|
+
f.flock(File::LOCK_EX)
|
18
|
+
f.write content
|
19
|
+
f.flock(File::LOCK_UN)
|
20
|
+
ensure
|
21
|
+
f.close unless f.closed?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.write(file, content = nil, options = {})
|
27
|
+
options = IndiferentHash.add_defaults options, :mode => 'w'
|
28
|
+
|
29
|
+
file = file.find(options[:where]) if Path === file
|
30
|
+
mode = IndiferentHash.process_options options, :mode
|
31
|
+
|
32
|
+
Open.mkdir File.dirname(file)
|
33
|
+
|
34
|
+
case
|
35
|
+
when block_given?
|
36
|
+
begin
|
37
|
+
f = File.open(file, mode)
|
38
|
+
begin
|
39
|
+
yield f
|
40
|
+
ensure
|
41
|
+
f.close unless f.closed?
|
42
|
+
end
|
43
|
+
rescue Exception
|
44
|
+
FileUtils.rm file if File.exist? file
|
45
|
+
raise $!
|
46
|
+
end
|
47
|
+
when content.nil?
|
48
|
+
file_write(file, "", mode)
|
49
|
+
when String === content
|
50
|
+
file_write(file, content, mode)
|
51
|
+
when (IO === content || StringIO === content)
|
52
|
+
begin
|
53
|
+
File.open(file, mode) do |f|
|
54
|
+
f.flock(File::LOCK_EX)
|
55
|
+
while block = content.read(Open::BLOCK_SIZE)
|
56
|
+
f.write block
|
57
|
+
end
|
58
|
+
f.flock(File::LOCK_UN)
|
59
|
+
end
|
60
|
+
rescue Exception
|
61
|
+
FileUtils.rm_rf file if File.exist? file
|
62
|
+
raise $!
|
63
|
+
end
|
64
|
+
content.close unless content.closed?
|
65
|
+
content.join if content.respond_to? :join
|
66
|
+
else
|
67
|
+
raise "Content unknown #{Log.fingerprint content}"
|
68
|
+
end
|
69
|
+
|
70
|
+
notify_write(file)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.mv(source, target, options = {})
|
74
|
+
target = target.find if Path === target
|
75
|
+
source = source.find if Path === source
|
76
|
+
FileUtils.mkdir_p File.dirname(target) unless File.exist?(File.dirname(target))
|
77
|
+
tmp_target = File.join(File.dirname(target), '.tmp_mv.' + File.basename(target))
|
78
|
+
FileUtils.mv source, tmp_target
|
79
|
+
FileUtils.mv tmp_target, target
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.rm(file)
|
84
|
+
FileUtils.rm(file) if File.exist?(file) || Open.broken_link?(file)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.rm_rf(file)
|
88
|
+
FileUtils.rm_rf(file)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.touch(file)
|
92
|
+
FileUtils.touch(file)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.mkdir(target)
|
96
|
+
target = target.find if Path === target
|
97
|
+
if ! File.exist?(target)
|
98
|
+
FileUtils.mkdir_p target
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.cp(source, target, options = {})
|
103
|
+
source = source.find if Path === source
|
104
|
+
target = target.find if Path === target
|
105
|
+
|
106
|
+
FileUtils.mkdir_p File.dirname(target) unless File.exist?(File.dirname(target))
|
107
|
+
FileUtils.rm_rf target if File.exist?(target)
|
108
|
+
FileUtils.cp_r source, target
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.directory?(file)
|
112
|
+
file = file.find if Path === file
|
113
|
+
File.directory?(file)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.exists?(file)
|
117
|
+
file = file.find if Path === file
|
118
|
+
File.exist?(file)
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.ctime(file)
|
122
|
+
file = file.find if Path === file
|
123
|
+
File.ctime(file)
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.mtime(file)
|
127
|
+
file = file.find if Path === file
|
128
|
+
begin
|
129
|
+
if File.symlink?(file) || File.stat(file).nlink > 1
|
130
|
+
if File.exist?(file + '.info') && defined?(Step)
|
131
|
+
done = Persist.load(file + '.info', Step::SERIALIZER)[:done]
|
132
|
+
return done if done
|
133
|
+
end
|
134
|
+
|
135
|
+
file = Pathname.new(file).realpath.to_s
|
136
|
+
end
|
137
|
+
return nil unless File.exist?(file)
|
138
|
+
File.mtime(file)
|
139
|
+
rescue
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/scout/open/stream.rb
CHANGED
@@ -105,7 +105,7 @@ module Open
|
|
105
105
|
|
106
106
|
Open.lock tmp_path_lock, lock_options do
|
107
107
|
|
108
|
-
if
|
108
|
+
if Open.exist? path and not force
|
109
109
|
Log.warn "Path exists in sensible_write, not forcing update: #{ path }"
|
110
110
|
Open.consume_stream content
|
111
111
|
else
|
data/lib/scout/open/util.rb
CHANGED
@@ -103,50 +103,12 @@ module Open
|
|
103
103
|
File.symlink?(path) && ! File.exist?(File.readlink(path))
|
104
104
|
end
|
105
105
|
|
106
|
-
def self.directory?(file)
|
107
|
-
file = file.find if Path === file
|
108
|
-
File.directory?(file)
|
109
|
-
end
|
110
|
-
|
111
|
-
def self.exists?(file)
|
112
|
-
file = file.find if Path === file
|
113
|
-
File.exist?(file)
|
114
|
-
end
|
115
106
|
class << self; alias exist? exists? end
|
116
107
|
|
117
108
|
def self.exist_or_link?(file)
|
118
109
|
self.exists?(file) || File.symlink?(file)
|
119
110
|
end
|
120
111
|
|
121
|
-
def self.mv(source, target, options = {})
|
122
|
-
target = target.find if Path === target
|
123
|
-
source = source.find if Path === source
|
124
|
-
FileUtils.mkdir_p File.dirname(target) unless File.exist?(File.dirname(target))
|
125
|
-
tmp_target = File.join(File.dirname(target), '.tmp_mv.' + File.basename(target))
|
126
|
-
FileUtils.mv source, tmp_target
|
127
|
-
FileUtils.mv tmp_target, target
|
128
|
-
return nil
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.rm(file)
|
132
|
-
FileUtils.rm(file) if File.exist?(file) || Open.broken_link?(file)
|
133
|
-
end
|
134
|
-
|
135
|
-
def self.rm_rf(file)
|
136
|
-
FileUtils.rm_rf(file)
|
137
|
-
end
|
138
|
-
|
139
|
-
def self.touch(file)
|
140
|
-
FileUtils.touch(file)
|
141
|
-
end
|
142
|
-
|
143
|
-
def self.mkdir(target)
|
144
|
-
target = target.find if Path === target
|
145
|
-
if ! File.exist?(target)
|
146
|
-
FileUtils.mkdir_p target
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
112
|
def self.writable?(path)
|
151
113
|
path = path.find if Path === path
|
152
114
|
if File.symlink?(path)
|
@@ -158,44 +120,11 @@ module Open
|
|
158
120
|
end
|
159
121
|
end
|
160
122
|
|
161
|
-
def self.ctime(file)
|
162
|
-
file = file.find if Path === file
|
163
|
-
File.ctime(file)
|
164
|
-
end
|
165
|
-
|
166
123
|
def self.realpath(file)
|
167
124
|
file = file.find if Path === file
|
168
125
|
Pathname.new(File.expand_path(file)).realpath.to_s
|
169
126
|
end
|
170
127
|
|
171
|
-
def self.mtime(file)
|
172
|
-
file = file.find if Path === file
|
173
|
-
begin
|
174
|
-
if File.symlink?(file) || File.stat(file).nlink > 1
|
175
|
-
if File.exist?(file + '.info') && defined?(Step)
|
176
|
-
done = Persist.load(file + '.info', Step::SERIALIZER)[:done]
|
177
|
-
return done if done
|
178
|
-
end
|
179
|
-
|
180
|
-
file = Pathname.new(file).realpath.to_s
|
181
|
-
end
|
182
|
-
return nil unless File.exist?(file)
|
183
|
-
File.mtime(file)
|
184
|
-
rescue
|
185
|
-
nil
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def self.cp(source, target, options = {})
|
190
|
-
source = source.find if Path === source
|
191
|
-
target = target.find if Path === target
|
192
|
-
|
193
|
-
FileUtils.mkdir_p File.dirname(target) unless File.exist?(File.dirname(target))
|
194
|
-
FileUtils.rm_rf target if File.exist?(target)
|
195
|
-
FileUtils.cp_r source, target
|
196
|
-
end
|
197
|
-
|
198
|
-
|
199
128
|
def self.ln_s(source, target, options = {})
|
200
129
|
source = source.find if Path === source
|
201
130
|
target = target.find if Path === target
|
data/lib/scout/open.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative 'tmpfile'
|
2
1
|
require_relative 'path'
|
3
2
|
require_relative 'cmd'
|
4
3
|
|
4
|
+
require_relative 'open/final'
|
5
5
|
require_relative 'open/stream'
|
6
6
|
require_relative 'open/util'
|
7
7
|
require_relative 'open/remote'
|
@@ -20,17 +20,6 @@ module Open
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.get_stream(file, mode = 'r', options = {})
|
24
|
-
return file if Open.is_stream?(file)
|
25
|
-
return file.stream if Open.has_stream?(file)
|
26
|
-
file = file.find if Path === file
|
27
|
-
|
28
|
-
return Open.ssh(file, options) if Open.ssh?(file)
|
29
|
-
return Open.wget(file, options) if Open.remote?(file)
|
30
|
-
|
31
|
-
File.open(file, mode)
|
32
|
-
end
|
33
|
-
|
34
23
|
def self.file_open(file, grep = false, mode = 'r', invert_grep = false, fixed_grep = true, options = {})
|
35
24
|
Open.mkdir File.dirname(file) if mode.include? 'w'
|
36
25
|
|
@@ -43,18 +32,6 @@ module Open
|
|
43
32
|
end
|
44
33
|
end
|
45
34
|
|
46
|
-
def self.file_write(file, content, mode = 'w')
|
47
|
-
File.open(file, mode) do |f|
|
48
|
-
begin
|
49
|
-
f.flock(File::LOCK_EX)
|
50
|
-
f.write content
|
51
|
-
f.flock(File::LOCK_UN)
|
52
|
-
ensure
|
53
|
-
f.close unless f.closed?
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
35
|
def self.open(file, options = {})
|
59
36
|
if IO === file || StringIO === file
|
60
37
|
if block_given?
|
@@ -120,51 +97,4 @@ module Open
|
|
120
97
|
end
|
121
98
|
end
|
122
99
|
end
|
123
|
-
|
124
|
-
def self.write(file, content = nil, options = {})
|
125
|
-
options = IndiferentHash.add_defaults options, :mode => 'w'
|
126
|
-
|
127
|
-
file = file.find(options[:where]) if Path === file
|
128
|
-
mode = IndiferentHash.process_options options, :mode
|
129
|
-
|
130
|
-
FileUtils.mkdir_p File.dirname(file)
|
131
|
-
|
132
|
-
case
|
133
|
-
when block_given?
|
134
|
-
begin
|
135
|
-
f = File.open(file, mode)
|
136
|
-
begin
|
137
|
-
yield f
|
138
|
-
ensure
|
139
|
-
f.close unless f.closed?
|
140
|
-
end
|
141
|
-
rescue Exception
|
142
|
-
FileUtils.rm file if File.exist? file
|
143
|
-
raise $!
|
144
|
-
end
|
145
|
-
when content.nil?
|
146
|
-
file_write(file, "", mode)
|
147
|
-
when String === content
|
148
|
-
file_write(file, content, mode)
|
149
|
-
when (IO === content || StringIO === content)
|
150
|
-
begin
|
151
|
-
File.open(file, mode) do |f|
|
152
|
-
f.flock(File::LOCK_EX)
|
153
|
-
while block = content.read(Open::BLOCK_SIZE)
|
154
|
-
f.write block
|
155
|
-
end
|
156
|
-
f.flock(File::LOCK_UN)
|
157
|
-
end
|
158
|
-
rescue Exception
|
159
|
-
FileUtils.rm_rf file if File.exist? file
|
160
|
-
raise $!
|
161
|
-
end
|
162
|
-
content.close unless content.closed?
|
163
|
-
content.join if content.respond_to? :join
|
164
|
-
else
|
165
|
-
raise "Content unknown #{Log.fingerprint content}"
|
166
|
-
end
|
167
|
-
|
168
|
-
notify_write(file)
|
169
|
-
end
|
170
100
|
end
|
data/lib/scout/path/digest.rb
CHANGED
@@ -3,7 +3,7 @@ module Path
|
|
3
3
|
def digest_str
|
4
4
|
case
|
5
5
|
when File.directory?(self)
|
6
|
-
"Directory MD5: #{Misc.digest_str(
|
6
|
+
"Directory MD5: #{Misc.digest_str(self.glob("*"))}"
|
7
7
|
when self.located? && File.exist?(self)
|
8
8
|
"File MD5: #{Misc.digest_file(self)}"
|
9
9
|
else
|
data/lib/scout/path/find.rb
CHANGED
@@ -7,7 +7,7 @@ module Path
|
|
7
7
|
caller_dup = caller.dup
|
8
8
|
while file = caller_dup.shift
|
9
9
|
break unless file =~ /(?:scout|rbbt)\/(?:resource\.rb|workflow\.rb)/ or
|
10
|
-
file =~ /(?:scout|rbbt)\/(?:.*\/)?(path|open|tsv|refactor)\.rb/ or
|
10
|
+
file =~ /(?:scout|rbbt)\/(?:.*\/)?(path|open|final|tsv|refactor)\.rb/ or
|
11
11
|
file =~ /(?:scout|rbbt)\/(?:.*\/)?path\/(?:find|refactor|util)\.rb/ or
|
12
12
|
file =~ /(?:scout|rbbt)\/persist.rb/ or
|
13
13
|
file =~ /scout\/resource\/produce.rb/ or
|
@@ -42,10 +42,10 @@ module Path
|
|
42
42
|
file = map.sub('{PKGDIR}', pkgdir).
|
43
43
|
sub('{HOME}', ENV["HOME"]).
|
44
44
|
sub('{RESOURCE}', path.pkgdir.to_s).
|
45
|
-
sub('{PWD}'
|
46
|
-
sub('{TOPLEVEL}'
|
47
|
-
sub('{SUBPATH}'
|
48
|
-
sub('{BASENAME}'
|
45
|
+
sub('{PWD}'){ FileUtils.pwd }.
|
46
|
+
sub('{TOPLEVEL}'){ path._toplevel }.
|
47
|
+
sub('{SUBPATH}'){ path._subpath }.
|
48
|
+
sub('{BASENAME}'){ File.basename(path)}.
|
49
49
|
sub('{PATH}', path).
|
50
50
|
sub('{LIBDIR}'){ path.libdir || (path.pkgdir.respond_to?(:libdir) && path.pkgdir.libdir) || Path.caller_lib_dir || "NOLIBDIR" }.
|
51
51
|
sub('{MAPNAME}', map_name.to_s).
|
data/lib/scout/path/util.rb
CHANGED
@@ -8,7 +8,10 @@ module Path
|
|
8
8
|
def self.is_filename?(string, need_to_exists = true)
|
9
9
|
return false if string.nil?
|
10
10
|
return true if Path === string
|
11
|
-
return true if String === string and
|
11
|
+
return true if String === string and
|
12
|
+
! string.include?("\n") and
|
13
|
+
(string.length < 265 || string.split("/").select{|p| p.length > 265 }.empty?) and
|
14
|
+
(! need_to_exists || File.exist?(string))
|
12
15
|
return false
|
13
16
|
end
|
14
17
|
|
@@ -48,7 +51,11 @@ module Path
|
|
48
51
|
|
49
52
|
def glob(pattern = '*')
|
50
53
|
if self.include? "*"
|
51
|
-
|
54
|
+
if located?
|
55
|
+
Dir.glob(File.join(self, pattern))
|
56
|
+
else
|
57
|
+
self.glob_all
|
58
|
+
end
|
52
59
|
else
|
53
60
|
return [] unless self.exist?
|
54
61
|
found = self.find
|
@@ -69,7 +76,8 @@ module Path
|
|
69
76
|
|
70
77
|
search_paths.keys.collect do |where|
|
71
78
|
found = find(where)
|
72
|
-
|
79
|
+
|
80
|
+
paths = pattern ? found.glob(pattern) : found.glob
|
73
81
|
|
74
82
|
paths = paths.collect{|p| self.annotate p }
|
75
83
|
|
data/lib/scout/resource/util.rb
CHANGED
@@ -15,7 +15,7 @@ module Resource
|
|
15
15
|
pattern = path_maps[pattern] while Symbol === pattern
|
16
16
|
next if pattern.nil?
|
17
17
|
|
18
|
-
pattern = pattern.sub('{PWD}'
|
18
|
+
pattern = pattern.sub('{PWD}'){Dir.pwd}
|
19
19
|
pattern = pattern.sub('{HOME}', ENV["HOME"])
|
20
20
|
if String === pattern and pattern.include?('{')
|
21
21
|
regexp = "^" + pattern
|
data/lib/scout/tmpfile.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative 'open'
|
1
2
|
require_relative 'misc'
|
2
3
|
require_relative 'log'
|
3
4
|
require 'fileutils'
|
@@ -32,7 +33,7 @@ module TmpFile
|
|
32
33
|
def self.tmp_file(prefix = 'tmp-', max = 1_000_000_000, dir = nil)
|
33
34
|
dir ||= TmpFile.tmpdir
|
34
35
|
dir = dir.find if Path === dir
|
35
|
-
File.
|
36
|
+
File.join(dir, random_name(prefix, max))
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.with_file(content = nil, erase = true, options = {})
|
@@ -52,9 +53,9 @@ module TmpFile
|
|
52
53
|
tmpfile = tmp_file prefix, max, tmpdir
|
53
54
|
tmpfile += ".#{options[:extension]}" if options[:extension]
|
54
55
|
|
55
|
-
|
56
|
+
Open.mkdir tmpdir
|
56
57
|
if IO === content
|
57
|
-
|
58
|
+
Open.open(tmpfile, mode: 'wb') do |f|
|
58
59
|
begin
|
59
60
|
while c = content.readpartial(1024)
|
60
61
|
f << c
|
@@ -63,12 +64,12 @@ module TmpFile
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
elsif !content.nil?
|
66
|
-
|
67
|
+
Open.write(tmpfile, content)
|
67
68
|
end
|
68
69
|
|
69
70
|
result = yield(tmpfile)
|
70
71
|
|
71
|
-
|
72
|
+
Open.rm_rf tmpfile if Open.exist?(tmpfile) && erase
|
72
73
|
|
73
74
|
result
|
74
75
|
end
|
@@ -77,11 +78,11 @@ module TmpFile
|
|
77
78
|
prefix = options[:prefix] || 'tmpdir-'
|
78
79
|
tmpdir = tmp_file prefix
|
79
80
|
|
80
|
-
|
81
|
+
Open.mkdir tmpdir
|
81
82
|
|
82
83
|
result = yield(tmpdir)
|
83
84
|
|
84
|
-
|
85
|
+
Open.rm_rf tmpdir if Open.exist?(tmpdir) && erase
|
85
86
|
|
86
87
|
result
|
87
88
|
end
|
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.7 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.7".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 = "2025-03-
|
14
|
+
s.date = "2025-03-19"
|
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 = [
|
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
|
|
51
51
|
"lib/scout/misc/filesystem.rb",
|
52
52
|
"lib/scout/misc/format.rb",
|
53
53
|
"lib/scout/misc/helper.rb",
|
54
|
+
"lib/scout/misc/hook.rb",
|
54
55
|
"lib/scout/misc/insist.rb",
|
55
56
|
"lib/scout/misc/matching.rb",
|
56
57
|
"lib/scout/misc/math.rb",
|
@@ -58,6 +59,7 @@ Gem::Specification.new do |s|
|
|
58
59
|
"lib/scout/misc/system.rb",
|
59
60
|
"lib/scout/named_array.rb",
|
60
61
|
"lib/scout/open.rb",
|
62
|
+
"lib/scout/open/final.rb",
|
61
63
|
"lib/scout/open/lock.rb",
|
62
64
|
"lib/scout/open/lock/lockfile.rb",
|
63
65
|
"lib/scout/open/remote.rb",
|
@@ -100,6 +102,7 @@ Gem::Specification.new do |s|
|
|
100
102
|
"test/scout/misc/test_digest.rb",
|
101
103
|
"test/scout/misc/test_filesystem.rb",
|
102
104
|
"test/scout/misc/test_helper.rb",
|
105
|
+
"test/scout/misc/test_hook.rb",
|
103
106
|
"test/scout/misc/test_insist.rb",
|
104
107
|
"test/scout/misc/test_matching.rb",
|
105
108
|
"test/scout/misc/test_math.rb",
|
@@ -0,0 +1,42 @@
|
|
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 TestHook < Test::Unit::TestCase
|
5
|
+
def test_hook
|
6
|
+
m = Module.new do
|
7
|
+
def self.test
|
8
|
+
"original"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test
|
12
|
+
'ORIGINAL'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
a = 's'
|
17
|
+
a.extend m
|
18
|
+
|
19
|
+
assert_equal 'original', m.test
|
20
|
+
assert_equal 'ORIGINAL', a.test
|
21
|
+
|
22
|
+
h = Module.new do
|
23
|
+
extend Hook
|
24
|
+
def self.test
|
25
|
+
"hook"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test
|
29
|
+
'HOOK'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Hook.apply(h, m)
|
34
|
+
|
35
|
+
a = 's'
|
36
|
+
a.extend m
|
37
|
+
|
38
|
+
assert_equal 'hook', m.test
|
39
|
+
assert_equal 'HOOK', a.test
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/test/scout/test_tmpfile.rb
CHANGED
@@ -17,7 +17,7 @@ class TestTmpFile < Test::Unit::TestCase
|
|
17
17
|
def test_do_tmp_file_io
|
18
18
|
content = "Hello World!"
|
19
19
|
TmpFile.with_file(content) do |file1|
|
20
|
-
|
20
|
+
Open.open(file1) do |io|
|
21
21
|
TmpFile.with_file(io) do |file|
|
22
22
|
assert_equal content, File.open(file).read
|
23
23
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: shoulda
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/scout/misc/filesystem.rb
|
162
162
|
- lib/scout/misc/format.rb
|
163
163
|
- lib/scout/misc/helper.rb
|
164
|
+
- lib/scout/misc/hook.rb
|
164
165
|
- lib/scout/misc/insist.rb
|
165
166
|
- lib/scout/misc/matching.rb
|
166
167
|
- lib/scout/misc/math.rb
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- lib/scout/misc/system.rb
|
169
170
|
- lib/scout/named_array.rb
|
170
171
|
- lib/scout/open.rb
|
172
|
+
- lib/scout/open/final.rb
|
171
173
|
- lib/scout/open/lock.rb
|
172
174
|
- lib/scout/open/lock/lockfile.rb
|
173
175
|
- lib/scout/open/remote.rb
|
@@ -210,6 +212,7 @@ files:
|
|
210
212
|
- test/scout/misc/test_digest.rb
|
211
213
|
- test/scout/misc/test_filesystem.rb
|
212
214
|
- test/scout/misc/test_helper.rb
|
215
|
+
- test/scout/misc/test_hook.rb
|
213
216
|
- test/scout/misc/test_insist.rb
|
214
217
|
- test/scout/misc/test_matching.rb
|
215
218
|
- test/scout/misc/test_math.rb
|