ykutils 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +27 -0
- data/.gitignore +5 -1
- data/.rspec +1 -0
- data/.rubocop.yml +17 -0
- data/.rubocop_todo.yml +332 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +20 -1
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +21 -0
- data/README.md +12 -8
- data/Rakefile +11 -0
- data/_config.yml +1 -0
- data/bin/console +2 -1
- data/bin/erubix +17 -0
- data/bin/erubix2 +13 -0
- data/bin/makegrid +23 -0
- data/bin/setup +2 -1
- data/lib/ykutils/datastructop.rb +58 -0
- data/lib/ykutils/debugutils.rb +28 -35
- data/lib/ykutils/erubyx.rb +41 -0
- data/lib/ykutils/fileoputils.rb +401 -0
- data/lib/ykutils/filepermision.rb +8 -9
- data/lib/ykutils/gridlist.rb +49 -0
- data/lib/ykutils/hasharray.rb +13 -22
- data/lib/ykutils/lines.rb +143 -154
- data/lib/ykutils/lsutils.rb +71 -72
- data/lib/ykutils/nginxconfig.rb +41 -0
- data/lib/ykutils/nginxconfigfiles.rb +31 -0
- data/lib/ykutils/nkfutil.rb +147 -155
- data/lib/ykutils/nkfutil19.rb +88 -84
- data/lib/ykutils/osutil.rb +16 -19
- data/lib/ykutils/pathop.rb +16 -18
- data/lib/ykutils/retcodex.rb +9 -11
- data/lib/ykutils/specfileop.rb +82 -91
- data/lib/ykutils/stext.rb +425 -462
- data/lib/ykutils/stextx.rb +32 -33
- data/lib/ykutils/stringutils.rb +111 -125
- data/lib/ykutils/treemanager.rb +33 -36
- data/lib/ykutils/treemanagera.rb +21 -26
- data/lib/ykutils/version.rb +3 -1
- data/lib/ykutils/xlines.rb +8 -9
- data/lib/ykutils/yamlop.rb +227 -0
- data/lib/ykutils/yamlxop.rb +35 -34
- data/lib/ykutils.rb +28 -0
- data/sig/ykutils.rbs +4 -0
- data/test_data/4servers.erb +7 -0
- data/test_data/a.bat +5 -0
- data/test_data/a_ncn.bat +12 -0
- data/test_data/top.yml +0 -0
- data/test_data/v103-3-189-127/4servers.erb +0 -0
- data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/t_server_1.erb +7 -0
- data/test_data/v103-3-189-127/template.erb +21 -0
- data/test_data/v103-3-189-127/template_ssl.erb +22 -0
- data/test_data/v103-3-189-127/template_ssl_www.erb +12 -0
- data/test_data/v103-3-189-127/template_www.erb +24 -0
- data/test_data/v103-3-189-127/value.yml +3 -0
- data/test_data/v103-3-189-127/value_ssl.yml +5 -0
- data/ykutils.gemspec +43 -27
- metadata +91 -27
- data/.travis.yml +0 -3
- data/lib/ykutils/fileoputils2.rb +0 -443
data/lib/ykutils/pathop.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
|
-
require
|
1
|
+
require "pathname"
|
2
2
|
|
3
3
|
module Ykutils
|
4
4
|
module PathOp
|
5
|
-
def get_buddy_path(
|
6
|
-
one_path = Pathname.new(
|
5
|
+
def get_buddy_path(fname, append_name = "", extname = "")
|
6
|
+
one_path = Pathname.new(fname).expand_path
|
7
7
|
dir_path = one_path.dirname
|
8
8
|
base_path = one_path.basename(".*")
|
9
|
-
append_name = "-2" unless
|
9
|
+
append_name = "-2" unless append_name.empty? or extname.empty?
|
10
10
|
extname ||= one_path.extname
|
11
11
|
|
12
|
-
[one_path
|
12
|
+
[one_path, dir_path.join(base_path.to_s + append_name + extname)]
|
13
13
|
end
|
14
14
|
|
15
|
-
def determine_fname_for_update(
|
16
|
-
get_buddy_path(
|
15
|
+
def determine_fname_for_update(fname, ext = ".bak")
|
16
|
+
get_buddy_path(fname, "", ext)
|
17
17
|
end
|
18
18
|
|
19
|
-
def determine_fname_for_update2(
|
19
|
+
def determine_fname_for_update2(fname)
|
20
20
|
begin
|
21
|
-
ctime = File.ctime(
|
22
|
-
rescue =>
|
21
|
+
ctime = File.ctime(fname)
|
22
|
+
rescue StandardError => e
|
23
23
|
end
|
24
|
-
ctime
|
24
|
+
ctime ||= Time.now
|
25
25
|
ary = ctime.to_s.split(" ")
|
26
|
-
extname = File.extname(
|
27
|
-
append = ["", ary[0]
|
28
|
-
get_buddy_path(
|
26
|
+
extname = File.extname(fname)
|
27
|
+
append = ["", ary[0], ary[1].gsub(":", "-")].join("-")
|
28
|
+
get_buddy_path(fname, append, extname)
|
29
29
|
end
|
30
30
|
|
31
|
-
def file_ensure(
|
32
|
-
File.open(
|
31
|
+
def file_ensure(fname)
|
32
|
+
File.open(fname, "w").close unless File.exist?(fname)
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
37
|
-
|
data/lib/ykutils/retcodex.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Ykutils
|
2
|
-
|
3
2
|
class RetCode
|
4
|
-
attr_reader :val
|
3
|
+
attr_reader :val, :mes, :ret, :bool
|
5
4
|
|
6
5
|
def initialize(obj)
|
7
6
|
@val = obj
|
@@ -18,7 +17,7 @@ module Ykutils
|
|
18
17
|
@bool
|
19
18
|
end
|
20
19
|
|
21
|
-
def set_bool(
|
20
|
+
def set_bool(val)
|
22
21
|
@bool = val
|
23
22
|
end
|
24
23
|
|
@@ -26,25 +25,24 @@ module Ykutils
|
|
26
25
|
@bool
|
27
26
|
end
|
28
27
|
|
29
|
-
def set_mes(
|
28
|
+
def set_mes(val)
|
30
29
|
@mes = val
|
31
30
|
end
|
32
31
|
|
33
|
-
def set_ret(
|
32
|
+
def set_ret(val)
|
34
33
|
@ret = val
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
class RetCode2 < RetCode
|
39
|
-
attr_reader :val
|
40
|
-
attr_accessor
|
41
|
-
|
42
|
-
def initialize(
|
43
|
-
@val = { "ret" => ret
|
38
|
+
attr_reader :val
|
39
|
+
attr_accessor :mes, :ret, :bool
|
40
|
+
|
41
|
+
def initialize(ret, bool, mes)
|
42
|
+
@val = { "ret" => ret, "bool" => bool, "mes" => mes }
|
44
43
|
@ret = ret
|
45
44
|
@bool = bool
|
46
45
|
@mes = mes
|
47
46
|
end
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
data/lib/ykutils/specfileop.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# -*- coding utf-8 -*-
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "pp"
|
4
|
+
require "yaml"
|
5
|
+
require "csv"
|
6
|
+
require "ykutils/treemanagera"
|
7
7
|
if RUBY_VERSION >= "1.8.7"
|
8
|
-
require
|
8
|
+
require "ykutils/nkfutil19"
|
9
9
|
else
|
10
|
-
require
|
10
|
+
require "ykutils/nkfutil"
|
11
11
|
end
|
12
|
-
require
|
12
|
+
require "ykutils/debugutils"
|
13
13
|
|
14
14
|
module Ykutils
|
15
|
-
|
16
15
|
module SpecFileOp
|
17
16
|
include DebugUtils
|
18
17
|
include NKFUTIL
|
@@ -21,102 +20,96 @@ module Ykutils
|
|
21
20
|
@valid
|
22
21
|
end
|
23
22
|
|
24
|
-
def open_for_write(
|
23
|
+
def open_for_write(fname)
|
25
24
|
begin
|
26
|
-
fileobj = File.open(
|
27
|
-
rescue =>
|
28
|
-
pp
|
29
|
-
pp
|
25
|
+
fileobj = File.open(fname, "w")
|
26
|
+
rescue StandardError => e
|
27
|
+
pp e
|
28
|
+
pp e.backtrace
|
30
29
|
@valid = false
|
31
30
|
end
|
32
31
|
fileobj
|
33
32
|
end
|
34
33
|
|
35
|
-
def dump_yaml_fileobj(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@valid = false
|
42
|
-
end
|
34
|
+
def dump_yaml_fileobj(obj, fileobj)
|
35
|
+
YAML.dump(obj, fileobj)
|
36
|
+
rescue StandardError => e
|
37
|
+
pp e
|
38
|
+
pp e.backtrace
|
39
|
+
@valid = false
|
43
40
|
end
|
44
41
|
|
45
|
-
def save_yaml_file(
|
46
|
-
|
47
|
-
|
48
|
-
YAML.dump( obj , fileobj )
|
49
|
-
}
|
50
|
-
rescue => ex
|
51
|
-
pp ex
|
52
|
-
pp ex.backtrace
|
53
|
-
@valid = false
|
42
|
+
def save_yaml_file(obj, fname)
|
43
|
+
File.open(fname, "w") do |fileobj|
|
44
|
+
YAML.dump(obj, fileobj)
|
54
45
|
end
|
46
|
+
rescue StandardError => e
|
47
|
+
pp e
|
48
|
+
pp e.backtrace
|
49
|
+
@valid = false
|
55
50
|
end
|
56
51
|
|
57
|
-
def load_yaml_file(
|
52
|
+
def load_yaml_file(fname)
|
58
53
|
@data = nil
|
59
54
|
begin
|
60
55
|
@data = YAML.load_file(fname)
|
61
|
-
rescue =>
|
62
|
-
pp
|
63
|
-
pp
|
56
|
+
rescue StandardError => e
|
57
|
+
pp e
|
58
|
+
pp e.backtrace
|
64
59
|
@valid = false
|
65
60
|
end
|
66
61
|
@data
|
67
62
|
end
|
68
63
|
|
69
|
-
def parse_yaml_file(
|
64
|
+
def parse_yaml_file(fname)
|
70
65
|
begin
|
71
|
-
@data = YAML.parse(
|
72
|
-
rescue =>
|
73
|
-
pp
|
74
|
-
pp
|
66
|
+
@data = YAML.parse(File.read(fname))
|
67
|
+
rescue StandardError => e
|
68
|
+
pp e
|
69
|
+
pp e.backtrace
|
75
70
|
@valid = false
|
76
71
|
end
|
77
72
|
@data
|
78
73
|
end
|
79
74
|
|
80
|
-
def expand_data(
|
75
|
+
def expand_data(data, separator, except_ary = [])
|
81
76
|
tm = TreeManager.new
|
82
|
-
re = Regexp.new(
|
83
|
-
|
84
|
-
data.each do |k,v|
|
77
|
+
re = Regexp.new(separator + "([^#{separator[0, 1]}]+)" + separator)
|
78
|
+
|
79
|
+
data.each do |k, v|
|
85
80
|
next unless v
|
81
|
+
|
86
82
|
v.scan(re).flatten.each do |it|
|
87
83
|
if it
|
88
|
-
tm.add(
|
89
|
-
tm.addTag(
|
84
|
+
tm.add(it, k)
|
85
|
+
tm.addTag(k, it)
|
90
86
|
else
|
91
|
-
tm.add(
|
87
|
+
tm.add(nil, k)
|
92
88
|
end
|
93
89
|
end
|
94
|
-
end
|
90
|
+
end
|
95
91
|
|
96
92
|
tm.tsort.reverse.each do |k|
|
97
93
|
next unless data[k]
|
98
94
|
|
99
95
|
tag = tm.getTag(k)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
96
|
+
next unless tag
|
97
|
+
|
98
|
+
i = 0
|
99
|
+
tag.each do |it|
|
100
|
+
ntag = Regexp.new(separator + it + separator)
|
101
|
+
data[k] = data[k].sub(ntag, data[it]) if data[it]
|
108
102
|
end
|
109
103
|
end
|
110
104
|
|
111
|
-
data.each do |k,v|
|
105
|
+
data.each do |k, v|
|
112
106
|
next unless v
|
107
|
+
|
113
108
|
ary = v.scan(re).flatten
|
114
109
|
i = 0
|
115
110
|
if ary and ary.size > 0
|
116
111
|
except_ary.each do |it|
|
117
|
-
unless ary.index(it)
|
118
|
-
i += 1
|
119
|
-
end
|
112
|
+
i += 1 unless ary.index(it)
|
120
113
|
end
|
121
114
|
end
|
122
115
|
if i > 0
|
@@ -128,15 +121,13 @@ module Ykutils
|
|
128
121
|
data
|
129
122
|
end
|
130
123
|
|
131
|
-
def make_data_complement(item_ary, data
|
124
|
+
def make_data_complement(item_ary, data, common)
|
132
125
|
item_ary.each do |it|
|
133
|
-
unless data[it] and data[it].strip != ""
|
134
|
-
data[it] = common[it]
|
135
|
-
end
|
126
|
+
data[it] = common[it] unless data[it] and data[it].strip != ""
|
136
127
|
end
|
137
128
|
end
|
138
129
|
|
139
|
-
def check_data_complement(
|
130
|
+
def check_data_complement(item_ary, _data)
|
140
131
|
mes_ary = []
|
141
132
|
item_ary.each do |k|
|
142
133
|
unless @data[k]
|
@@ -147,62 +138,62 @@ module Ykutils
|
|
147
138
|
mes_ary
|
148
139
|
end
|
149
140
|
|
150
|
-
def check_data_complement_print_message(
|
151
|
-
mes_ary = check_data_complement(
|
141
|
+
def check_data_complement_print_message(item_ary, data)
|
142
|
+
mes_ary = check_data_complement(item_ary, data)
|
152
143
|
mes_ary.each do |mes|
|
153
144
|
puts mes
|
154
145
|
end
|
155
146
|
end
|
156
|
-
|
157
|
-
def load_csv_file(
|
147
|
+
|
148
|
+
def load_csv_file(fname)
|
158
149
|
ary = []
|
159
150
|
begin
|
160
|
-
CSV.open(
|
151
|
+
CSV.open(fname, "r") do |row|
|
161
152
|
next unless row
|
162
|
-
|
153
|
+
|
163
154
|
ary << row[0]
|
164
155
|
end
|
165
|
-
rescue =>
|
166
|
-
pp
|
167
|
-
pp
|
156
|
+
rescue StandardError => e
|
157
|
+
pp e
|
158
|
+
pp e.backtrace
|
168
159
|
@valid = false
|
169
160
|
end
|
170
161
|
ary
|
171
162
|
end
|
172
163
|
|
173
|
-
def load_csv_file_ex(
|
164
|
+
def load_csv_file_ex(fname)
|
174
165
|
ary = []
|
175
166
|
begin
|
176
|
-
CSV.open(
|
167
|
+
CSV.open(fname, "r") do |row|
|
177
168
|
next unless row
|
178
|
-
|
179
|
-
ary.concat(
|
169
|
+
|
170
|
+
ary.concat(row)
|
180
171
|
end
|
181
|
-
rescue =>
|
182
|
-
pp
|
183
|
-
pp
|
172
|
+
rescue StandardError => e
|
173
|
+
pp e
|
174
|
+
pp e.backtrace
|
184
175
|
@valid = false
|
185
176
|
end
|
186
177
|
ary
|
187
178
|
end
|
188
179
|
|
189
|
-
def load_plain_text_file(
|
180
|
+
def load_plain_text_file(fname)
|
190
181
|
ary = []
|
191
182
|
|
192
183
|
begin
|
193
184
|
ary0 = File.readlines(fname)
|
194
|
-
senc = NKFUTIL.auto_config_to_inner(
|
185
|
+
senc = NKFUTIL.auto_config_to_inner(ary0.join)
|
195
186
|
|
196
|
-
ary = ary0.select{ |x| x
|
197
|
-
if x
|
198
|
-
|
199
|
-
else
|
200
|
-
|
187
|
+
ary = ary0.select { |x| !x.nil? }.collect do |x|
|
188
|
+
if x.nil?
|
189
|
+
""
|
190
|
+
else
|
191
|
+
NKFUTIL.convert(x)
|
201
192
|
end
|
202
|
-
|
203
|
-
rescue =>
|
204
|
-
pp
|
205
|
-
pp
|
193
|
+
end
|
194
|
+
rescue StandardError => e
|
195
|
+
pp e
|
196
|
+
pp e.backtrace
|
206
197
|
@valid = false
|
207
198
|
|
208
199
|
ary = []
|