ykutils 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/main.yml +2 -0
- data/.gitignore +3 -0
- data/.rubocop_todo.yml +15 -377
- data/Gemfile +7 -8
- data/Gemfile.lock +49 -39
- data/Rakefile +25 -8
- data/SECURITY.md +21 -0
- data/bin/console +0 -0
- data/bin/erubix +1 -1
- data/bin/erubix2 +2 -2
- data/bin/makegrid +1 -1
- data/lib/ykutils/debugutils.rb +32 -42
- data/lib/ykutils/erubyx.rb +5 -7
- data/lib/ykutils/fileoputils.rb +53 -53
- data/lib/ykutils/filepermision.rb +1 -1
- data/lib/ykutils/gridlist.rb +9 -12
- data/lib/ykutils/hasharray.rb +1 -5
- data/lib/ykutils/lines.rb +14 -12
- data/lib/ykutils/lsutils.rb +3 -5
- data/lib/ykutils/nginxconfig.rb +12 -12
- data/lib/ykutils/nginxconfigfiles.rb +10 -12
- data/lib/ykutils/nkfutil.rb +20 -20
- data/lib/ykutils/nkfutil19.rb +16 -16
- data/lib/ykutils/osutil.rb +7 -7
- data/lib/ykutils/pathop.rb +4 -3
- data/lib/ykutils/retcodex.rb +2 -17
- data/lib/ykutils/specfileop.rb +8 -10
- data/lib/ykutils/stext.rb +53 -69
- data/lib/ykutils/stextx.rb +12 -12
- data/lib/ykutils/stringutils.rb +12 -12
- data/lib/ykutils/treemanager.rb +1 -1
- data/lib/ykutils/treemanagera.rb +2 -2
- data/lib/ykutils/version.rb +1 -1
- data/lib/ykutils/yamlop.rb +30 -31
- data/lib/ykutils/yamlxop.rb +0 -5
- data/lib/ykutils.rb +4 -1
- data/ykutils.gemspec +1 -0
- metadata +5 -3
data/lib/ykutils/stringutils.rb
CHANGED
@@ -4,8 +4,8 @@ module Ykutils
|
|
4
4
|
str || ""
|
5
5
|
end
|
6
6
|
|
7
|
-
def get_basename_ext(
|
8
|
-
bn0 =
|
7
|
+
def get_basename_ext(itx)
|
8
|
+
bn0 = itx.basename.to_s
|
9
9
|
if RUBY_VERSION > "1.9"
|
10
10
|
# bn0.encode!( "internal" )
|
11
11
|
bn0.encode! "UTF-8"
|
@@ -48,7 +48,7 @@ module Ykutils
|
|
48
48
|
content_ary = []
|
49
49
|
|
50
50
|
reg_hash = {}
|
51
|
-
tag_value_hash.
|
51
|
+
tag_value_hash.each_key do |k|
|
52
52
|
reg_hash[k] = Regexp.new(separator + k + separator)
|
53
53
|
end
|
54
54
|
|
@@ -61,17 +61,17 @@ module Ykutils
|
|
61
61
|
content_ary
|
62
62
|
end
|
63
63
|
|
64
|
-
def indent(
|
64
|
+
def indent(num)
|
65
65
|
n ||= 0
|
66
66
|
@indent_hash ||= {}
|
67
|
-
@indent_hash[
|
68
|
-
@indent_hash[
|
67
|
+
@indent_hash[num] ||= " " * n
|
68
|
+
@indent_hash[num]
|
69
69
|
end
|
70
70
|
|
71
71
|
def print_hier(data, level)
|
72
72
|
case data.class.to_s
|
73
73
|
when "Hash"
|
74
|
-
data.
|
74
|
+
data.each_value do |v|
|
75
75
|
# puts "#{indent(level)}#{k}|#{v.class} #{if v.class.to_s == 'String' then v.size else '' end }"
|
76
76
|
# puts "#{indent(level)}#{k}|#{v.class}"
|
77
77
|
print_hier(v, level + 1)
|
@@ -80,12 +80,12 @@ module Ykutils
|
|
80
80
|
data.each do |v|
|
81
81
|
print_hier(v, level + 1)
|
82
82
|
end
|
83
|
-
|
83
|
+
# else
|
84
84
|
# puts "#{indent(level)}|#{data.class}"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def print_hier2(data, level)
|
89
89
|
case data.class.to_s
|
90
90
|
when "Hash"
|
91
91
|
data.each do |k, v|
|
@@ -93,8 +93,8 @@ module Ykutils
|
|
93
93
|
str = "#{indent(level)}#{k}|#{v.class}"
|
94
94
|
if v.instance_of?(Array)
|
95
95
|
num = v.size
|
96
|
-
str +=
|
97
|
-
str
|
96
|
+
str += "|#{num}"
|
97
|
+
"#{str}###################" if num > 1
|
98
98
|
end
|
99
99
|
# puts str
|
100
100
|
print_hier_2(v, level + 1) if k != "group"
|
@@ -103,7 +103,7 @@ module Ykutils
|
|
103
103
|
data.each do |v|
|
104
104
|
print_hier_2(v, level + 1)
|
105
105
|
end
|
106
|
-
|
106
|
+
# else
|
107
107
|
# puts "#{indent(level)}|#{data.class}"
|
108
108
|
end
|
109
109
|
end
|
data/lib/ykutils/treemanager.rb
CHANGED
data/lib/ykutils/treemanagera.rb
CHANGED
@@ -2,7 +2,7 @@ require "ykutils/treemanager"
|
|
2
2
|
|
3
3
|
module Ykutils
|
4
4
|
class TreeManager
|
5
|
-
def
|
5
|
+
def add_tag(node_name, tag_name)
|
6
6
|
@tag ||= {}
|
7
7
|
|
8
8
|
if @tag[node_name]
|
@@ -12,7 +12,7 @@ module Ykutils
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def tag(node_name)
|
16
16
|
ret = nil
|
17
17
|
ret = @tag[node_name] if @tag
|
18
18
|
ret
|
data/lib/ykutils/version.rb
CHANGED
data/lib/ykutils/yamlop.rb
CHANGED
@@ -12,7 +12,7 @@ module Ykutils
|
|
12
12
|
TEST_ID_NO_VALUE = 0
|
13
13
|
TEST_ID_LISTUP_ALL = 1
|
14
14
|
|
15
|
-
def initialize(opts = {}, _argv = [], _debug
|
15
|
+
def initialize(opts = {}, _argv = [], _debug: false)
|
16
16
|
@fname = nil
|
17
17
|
@check_flag = opts["check"]
|
18
18
|
@ifname = opts["input_file"]
|
@@ -30,7 +30,7 @@ module Ykutils
|
|
30
30
|
def exec
|
31
31
|
if @reform_flag
|
32
32
|
reform
|
33
|
-
elsif @test_id
|
33
|
+
elsif @test_id.positive?
|
34
34
|
case @test_id
|
35
35
|
when TEST_ID_LISTUP_ALL
|
36
36
|
test_listup
|
@@ -104,8 +104,8 @@ module Ykutils
|
|
104
104
|
|
105
105
|
def import(fname)
|
106
106
|
ret = false
|
107
|
-
if File.file?(fname)
|
108
|
-
@ptext = load_plain_text_file(fname).collect
|
107
|
+
if File.file?(fname) && File.readable?(fname)
|
108
|
+
@ptext = load_plain_text_file(fname).collect(&:chomp)
|
109
109
|
ret = false
|
110
110
|
end
|
111
111
|
ret
|
@@ -115,10 +115,9 @@ module Ykutils
|
|
115
115
|
ret = import(fname)
|
116
116
|
if ret
|
117
117
|
@ptext_hash = {}
|
118
|
-
i = 0
|
119
118
|
@ptext_hash = make_hash(@ptext, 0) do |l, i|
|
120
|
-
if l !~ /^\s/
|
121
|
-
key,
|
119
|
+
if l !~ (/^\s/) && l !~ (/^==/)
|
120
|
+
key, = l.split(":")
|
122
121
|
[key, { "CONTENT" => l, "INDEX" => i }]
|
123
122
|
end
|
124
123
|
end
|
@@ -136,14 +135,14 @@ module Ykutils
|
|
136
135
|
end
|
137
136
|
|
138
137
|
def listup_domain
|
139
|
-
@ptext.
|
138
|
+
@ptext.grep(/^==/)
|
140
139
|
end
|
141
140
|
|
142
141
|
def output_yaml(obj, fname)
|
143
142
|
File.open(fname, "w") do |file|
|
144
143
|
YAML.dump(obj, file)
|
145
144
|
end
|
146
|
-
rescue
|
145
|
+
rescue YkutilsError => e
|
147
146
|
pp e
|
148
147
|
pp e.backtrace
|
149
148
|
@valid = false
|
@@ -165,19 +164,19 @@ module Ykutils
|
|
165
164
|
File.open(fname, "w") do |file|
|
166
165
|
@yamlstext.dump(file)
|
167
166
|
end
|
168
|
-
rescue
|
167
|
+
rescue YkutilsError => e
|
169
168
|
pp e
|
170
169
|
pp e.backtrace
|
171
170
|
@valid = false
|
172
171
|
end
|
173
172
|
|
174
173
|
def dump_ptext_to_file(fname)
|
175
|
-
|
174
|
+
File.open(fname, "w") do |file|
|
176
175
|
@ptext.each do |l|
|
177
|
-
file.write(l
|
176
|
+
file.write("#{l}\n")
|
178
177
|
end
|
179
178
|
end
|
180
|
-
rescue
|
179
|
+
rescue YkutilsdError => e
|
181
180
|
pp e
|
182
181
|
pp e.backtrace
|
183
182
|
@valid = false
|
@@ -190,25 +189,25 @@ module Ykutils
|
|
190
189
|
|
191
190
|
def reform
|
192
191
|
ret = importex(@ifname)
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
str2 = ary2.join(" , ")
|
205
|
-
new_domain_list = "=-DOMAIN_LIST: [#{str2}]"
|
206
|
-
pp "==new_host_list"
|
207
|
-
pp new_host_list
|
208
|
-
exchange_ptext("=-HOST_LIST", new_host_list)
|
209
|
-
exchange_ptext("=-DOMAIN_LIST", new_domain_list)
|
210
|
-
dump_ptext_to_file(@ofname)
|
192
|
+
return unless ret
|
193
|
+
|
194
|
+
ary = listup_host.collect do |it|
|
195
|
+
key, = it.split(":")
|
196
|
+
key
|
197
|
+
end
|
198
|
+
str = ary.join(" , ")
|
199
|
+
new_host_list = "=-HOST_LIST: [#{str}]"
|
200
|
+
ary2 = listup_domain.collect do |it|
|
201
|
+
key, = it.split(":")
|
202
|
+
key
|
211
203
|
end
|
204
|
+
str2 = ary2.join(" , ")
|
205
|
+
new_domain_list = "=-DOMAIN_LIST: [#{str2}]"
|
206
|
+
pp "==new_host_list"
|
207
|
+
pp new_host_list
|
208
|
+
exchange_ptext("=-HOST_LIST", new_host_list)
|
209
|
+
exchange_ptext("=-DOMAIN_LIST", new_domain_list)
|
210
|
+
dump_ptext_to_file(@ofname)
|
212
211
|
end
|
213
212
|
|
214
213
|
def extract_value(ary)
|
data/lib/ykutils/yamlxop.rb
CHANGED
data/lib/ykutils.rb
CHANGED
@@ -26,8 +26,11 @@ require "ykutils/xlines"
|
|
26
26
|
require "ykutils/yamlop"
|
27
27
|
require "ykutils/yamlxop"
|
28
28
|
|
29
|
-
require
|
29
|
+
require "pathname"
|
30
30
|
module Ykutils
|
31
31
|
TEST_DATA_DIR = Pathname.new(__dir__).parent + "test_data"
|
32
32
|
# Your code goes here...
|
33
|
+
|
34
|
+
class YkutilsError < StandardError
|
35
|
+
end
|
33
36
|
end
|
data/ykutils.gemspec
CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_dependency "tilt"
|
39
39
|
# spec.add_development_dependency "rubocop-rake"
|
40
40
|
# spec.add_development_dependency "rubocop-rspec"
|
41
|
+
# spec.add_development_dependency 'yard'
|
41
42
|
|
42
43
|
# For more information and examples about making a new gem, check out our
|
43
44
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ykutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasuo kominami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/dependabot.yml"
|
62
63
|
- ".github/workflows/main.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- ".rspec"
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- LICENSE.txt
|
72
73
|
- README.md
|
73
74
|
- Rakefile
|
75
|
+
- SECURITY.md
|
74
76
|
- bin/console
|
75
77
|
- bin/erubix
|
76
78
|
- bin/erubix2
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.5.11
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: utilty function created by yk.
|