ykutils 0.1.4 → 0.1.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/.gitignore +5 -1
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +181 -85
- data/Gemfile +11 -11
- data/Gemfile.lock +17 -12
- data/bin/erubix +1 -1
- data/bin/makegrid +4 -4
- data/lib/ykutils/debugutils.rb +44 -32
- data/lib/ykutils/erubyx.rb +30 -19
- data/lib/ykutils/fileoputils.rb +2 -2
- data/lib/ykutils/gridlist.rb +49 -49
- data/lib/ykutils/lines.rb +143 -143
- data/lib/ykutils/lsutils.rb +71 -71
- data/lib/ykutils/nginxconfig.rb +40 -41
- data/lib/ykutils/nginxconfigfiles.rb +31 -31
- data/lib/ykutils/nkfutil.rb +148 -147
- data/lib/ykutils/nkfutil19.rb +9 -11
- data/lib/ykutils/osutil.rb +16 -16
- data/lib/ykutils/retcodex.rb +1 -3
- data/lib/ykutils/stext.rb +427 -425
- data/lib/ykutils/stextx.rb +32 -32
- data/lib/ykutils/stringutils.rb +111 -111
- data/lib/ykutils/treemanager.rb +33 -33
- data/lib/ykutils/treemanagera.rb +21 -21
- data/lib/ykutils/version.rb +1 -1
- data/lib/ykutils/xlines.rb +8 -8
- data/lib/ykutils/yamlop.rb +227 -227
- data/lib/ykutils/yamlxop.rb +35 -35
- data/test_data/4servers.erb +7 -7
- data/test_data/a.bat +5 -5
- data/test_data/a_ncn.bat +12 -12
- data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/t_server_1.erb +7 -7
- data/test_data/v103-3-189-127/template.erb +21 -21
- data/test_data/v103-3-189-127/template_ssl.erb +22 -22
- data/test_data/v103-3-189-127/template_ssl_www.erb +12 -12
- data/test_data/v103-3-189-127/template_www.erb +24 -24
- data/test_data/v103-3-189-127/value.yml +3 -3
- data/test_data/v103-3-189-127/value_ssl.yml +5 -5
- data/ykutils.gemspec +45 -43
- metadata +8 -9
- data/_config.yml +0 -1
data/lib/ykutils/debugutils.rb
CHANGED
@@ -3,43 +3,55 @@ require "pp"
|
|
3
3
|
module Ykutils
|
4
4
|
module DebugUtils
|
5
5
|
class DebugMes
|
6
|
+
@debug = false
|
7
|
+
@warn = false
|
8
|
+
@buf = []
|
9
|
+
|
6
10
|
def self.init(debug = false)
|
7
|
-
|
8
|
-
|
11
|
+
@debug = debug
|
12
|
+
@buf = []
|
9
13
|
end
|
10
14
|
|
11
15
|
def self.set_debug(debug)
|
12
|
-
|
16
|
+
@debug = debug
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_debug
|
20
|
+
@debug
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.set_warn(warn)
|
24
|
+
@warn = warn
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_warn
|
28
|
+
@warn
|
13
29
|
end
|
14
30
|
|
15
31
|
def self.puts_x(mes)
|
16
|
-
|
17
|
-
@@buf << mes
|
18
|
-
# puts "#{@@buf.size} |#{mes}"
|
32
|
+
@buf << mes
|
19
33
|
end
|
20
34
|
|
21
35
|
def self.get
|
22
|
-
|
23
|
-
# DebugMes.clear
|
36
|
+
@buf
|
24
37
|
end
|
25
38
|
|
26
39
|
def self.clear
|
27
|
-
|
28
|
-
@@buf.clear
|
40
|
+
@buf.clear
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
32
44
|
def clear_d
|
33
|
-
DebugMes
|
45
|
+
Ykutils::DebugUtils::DebugMes..clear
|
34
46
|
end
|
35
47
|
|
36
48
|
def puts_d(mes)
|
37
|
-
DebugMes
|
49
|
+
Ykutils::DebugUtils::DebugMes..puts_x(mes)
|
38
50
|
# puts mes
|
39
51
|
end
|
40
52
|
|
41
53
|
def get_d
|
42
|
-
|
54
|
+
self.class.get
|
43
55
|
end
|
44
56
|
|
45
57
|
def puts_current_method
|
@@ -56,46 +68,46 @@ module Ykutils
|
|
56
68
|
set_debug(false)
|
57
69
|
set_warn(0)
|
58
70
|
|
59
|
-
DebugMes.init(false)
|
71
|
+
Ykutils::DebugUtils::DebugMes.init(false)
|
60
72
|
end
|
61
73
|
|
62
74
|
def set_debug(val)
|
63
|
-
|
64
|
-
DebugMes.set_debug(val)
|
75
|
+
# self.class.set_debug(val)
|
76
|
+
Ykutils::DebugUtils::DebugMes.set_debug(val)
|
65
77
|
end
|
66
78
|
|
67
79
|
def get_debug
|
68
|
-
|
80
|
+
Ykutils::DebugUtils::DebugMes.get_debug
|
69
81
|
end
|
70
82
|
|
71
83
|
def set_warn(val)
|
72
|
-
|
84
|
+
Ykutils::DebugUtils::DebugMes.set_warn(val)
|
73
85
|
end
|
74
86
|
|
75
|
-
def
|
76
|
-
|
87
|
+
def get_warn
|
88
|
+
Ykutils::DebugUtils::DebugMes..get_warn
|
77
89
|
end
|
78
90
|
|
79
91
|
def d_exit(num)
|
80
|
-
exit(num) if
|
92
|
+
exit(num) if get_debug
|
81
93
|
end
|
82
94
|
|
83
95
|
def d_puts(str)
|
84
|
-
puts(str) if
|
96
|
+
puts(str) if get_debug
|
85
97
|
end
|
86
98
|
|
87
99
|
def w1_puts(str)
|
88
|
-
set_warn(0) unless
|
89
|
-
puts(str) if
|
100
|
+
set_warn(0) unless get_warn
|
101
|
+
puts(str) if get_debug or get_warn >= 1
|
90
102
|
end
|
91
103
|
|
92
104
|
def w2_puts(str)
|
93
|
-
set_warn(0) unless
|
94
|
-
puts(str) if
|
105
|
+
set_warn(0) unless get_warn
|
106
|
+
puts(str) if get_debug or get_warn >= 2
|
95
107
|
end
|
96
108
|
|
97
109
|
def d_caller(_num)
|
98
|
-
pp caller(0) if
|
110
|
+
pp caller(0) if get_debug
|
99
111
|
end
|
100
112
|
|
101
113
|
def puts_no_empty(mes)
|
@@ -103,20 +115,20 @@ module Ykutils
|
|
103
115
|
end
|
104
116
|
|
105
117
|
def d_puts_no_empty(mes)
|
106
|
-
puts mes if mes != "" and
|
118
|
+
puts mes if mes != "" and get_debug
|
107
119
|
end
|
108
120
|
|
109
121
|
def d_p(it)
|
110
|
-
p it if
|
122
|
+
p it if get_debug
|
111
123
|
end
|
112
124
|
|
113
125
|
def d_pp(it)
|
114
|
-
if
|
115
|
-
pp "
|
126
|
+
if get_debug
|
127
|
+
pp "debug=#{get_debug}"
|
116
128
|
pp caller(0)
|
117
129
|
exit
|
118
130
|
end
|
119
|
-
pp it if
|
131
|
+
pp it if get_debug
|
120
132
|
end
|
121
133
|
end
|
122
134
|
end
|
data/lib/ykutils/erubyx.rb
CHANGED
@@ -5,37 +5,48 @@ module Ykutils
|
|
5
5
|
module Erubyx
|
6
6
|
module_function
|
7
7
|
|
8
|
-
def erubi_render(template_hash, scope, value_hash)
|
8
|
+
def erubi_render(template_hash, scope, value_hash = {})
|
9
9
|
unless template_hash[:OBJ]
|
10
|
-
template_hash[:OBJ] = Tilt::ErubiTemplate.new{ template_hash[:TEMPLATE] }
|
10
|
+
template_hash[:OBJ] = Tilt::ErubiTemplate.new { template_hash[:TEMPLATE] }
|
11
11
|
end
|
12
|
-
template_hash[:OBJ].render(
|
12
|
+
template_hash[:OBJ].render(scope, value_hash)
|
13
13
|
end
|
14
14
|
|
15
|
-
##
|
16
|
-
# `erubi_render_with_file` takes a template file path, a scope, and a value file path, reads the
|
17
|
-
# template file, loads the value file, and then calls `erubi_render` with the template hash, scope,
|
18
|
-
# and value hash
|
19
|
-
#
|
20
|
-
# Args:
|
21
|
-
# template_file_path: The path to the template file.
|
22
|
-
# scope: the scope of the template. This is the name of the directory that the template is in.
|
23
|
-
# value_file_path: The path to the YAML file that contains the values to be used in the template.
|
15
|
+
##
|
16
|
+
# `erubi_render_with_file` takes a template file path, a scope, and a value file path, reads the
|
17
|
+
# template file, loads the value file, and then calls `erubi_render` with the template hash, scope,
|
18
|
+
# and value hash
|
19
|
+
#
|
20
|
+
# Args:
|
21
|
+
# template_file_path: The path to the template file.
|
22
|
+
# scope: the scope of the template. This is the name of the directory that the template is in.
|
23
|
+
# value_file_path: The path to the YAML file that contains the values to be used in the template.
|
24
24
|
def erubi_render_with_file(template_file_path, scope, value_file_path_array)
|
25
25
|
template_text = File.read(template_file_path)
|
26
26
|
template_hash = { TEMPLATE: template_text,
|
27
|
-
OBJ: nil
|
28
|
-
|
29
|
-
|
30
|
-
#p path
|
27
|
+
OBJ: nil }
|
28
|
+
value_hash = value_file_path_array.reduce({}) { |hash, path|
|
29
|
+
# p path
|
31
30
|
hash0 = YAML.load_file(path)
|
32
|
-
#p hash0
|
31
|
+
# p hash0
|
33
32
|
hash = hash.merge(hash0)
|
34
|
-
#p hash
|
33
|
+
# p hash
|
35
34
|
hash
|
36
35
|
}
|
37
|
-
#puts value_hash
|
36
|
+
# puts value_hash
|
38
37
|
erubi_render(template_hash, scope, value_hash)
|
39
38
|
end
|
39
|
+
|
40
|
+
def erubi_render_with_template_file(template_file_path, scope, value_hash = {})
|
41
|
+
template_text = File.read(template_file_path)
|
42
|
+
template_hash = make_template_hash(template_text)
|
43
|
+
# puts value_hash
|
44
|
+
erubi_render(template_hash, scope, value_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
def make_template_hash(text)
|
48
|
+
{ TEMPLATE: text,
|
49
|
+
OBJ: nil }
|
50
|
+
end
|
40
51
|
end
|
41
52
|
end
|
data/lib/ykutils/fileoputils.rb
CHANGED
@@ -154,7 +154,7 @@ module Ykutils
|
|
154
154
|
ary = []
|
155
155
|
begin
|
156
156
|
File.open(input_file_path, "r") do |file|
|
157
|
-
while line = file.gets
|
157
|
+
while (line = file.gets)
|
158
158
|
line.chomp!
|
159
159
|
ary << file_content_process(line)
|
160
160
|
end
|
@@ -194,7 +194,7 @@ module Ykutils
|
|
194
194
|
ary = []
|
195
195
|
begin
|
196
196
|
File.open(from_path, "r") do |file|
|
197
|
-
while line = file.gets
|
197
|
+
while (line = file.gets)
|
198
198
|
line.chomp!
|
199
199
|
ary << file_content_process(line)
|
200
200
|
end
|
data/lib/ykutils/gridlist.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'ykutils/erubyx'
|
2
|
-
|
3
|
-
module Ykutils
|
4
|
-
module Gridlist
|
5
|
-
TAMPLETES = { :GRID_DEF =>
|
6
|
-
{ :TEMPLATE => %!
|
7
|
-
.g-<%= row %>-<%= colum %> {
|
8
|
-
grid-row-start: <%= row %>;
|
9
|
-
grid-row-end: ,<%= row + 1 %>;
|
10
|
-
grid-column-start: <%= colum %>;
|
11
|
-
grid-column-end: <%= colum + 1 %>;
|
12
|
-
}
|
13
|
-
|
14
|
-
|
15
|
-
module_function
|
16
|
-
|
17
|
-
def make_one_grid(hash, row, colum)
|
18
|
-
unless hash[:OBJ]
|
19
|
-
hash[:OBJ] = Tilt::ErubiTemplate.new{ hash[:TEMPLATE] }
|
20
|
-
end
|
21
|
-
hash[:OBJ].render(
|
22
|
-
end
|
23
|
-
|
24
|
-
def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
25
|
-
(min_row..max_row).map { |row|
|
26
|
-
(min_colum..max_colum).map { |colum|
|
27
|
-
#puts "#{row} #{colum}"
|
28
|
-
value_hash = { row: row, colum: colum }
|
29
|
-
#make_one_grid(template_hash, value_hash)
|
30
|
-
#p template_hash
|
31
|
-
#p value_hash
|
32
|
-
Ykutils::Erubyx::erubi_render(template_hash, scope, value_hash)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
def make_grid_list(min_row, max_row, min_colum, max_colum)
|
38
|
-
template_hash = TAMPLETES[:GRID_DEF]
|
39
|
-
scope = nil
|
40
|
-
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
41
|
-
end
|
42
|
-
|
43
|
-
def make_grid_list_x(min_row, max_row, min_colum, max_colum)
|
44
|
-
template_hash = TAMPLETES[:GRID_DEF]
|
45
|
-
scope = nil
|
46
|
-
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'ykutils/erubyx'
|
2
|
+
|
3
|
+
module Ykutils
|
4
|
+
module Gridlist
|
5
|
+
TAMPLETES = { :GRID_DEF =>
|
6
|
+
{ :TEMPLATE => %!
|
7
|
+
.g-<%= row %>-<%= colum %> {
|
8
|
+
grid-row-start: <%= row %>;
|
9
|
+
grid-row-end: ,<%= row + 1 %>;
|
10
|
+
grid-column-start: <%= colum %>;
|
11
|
+
grid-column-end: <%= colum + 1 %>;
|
12
|
+
}
|
13
|
+
!, :OBJ => nil } }
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def make_one_grid(hash, row, colum)
|
18
|
+
unless hash[:OBJ]
|
19
|
+
hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] }
|
20
|
+
end
|
21
|
+
hash[:OBJ].render(Object.new, { row: row, colum: colum })
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
25
|
+
(min_row..max_row).map { |row|
|
26
|
+
(min_colum..max_colum).map { |colum|
|
27
|
+
# puts "#{row} #{colum}"
|
28
|
+
value_hash = { row: row, colum: colum }
|
29
|
+
# make_one_grid(template_hash, value_hash)
|
30
|
+
# p template_hash
|
31
|
+
# p value_hash
|
32
|
+
Ykutils::Erubyx::erubi_render(template_hash, scope, value_hash)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def make_grid_list(min_row, max_row, min_colum, max_colum)
|
38
|
+
template_hash = TAMPLETES[:GRID_DEF]
|
39
|
+
scope = nil
|
40
|
+
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_grid_list_x(min_row, max_row, min_colum, max_colum)
|
44
|
+
template_hash = TAMPLETES[:GRID_DEF]
|
45
|
+
scope = nil
|
46
|
+
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/ykutils/lines.rb
CHANGED
@@ -1,143 +1,143 @@
|
|
1
|
-
module Ykutils
|
2
|
-
class BasicLines
|
3
|
-
def initialize(line_ary)
|
4
|
-
@line_ary = line_ary
|
5
|
-
end
|
6
|
-
|
7
|
-
def get_line
|
8
|
-
@line_ary.shift if @line_ary.size > -1
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Lines
|
13
|
-
def initialize(line_ary)
|
14
|
-
@lines = BasicLines.new(line_ary)
|
15
|
-
@line_stack = []
|
16
|
-
@status = nil
|
17
|
-
|
18
|
-
setup
|
19
|
-
end
|
20
|
-
|
21
|
-
def setup; end
|
22
|
-
|
23
|
-
def get_line
|
24
|
-
@line_stack.shift if @line_stack.size > -1
|
25
|
-
end
|
26
|
-
|
27
|
-
def output_f(fname)
|
28
|
-
if fname
|
29
|
-
File.open(fname, "w") do |file|
|
30
|
-
@line_stack.each do |it|
|
31
|
-
file.write(it.to_s)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class FtpOpLines < BasicLines
|
39
|
-
end
|
40
|
-
|
41
|
-
# class AccountLines < BasicLines
|
42
|
-
class AccountLines < Lines
|
43
|
-
HOST_ACCOUNT_START = 10
|
44
|
-
HOST_ACCOUNT = 11
|
45
|
-
HOST_ACCOUNT_END = 12
|
46
|
-
DOMAIN_ACCOUNT_START = 20
|
47
|
-
DOMAIN_ACCOUNT = 21
|
48
|
-
DOMAIN_ACCOUNT_END = 22
|
49
|
-
SEPARATOR = 30
|
50
|
-
ETC = 100
|
51
|
-
|
52
|
-
def setup
|
53
|
-
while line = @lines.get_line
|
54
|
-
next if line.strip == ""
|
55
|
-
|
56
|
-
if line =~ /^---/
|
57
|
-
case @status
|
58
|
-
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
59
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
60
|
-
"CONTENT" => nil })
|
61
|
-
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
62
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
63
|
-
"CONTENT" => nil })
|
64
|
-
end
|
65
|
-
|
66
|
-
@line_stack.push({ "STATUS" => SEPARATOR,
|
67
|
-
"CONTENT" => line })
|
68
|
-
@status = SEPARATOR
|
69
|
-
elsif line =~ /^\s/
|
70
|
-
case @status
|
71
|
-
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
72
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT,
|
73
|
-
"CONTENT" => line })
|
74
|
-
@status = HOST_ACCOUNT
|
75
|
-
when HOST_ACCOUNT_END
|
76
|
-
puts("error!")
|
77
|
-
puts(line)
|
78
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT,
|
79
|
-
"CONTENT" => line })
|
80
|
-
@status = HOST_ACCOUNT
|
81
|
-
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
82
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
|
83
|
-
"CONTENT" => line })
|
84
|
-
@status = DOMAIN_ACCOUNT
|
85
|
-
when DOMAIN_ACCOUNT_END
|
86
|
-
puts("error!")
|
87
|
-
puts(line)
|
88
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
|
89
|
-
"CONTENT" => line })
|
90
|
-
@status = DOMAIN_ACCOUNT
|
91
|
-
else
|
92
|
-
@line_stack.push({ "STATUS" => ETC,
|
93
|
-
"CONTENT" => line })
|
94
|
-
@status = ETC
|
95
|
-
end
|
96
|
-
elsif line =~ /^==/
|
97
|
-
case @status
|
98
|
-
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
99
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
100
|
-
"CONTENT" => nil })
|
101
|
-
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
102
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
103
|
-
"CONTENT" => nil })
|
104
|
-
end
|
105
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_START,
|
106
|
-
"CONTENT" => line })
|
107
|
-
@status = DOMAIN_ACCOUNT_START
|
108
|
-
else
|
109
|
-
case @status
|
110
|
-
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
111
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
112
|
-
"CONTENT" => nil })
|
113
|
-
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
114
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
115
|
-
"CONTENT" => nil })
|
116
|
-
end
|
117
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT_START,
|
118
|
-
"CONTENT" => line })
|
119
|
-
@status = HOST_ACCOUNT_START
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
i = @line_stack.size - 1
|
124
|
-
seeking = true
|
125
|
-
while i >= 0 and seeking
|
126
|
-
case @line_stack[i]["STATUS"]
|
127
|
-
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
128
|
-
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
129
|
-
"CONTENT" => nil })
|
130
|
-
seeking = false
|
131
|
-
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
132
|
-
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
133
|
-
"CONTENT" => nil })
|
134
|
-
seeking = false
|
135
|
-
when ETC
|
136
|
-
else
|
137
|
-
seeking = false
|
138
|
-
end
|
139
|
-
i -= 1
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
1
|
+
module Ykutils
|
2
|
+
class BasicLines
|
3
|
+
def initialize(line_ary)
|
4
|
+
@line_ary = line_ary
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_line
|
8
|
+
@line_ary.shift if @line_ary.size > -1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Lines
|
13
|
+
def initialize(line_ary)
|
14
|
+
@lines = BasicLines.new(line_ary)
|
15
|
+
@line_stack = []
|
16
|
+
@status = nil
|
17
|
+
|
18
|
+
setup
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup; end
|
22
|
+
|
23
|
+
def get_line
|
24
|
+
@line_stack.shift if @line_stack.size > -1
|
25
|
+
end
|
26
|
+
|
27
|
+
def output_f(fname)
|
28
|
+
if fname
|
29
|
+
File.open(fname, "w") do |file|
|
30
|
+
@line_stack.each do |it|
|
31
|
+
file.write(it.to_s)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class FtpOpLines < BasicLines
|
39
|
+
end
|
40
|
+
|
41
|
+
# class AccountLines < BasicLines
|
42
|
+
class AccountLines < Lines
|
43
|
+
HOST_ACCOUNT_START = 10
|
44
|
+
HOST_ACCOUNT = 11
|
45
|
+
HOST_ACCOUNT_END = 12
|
46
|
+
DOMAIN_ACCOUNT_START = 20
|
47
|
+
DOMAIN_ACCOUNT = 21
|
48
|
+
DOMAIN_ACCOUNT_END = 22
|
49
|
+
SEPARATOR = 30
|
50
|
+
ETC = 100
|
51
|
+
|
52
|
+
def setup
|
53
|
+
while (line = @lines.get_line)
|
54
|
+
next if line.strip == ""
|
55
|
+
|
56
|
+
if line =~ /^---/
|
57
|
+
case @status
|
58
|
+
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
59
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
60
|
+
"CONTENT" => nil })
|
61
|
+
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
62
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
63
|
+
"CONTENT" => nil })
|
64
|
+
end
|
65
|
+
|
66
|
+
@line_stack.push({ "STATUS" => SEPARATOR,
|
67
|
+
"CONTENT" => line })
|
68
|
+
@status = SEPARATOR
|
69
|
+
elsif line =~ /^\s/
|
70
|
+
case @status
|
71
|
+
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
72
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT,
|
73
|
+
"CONTENT" => line })
|
74
|
+
@status = HOST_ACCOUNT
|
75
|
+
when HOST_ACCOUNT_END
|
76
|
+
puts("error!")
|
77
|
+
puts(line)
|
78
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT,
|
79
|
+
"CONTENT" => line })
|
80
|
+
@status = HOST_ACCOUNT
|
81
|
+
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
82
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
|
83
|
+
"CONTENT" => line })
|
84
|
+
@status = DOMAIN_ACCOUNT
|
85
|
+
when DOMAIN_ACCOUNT_END
|
86
|
+
puts("error!")
|
87
|
+
puts(line)
|
88
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT,
|
89
|
+
"CONTENT" => line })
|
90
|
+
@status = DOMAIN_ACCOUNT
|
91
|
+
else
|
92
|
+
@line_stack.push({ "STATUS" => ETC,
|
93
|
+
"CONTENT" => line })
|
94
|
+
@status = ETC
|
95
|
+
end
|
96
|
+
elsif line =~ /^==/
|
97
|
+
case @status
|
98
|
+
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
99
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
100
|
+
"CONTENT" => nil })
|
101
|
+
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
102
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
103
|
+
"CONTENT" => nil })
|
104
|
+
end
|
105
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_START,
|
106
|
+
"CONTENT" => line })
|
107
|
+
@status = DOMAIN_ACCOUNT_START
|
108
|
+
else
|
109
|
+
case @status
|
110
|
+
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
111
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
112
|
+
"CONTENT" => nil })
|
113
|
+
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
114
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
115
|
+
"CONTENT" => nil })
|
116
|
+
end
|
117
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT_START,
|
118
|
+
"CONTENT" => line })
|
119
|
+
@status = HOST_ACCOUNT_START
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
i = @line_stack.size - 1
|
124
|
+
seeking = true
|
125
|
+
while i >= 0 and seeking
|
126
|
+
case @line_stack[i]["STATUS"]
|
127
|
+
when DOMAIN_ACCOUNT_START, DOMAIN_ACCOUNT
|
128
|
+
@line_stack.push({ "STATUS" => DOMAIN_ACCOUNT_END,
|
129
|
+
"CONTENT" => nil })
|
130
|
+
seeking = false
|
131
|
+
when HOST_ACCOUNT_START, HOST_ACCOUNT
|
132
|
+
@line_stack.push({ "STATUS" => HOST_ACCOUNT_END,
|
133
|
+
"CONTENT" => nil })
|
134
|
+
seeking = false
|
135
|
+
when ETC
|
136
|
+
else
|
137
|
+
seeking = false
|
138
|
+
end
|
139
|
+
i -= 1
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|