ykutils 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -1
  3. data/.rubocop.yml +2 -1
  4. data/.rubocop_todo.yml +181 -85
  5. data/Gemfile +11 -11
  6. data/Gemfile.lock +17 -12
  7. data/bin/erubix +1 -1
  8. data/bin/makegrid +4 -4
  9. data/lib/ykutils/erubyx.rb +30 -19
  10. data/lib/ykutils/fileoputils.rb +2 -2
  11. data/lib/ykutils/gridlist.rb +49 -49
  12. data/lib/ykutils/lines.rb +143 -143
  13. data/lib/ykutils/lsutils.rb +71 -71
  14. data/lib/ykutils/nginxconfig.rb +40 -41
  15. data/lib/ykutils/nginxconfigfiles.rb +31 -31
  16. data/lib/ykutils/nkfutil.rb +148 -147
  17. data/lib/ykutils/nkfutil19.rb +9 -11
  18. data/lib/ykutils/osutil.rb +16 -16
  19. data/lib/ykutils/retcodex.rb +1 -3
  20. data/lib/ykutils/stext.rb +427 -425
  21. data/lib/ykutils/stextx.rb +32 -32
  22. data/lib/ykutils/stringutils.rb +111 -111
  23. data/lib/ykutils/treemanager.rb +33 -33
  24. data/lib/ykutils/treemanagera.rb +21 -21
  25. data/lib/ykutils/version.rb +1 -1
  26. data/lib/ykutils/xlines.rb +8 -8
  27. data/lib/ykutils/yamlop.rb +227 -227
  28. data/lib/ykutils/yamlxop.rb +35 -35
  29. data/test_data/4servers.erb +7 -7
  30. data/test_data/a.bat +5 -5
  31. data/test_data/a_ncn.bat +12 -12
  32. data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -28
  33. data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -1
  34. data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -28
  35. data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -1
  36. data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -28
  37. data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -1
  38. data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -28
  39. data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -1
  40. data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -28
  41. data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -1
  42. data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -28
  43. data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -1
  44. data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -28
  45. data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -1
  46. data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -28
  47. data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -1
  48. data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -28
  49. data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -1
  50. data/test_data/v103-3-189-127/t_server_1.erb +7 -7
  51. data/test_data/v103-3-189-127/template.erb +21 -21
  52. data/test_data/v103-3-189-127/template_ssl.erb +22 -22
  53. data/test_data/v103-3-189-127/template_ssl_www.erb +12 -12
  54. data/test_data/v103-3-189-127/template_www.erb +24 -24
  55. data/test_data/v103-3-189-127/value.yml +3 -3
  56. data/test_data/v103-3-189-127/value_ssl.yml +5 -5
  57. data/ykutils.gemspec +45 -43
  58. metadata +8 -9
  59. data/_config.yml +0 -1
@@ -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
- ! , :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
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
@@ -1,71 +1,71 @@
1
- require "ykutils/filepermision"
2
- require "pathname"
3
-
4
- module Ykytils
5
- class DirEntryItem
6
- attr_accessor :name, :user, :group, :size, :month, :day, :time, :year, :path, :type, :parent_dir, :valid
7
-
8
- def initialize; end
9
-
10
- def parse(str, parent_dir, valid = true)
11
- ary = str.split(/\s+/)
12
- perm = ary[0]
13
- @type = if perm[0].chr == "d"
14
- :DIRECTORY
15
- else
16
- :FILE
17
- end
18
- @perm = FilePermision.new(ary[0][1..9])
19
- @value = ary[1]
20
- @user = ary[2]
21
- @group = ary[3]
22
- @size = ary[4]
23
- @month = ary[5]
24
- @day = ary[6]
25
- str = ary[7]
26
- if str =~ /:/
27
- @year = Time.now.year
28
- @time = str
29
- else
30
- @year = str
31
- @time = "00:00:00"
32
- end
33
-
34
- @time = ary[7]
35
- @name = ary[8]
36
- @path = File.join(parent_dir, @name)
37
- @parent_dir = parent_dir
38
- @valid = valid
39
- end
40
-
41
- def to_hash
42
- { "type" => @type, "perm" => @perm.to_hash, "value" => @value, "user" => @user, "group" => @group,
43
- "size" => @size, "month" => @month, "day" => @day, "year" => @year,
44
- "time" => @time, "name" => @name, "path" => @path, "parent_dir" => @parent_dir, "valid" => @valid }
45
- end
46
-
47
- def to_csv
48
- "#{@type},#{@perm},#{@value},#{@user},#{@group},#{@size},#{@year},#{@month},#{@day},#{@time},#{@name},#{@parent_dir},#{@valid}"
49
- end
50
-
51
- def directory?
52
- @type === :DIRECTORY
53
- end
54
-
55
- def file?
56
- @type === :FILE
57
- end
58
-
59
- def owner_perm
60
- @perm.owner
61
- end
62
-
63
- def group_perm
64
- @perm.group
65
- end
66
-
67
- def otherr_perm
68
- @perm.other
69
- end
70
- end
71
- end
1
+ require "ykutils/filepermision"
2
+ require "pathname"
3
+
4
+ module Ykytils
5
+ class DirEntryItem
6
+ attr_accessor :name, :user, :group, :size, :month, :day, :time, :year, :path, :type, :parent_dir, :valid
7
+
8
+ def initialize; end
9
+
10
+ def parse(str, parent_dir, valid = true)
11
+ ary = str.split(/\s+/)
12
+ perm = ary[0]
13
+ @type = if perm[0].chr == "d"
14
+ :DIRECTORY
15
+ else
16
+ :FILE
17
+ end
18
+ @perm = FilePermision.new(ary[0][1..9])
19
+ @value = ary[1]
20
+ @user = ary[2]
21
+ @group = ary[3]
22
+ @size = ary[4]
23
+ @month = ary[5]
24
+ @day = ary[6]
25
+ str = ary[7]
26
+ if str =~ /:/
27
+ @year = Time.now.year
28
+ @time = str
29
+ else
30
+ @year = str
31
+ @time = "00:00:00"
32
+ end
33
+
34
+ @time = ary[7]
35
+ @name = ary[8]
36
+ @path = File.join(parent_dir, @name)
37
+ @parent_dir = parent_dir
38
+ @valid = valid
39
+ end
40
+
41
+ def to_hash
42
+ { "type" => @type, "perm" => @perm.to_hash, "value" => @value, "user" => @user, "group" => @group,
43
+ "size" => @size, "month" => @month, "day" => @day, "year" => @year,
44
+ "time" => @time, "name" => @name, "path" => @path, "parent_dir" => @parent_dir, "valid" => @valid }
45
+ end
46
+
47
+ def to_csv
48
+ "#{@type},#{@perm},#{@value},#{@user},#{@group},#{@size},#{@year},#{@month},#{@day},#{@time},#{@name},#{@parent_dir},#{@valid}"
49
+ end
50
+
51
+ def directory?
52
+ @type === :DIRECTORY
53
+ end
54
+
55
+ def file?
56
+ @type === :FILE
57
+ end
58
+
59
+ def owner_perm
60
+ @perm.owner
61
+ end
62
+
63
+ def group_perm
64
+ @perm.group
65
+ end
66
+
67
+ def otherr_perm
68
+ @perm.other
69
+ end
70
+ end
71
+ end
@@ -1,41 +1,40 @@
1
- module Ykutils
2
- class Nginxconfig
3
- def initialize(yaml_path)
4
- #p "yaml_path=#{yaml_path}"
5
- yaml_pn = Pathname.new(yaml_path).cleanpath
6
- @virtual_domain_dir_pn = yaml_pn.parent
7
- @server_dir_pn = @virtual_domain_dir_pn.parent
8
- @common_dir_pn = @server_dir_pn.parent
9
- @hash = YAML.load_file(yaml_pn)
10
- #p @hash
11
- @root = @hash["_root"]
12
- #p @root
13
- root_template_0_pn = Pathname.new(@root["template"]).cleanpath
14
- @root_template_pn = @common_dir_pn + root_template_0_pn
15
- # puts "@root_template_pn=#{@root_template_pn}"
16
- end
17
-
18
- def extract(scope)
19
- hashx = {}
20
- @hash.each do |k, v|
21
- if k !~ /^_/
22
- # puts k
23
- #puts v
24
- pn = Pathname.new(v["template"]).cleanpath
25
- #Pathname.new(v).cleanpath
26
- template_pn = @server_dir_pn + pn
27
- # puts(template_pn)
28
- value_file_path_array = v["value"].map{|x|
29
- @virtual_domain_dir_pn + Pathname.new(x).cleanpath
30
- }
31
- hashx[k] = Ykutils::Erubyx::erubi_render_with_file(template_pn, scope, value_file_path_array)
32
- end
33
- end
34
- template = File.read(@root_template_pn)
35
- template_hash = { TEMPLATE: template,
36
- OBJ: nil
37
- }
38
- Ykutils::Erubyx::erubi_render(template_hash, scope, hashx)
39
- end
40
- end
41
- end
1
+ module Ykutils
2
+ class Nginxconfig
3
+ def initialize(yaml_path)
4
+ # p "yaml_path=#{yaml_path}"
5
+ yaml_pn = Pathname.new(yaml_path).cleanpath
6
+ @virtual_domain_dir_pn = yaml_pn.parent
7
+ @server_dir_pn = @virtual_domain_dir_pn.parent
8
+ @common_dir_pn = @server_dir_pn.parent
9
+ @hash = YAML.load_file(yaml_pn)
10
+ # p @hash
11
+ @root = @hash["_root"]
12
+ # p @root
13
+ root_template_0_pn = Pathname.new(@root["template"]).cleanpath
14
+ @root_template_pn = @common_dir_pn + root_template_0_pn
15
+ # puts "@root_template_pn=#{@root_template_pn}"
16
+ end
17
+
18
+ def extract(scope)
19
+ hashx = {}
20
+ @hash.each do |k, v|
21
+ if k !~ /^_/
22
+ # puts k
23
+ # puts v
24
+ pn = Pathname.new(v["template"]).cleanpath
25
+ # Pathname.new(v).cleanpath
26
+ template_pn = @server_dir_pn + pn
27
+ # puts(template_pn)
28
+ value_file_path_array = v["value"].map { |x|
29
+ @virtual_domain_dir_pn + Pathname.new(x).cleanpath
30
+ }
31
+ hashx[k] = Ykutils::Erubyx::erubi_render_with_file(template_pn, scope, value_file_path_array)
32
+ end
33
+ end
34
+ template = File.read(@root_template_pn)
35
+ template_hash = { TEMPLATE: template,
36
+ OBJ: nil }
37
+ Ykutils::Erubyx::erubi_render(template_hash, scope, hashx)
38
+ end
39
+ end
40
+ end
@@ -1,31 +1,31 @@
1
- module Ykutils
2
- require 'find'
3
- class Nginxconfigfiles
4
- def get_file_list(start_dir, re)
5
- @file_list = []
6
-
7
- Find.find(start_dir){|x|
8
- if x =~ re
9
- #puts x
10
- @file_list << x
11
- Find.prune
12
- end
13
- }
14
- @file_list
15
- end
16
-
17
- def output(file_list)
18
- file_list.map{ |fname|
19
- parent_dir_pn = Pathname.new(fname).cleanpath.parent
20
- vdomain = parent_dir_pn.basename
21
- output_fname = "#{vdomain}.conf"
22
- cli = Nginxconfig.new(fname)
23
- scope = nil
24
- File.open( output_fname, "w"){|f|
25
- x = cli.extract(scope)
26
- f.write(x)
27
- }
28
- }
29
- end
30
- end
31
- end
1
+ module Ykutils
2
+ require 'find'
3
+ class Nginxconfigfiles
4
+ def get_file_list(start_dir, re)
5
+ @file_list = []
6
+
7
+ Find.find(start_dir) { |x|
8
+ if x =~ re
9
+ # puts x
10
+ @file_list << x
11
+ Find.prune
12
+ end
13
+ }
14
+ @file_list
15
+ end
16
+
17
+ def output(file_list)
18
+ file_list.map { |fname|
19
+ parent_dir_pn = Pathname.new(fname).cleanpath.parent
20
+ vdomain = parent_dir_pn.basename
21
+ output_fname = "#{vdomain}.conf"
22
+ cli = Nginxconfig.new(fname)
23
+ scope = nil
24
+ File.open(output_fname, "w") { |f|
25
+ x = cli.extract(scope)
26
+ f.write(x)
27
+ }
28
+ }
29
+ end
30
+ end
31
+ end