depengine 3.0.20 → 3.0.21
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/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +52 -0
- data/Gemfile.lock +16 -1
- data/Rakefile +9 -9
- data/bin/cdb_crypt +2 -2
- data/bin/de +1 -1
- data/bin/depengine +2 -2
- data/bin/spec_setup +2 -2
- data/depengine.gemspec +22 -21
- data/lib/depengine/asserter/url.rb +8 -9
- data/lib/depengine/cli.rb +12 -14
- data/lib/depengine/dsl/cdb.rb +16 -17
- data/lib/depengine/dsl/deployment.rb +42 -50
- data/lib/depengine/dsl/dweb.rb +10 -11
- data/lib/depengine/dsl/executor.rb +5 -5
- data/lib/depengine/dsl/fileops.rb +3 -4
- data/lib/depengine/dsl/helper.rb +26 -28
- data/lib/depengine/dsl/iis.rb +21 -24
- data/lib/depengine/dsl/patch.rb +22 -46
- data/lib/depengine/dsl/publisher.rb +14 -14
- data/lib/depengine/dsl/remote.rb +11 -13
- data/lib/depengine/dsl/repository.rb +19 -21
- data/lib/depengine/dsl/template.rb +19 -19
- data/lib/depengine/dsl/zip.rb +24 -24
- data/lib/depengine/helper/cli_helper.rb +9 -11
- data/lib/depengine/helper/hudson.rb +15 -19
- data/lib/depengine/helper/mail.rb +19 -25
- data/lib/depengine/helper/properties.rb +33 -52
- data/lib/depengine/helper/smb.rb +19 -25
- data/lib/depengine/helper/validations.rb +7 -7
- data/lib/depengine/helper/yaml.rb +7 -9
- data/lib/depengine/log/log.rb +3 -6
- data/lib/depengine/processor/erb_template.rb +42 -47
- data/lib/depengine/processor/fileops.rb +39 -48
- data/lib/depengine/processor/local_execute.rb +6 -4
- data/lib/depengine/processor/properties.rb +34 -56
- data/lib/depengine/processor/sed.rb +8 -12
- data/lib/depengine/processor/tags.rb +9 -10
- data/lib/depengine/processor/template.rb +27 -32
- data/lib/depengine/processor/zip.rb +16 -20
- data/lib/depengine/provider/cdb.rb +64 -71
- data/lib/depengine/provider/cdb_filesystem.rb +18 -26
- data/lib/depengine/provider/git.rb +37 -42
- data/lib/depengine/provider/repository.rb +161 -176
- data/lib/depengine/publisher/dweb.rb +74 -90
- data/lib/depengine/publisher/iis.rb +23 -30
- data/lib/depengine/publisher/rsync.rb +14 -17
- data/lib/depengine/publisher/samba.rb +12 -14
- data/lib/depengine/publisher/sftp.rb +51 -61
- data/lib/depengine/publisher/ssh.rb +19 -22
- data/lib/depengine/publisher/tomcat.rb +19 -21
- data/lib/depengine/reporter/cdb.rb +2 -3
- data/lib/depengine/version.rb +1 -1
- data/lib/depengine.rb +1 -2
- data/spec/cdb_spec.rb +8 -10
- data/spec/demo_recipe/recipes/demo.rb +10 -10
- data/spec/deployhelper_spec.rb +20 -21
- data/spec/fileops_spec.rb +11 -12
- data/spec/git_spec.rb +8 -4
- data/spec/helper_spec.rb +75 -75
- data/spec/junit.rb +47 -49
- data/spec/local_execute.rb +7 -7
- data/spec/log_spec.rb +17 -18
- data/spec/properties_spec.rb +13 -15
- data/spec/recipe_spec.rb +15 -16
- data/spec/repository_spec.rb +20 -20
- data/spec/ssh_spec.rb +18 -19
- data/spec/template_spec.rb +30 -30
- data/spec/zip_spec.rb +7 -7
- metadata +18 -2
@@ -1,65 +1,61 @@
|
|
1
1
|
module Processor
|
2
|
-
class
|
2
|
+
class ErbTemplate
|
3
3
|
include Processor
|
4
4
|
attr_accessor :basepath
|
5
|
-
attr_writer
|
5
|
+
attr_writer :cdb
|
6
6
|
|
7
7
|
# Render a template and write the output to a file or directory
|
8
8
|
# structure under 'basepath'
|
9
|
-
def parse_template(template_source,
|
10
|
-
Helper.validates_presence_of basepath,
|
9
|
+
def parse_template(template_source, _content, outdir, options = {})
|
10
|
+
Helper.validates_presence_of basepath, 'Basepath not set for template engine'
|
11
11
|
# expand basepath
|
12
12
|
self.basepath = File.expand_path basepath
|
13
13
|
|
14
|
-
if File.file?(
|
15
|
-
source_root_path = File.join(
|
16
|
-
single_file = File.join(
|
14
|
+
if File.file?(File.join(basepath, template_source))
|
15
|
+
source_root_path = File.join(basepath, File.dirname(template_source))
|
16
|
+
single_file = File.join(basepath, template_source)
|
17
17
|
else
|
18
18
|
# source is a directory
|
19
|
-
source_root_path = File.join(
|
19
|
+
source_root_path = File.join(basepath, template_source)
|
20
20
|
single_file = nil
|
21
21
|
end
|
22
|
-
target_root_path = File.join(
|
22
|
+
target_root_path = File.join(basepath, outdir)
|
23
23
|
target_path = target_root_path
|
24
24
|
|
25
|
-
Find.find(
|
25
|
+
Find.find(single_file || source_root_path) do |path|
|
26
26
|
# next if we found ourself
|
27
27
|
next if path == source_root_path
|
28
|
-
|
29
|
-
sub_dir = File.join( File.dirname( path ).split(/\//) - \
|
30
|
-
source_root_path.split(/\//) )
|
31
|
-
target_path = File.join( target_root_path, sub_dir )
|
32
|
-
target = File.join( target_path, File.basename( path ) )
|
33
28
|
|
34
|
-
|
29
|
+
sub_dir = File.join(File.dirname(path).split(/\//) - \
|
30
|
+
source_root_path.split(/\//))
|
31
|
+
target_path = File.join(target_root_path, sub_dir)
|
32
|
+
target = File.join(target_path, File.basename(path))
|
33
|
+
|
34
|
+
if options[:excludes]
|
35
35
|
options[:excludes].each do |exclude|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
next
|
40
|
-
end
|
36
|
+
next unless target.include? exclude
|
37
|
+
$log.writer.debug "Skip template #{target}"
|
38
|
+
Find.prune
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
if File.directory? path
|
45
|
-
|
46
|
-
FileUtils.mkdir_p(
|
43
|
+
unless File.directory? target
|
44
|
+
FileUtils.mkdir_p(target)
|
47
45
|
$log.writer.debug "Create directory #{target}"
|
48
46
|
end
|
49
47
|
else
|
50
|
-
target_file = File.join(
|
51
|
-
|
48
|
+
target_file = File.join(target_path, \
|
49
|
+
File.basename(target, '.erb'))
|
52
50
|
begin
|
53
51
|
if not File.binary? path and not File.zero? path
|
54
52
|
writer = File.new(target_file, 'w')
|
55
|
-
|
56
|
-
writer.
|
57
|
-
writer.close if not writer.nil?
|
58
|
-
writer = nil
|
53
|
+
writer.write(ERB.new(File.read(path)).result)
|
54
|
+
writer.close unless writer.nil?
|
59
55
|
else
|
60
56
|
FileUtils.cp(path, File.expand_path(target_file))
|
61
57
|
end
|
62
|
-
rescue
|
58
|
+
rescue => e
|
63
59
|
$log.writer.error "Can not write output from template to #{target_file}"
|
64
60
|
$log.writer.error e.message
|
65
61
|
exit 1
|
@@ -78,50 +74,49 @@ module Processor
|
|
78
74
|
def parse(template, content)
|
79
75
|
context = load_tags(content, @cdb)
|
80
76
|
begin
|
81
|
-
parser = Radius::Parser.new(context, :
|
82
|
-
template_content =
|
83
|
-
result =
|
77
|
+
parser = Radius::Parser.new(context, tag_prefix: 't')
|
78
|
+
template_content = ''
|
79
|
+
result = ''
|
84
80
|
if File.file? template
|
85
|
-
read_mode =
|
81
|
+
read_mode = ''
|
86
82
|
if RUBY_VERSION < '1.9'
|
87
83
|
read_mode = 'r'
|
88
84
|
else
|
89
85
|
read_mode = 'rb'
|
90
86
|
end
|
91
87
|
File.open(template, read_mode) do |f|
|
92
|
-
c =
|
93
|
-
f.ungetc c unless (c = f.getc)=="\uFEFF" # remove BOM, if present
|
94
|
-
while line = f.gets
|
88
|
+
c = '' # rubocop:disable Lint/UselessAssignment
|
89
|
+
f.ungetc c unless (c = f.getc) == "\uFEFF" # remove BOM, if present
|
90
|
+
while line = f.gets # rubocop:disable Lint/AssignmentInCondition
|
95
91
|
template_content << line
|
96
92
|
end
|
97
93
|
end
|
98
94
|
else
|
99
95
|
template_content = template
|
100
96
|
end
|
101
|
-
|
102
|
-
result = parser.parse(template_content)
|
103
|
-
nested_result_1 =
|
97
|
+
|
98
|
+
result = parser.parse(template_content)
|
99
|
+
nested_result_1 = ''
|
104
100
|
nested_result_2 = result
|
105
101
|
nested_loop = 0
|
106
|
-
while( nested_result_1 != nested_result_2
|
102
|
+
while ( nested_result_1 != nested_result_2)
|
107
103
|
if nested_loop >= 100
|
108
|
-
$log.writer.error
|
104
|
+
$log.writer.error 'Template stack overflow, too many nested tags'
|
109
105
|
exit 1
|
110
106
|
end
|
111
107
|
nested_result_1 = parser.parse(nested_result_2)
|
112
108
|
nested_result_2 = parser.parse(nested_result_1)
|
113
109
|
|
114
110
|
nested_loop = nested_loop + 1
|
115
|
-
|
116
|
-
|
117
|
-
rescue
|
111
|
+
end
|
112
|
+
result = nested_result_2
|
113
|
+
rescue => e
|
118
114
|
$log.writer.error "Error in template processing: #{template}"
|
119
115
|
$log.writer.error e.message
|
120
116
|
exit 1
|
121
117
|
end
|
122
|
-
|
118
|
+
|
123
119
|
result
|
124
120
|
end
|
125
121
|
end
|
126
122
|
end
|
127
|
-
|
@@ -1,74 +1,66 @@
|
|
1
1
|
module Processor
|
2
|
-
def copy(source, target, options={})
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
FileUtils.cp_r(entry, target)
|
9
|
-
end
|
2
|
+
def copy(source, target, options = {})
|
3
|
+
if not options[:match].nil? and File.directory? source
|
4
|
+
Dir.glob(File.join(source, '*')) do |entry|
|
5
|
+
if File.fnmatch(options[:match], entry)
|
6
|
+
$log.writer.debug "Copy #{entry} to #{target}"
|
7
|
+
FileUtils.cp_r(entry, target)
|
10
8
|
end
|
11
|
-
else
|
12
|
-
$log.writer.debug "Copy #{source} to #{target}"
|
13
|
-
FileUtils.cp_r(source, target)
|
14
9
|
end
|
15
|
-
|
16
|
-
$log.writer.
|
17
|
-
|
18
|
-
exit 1
|
10
|
+
else
|
11
|
+
$log.writer.debug "Copy #{source} to #{target}"
|
12
|
+
FileUtils.cp_r(source, target)
|
19
13
|
end
|
14
|
+
rescue => e
|
15
|
+
$log.writer.error "Can not copy #{source} to #{target}"
|
16
|
+
$log.writer.error e.message
|
17
|
+
exit 1
|
20
18
|
end
|
21
19
|
module_function :copy
|
22
20
|
|
23
21
|
def mkdir(directory)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
exit 1
|
31
|
-
end
|
22
|
+
FileUtils.mkdir_p(directory)
|
23
|
+
$log.writer.debug "Create directory #{directory}"
|
24
|
+
rescue => e
|
25
|
+
$log.writer.error "Can not create directory #{directory}"
|
26
|
+
$log.writer.error e.message
|
27
|
+
exit 1
|
32
28
|
end
|
33
29
|
module_function :mkdir
|
34
30
|
|
35
|
-
def chmod(file, mode, options={})
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
FileUtils.chmod(mode, file)
|
41
|
-
end
|
42
|
-
$log.writer.debug "Chmod #{file} to #{mode}"
|
43
|
-
rescue Exception => e
|
44
|
-
$log.writer.error "Can not change mode on file #{file}"
|
45
|
-
$log.writer.error e.message
|
46
|
-
exit 1
|
31
|
+
def chmod(file, mode, options = {})
|
32
|
+
if not options[:recursive].nil? and options[:recursive] == true
|
33
|
+
FileUtils.chmod_R(mode, file)
|
34
|
+
else
|
35
|
+
FileUtils.chmod(mode, file)
|
47
36
|
end
|
37
|
+
$log.writer.debug "Chmod #{file} to #{mode}"
|
38
|
+
rescue => e
|
39
|
+
$log.writer.error "Can not change mode on file #{file}"
|
40
|
+
$log.writer.error e.message
|
41
|
+
exit 1
|
48
42
|
end
|
49
43
|
module_function :chmod
|
50
44
|
|
51
45
|
def remove(file)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
exit 1
|
59
|
-
end
|
46
|
+
FileUtils.rm_rf(file)
|
47
|
+
$log.writer.debug "Delete #{file}"
|
48
|
+
rescue => e
|
49
|
+
$log.writer.error "Can not delete file #{file}"
|
50
|
+
$log.writer.error e.message
|
51
|
+
exit 1
|
60
52
|
end
|
61
53
|
module_function :remove
|
62
54
|
|
63
55
|
def mklink(source, target)
|
64
|
-
|
56
|
+
unless File.exist? source
|
65
57
|
$log.writer.debug \
|
66
|
-
|
58
|
+
'Create link to nowhere, this deployment is broken by design!'
|
67
59
|
end
|
68
60
|
begin
|
69
61
|
$log.writer.debug "Create link from #{source} to #{target}"
|
70
62
|
FileUtils.ln_s(source, target)
|
71
|
-
rescue
|
63
|
+
rescue => e
|
72
64
|
$log.writer.error "Can not create link #{target}"
|
73
65
|
$log.writer.error e.message
|
74
66
|
exit 1
|
@@ -80,7 +72,7 @@ module Processor
|
|
80
72
|
CSV.foreach(list) do |file|
|
81
73
|
if not file.nil? and not file.first.nil?
|
82
74
|
$log.writer.debug "Checking file #{File.join(target, file.first)}"
|
83
|
-
|
75
|
+
unless File.exist?(File.join(target, file.first))
|
84
76
|
$log.writer.error "Necessary file not found: #{file}"
|
85
77
|
exit 1
|
86
78
|
end
|
@@ -89,4 +81,3 @@ module Processor
|
|
89
81
|
end
|
90
82
|
module_function :check_filelist
|
91
83
|
end
|
92
|
-
|
@@ -1,17 +1,19 @@
|
|
1
1
|
module Processor
|
2
|
-
|
3
2
|
def local_execute(shell_cmds)
|
3
|
+
outputs = []
|
4
4
|
shell_cmds.each do |shell_cmd|
|
5
|
+
outputs.push shell_cmd
|
5
6
|
$log.writer.debug "executing: #{shell_cmd}"
|
6
|
-
output =
|
7
|
-
|
7
|
+
output = ` /bin/bash --login -c \"#{shell_cmd}\" `
|
8
|
+
outputs.push output
|
9
|
+
if $CHILD_STATUS.exitstatus == 0
|
8
10
|
$log.writer.debug output
|
9
11
|
else
|
10
12
|
$log.writer.error output
|
11
13
|
exit 1
|
12
14
|
end
|
13
15
|
end
|
16
|
+
outputs
|
14
17
|
end
|
15
18
|
module_function :local_execute
|
16
|
-
|
17
19
|
end
|
@@ -1,49 +1,41 @@
|
|
1
1
|
module Processor
|
2
2
|
class Properties
|
3
|
-
|
4
3
|
attr_accessor :properties_hash
|
5
4
|
attr_accessor :assigner
|
6
5
|
|
7
|
-
def initialize
|
8
|
-
properties_hash = {}
|
9
|
-
assigner =
|
6
|
+
def initialize
|
7
|
+
@properties_hash = {}
|
8
|
+
@assigner = '='
|
10
9
|
end
|
11
10
|
|
12
11
|
### patch properties (key/value)
|
13
12
|
def patch(source, target)
|
14
|
-
|
15
|
-
if not File.file? source
|
13
|
+
unless File.file? source
|
16
14
|
$log.writer.error "File #{source} does not exists"
|
17
15
|
exit 1
|
18
16
|
end
|
19
17
|
|
20
18
|
if target.nil?
|
21
|
-
$log.writer.error
|
19
|
+
$log.writer.error 'Parameter target not set'
|
22
20
|
exit 1
|
23
21
|
end
|
24
22
|
|
25
23
|
if target.length == 0
|
26
|
-
$log.writer.error
|
24
|
+
$log.writer.error 'Parameter target not set'
|
27
25
|
exit 1
|
28
26
|
end
|
29
27
|
|
30
28
|
data = File.open(source, 'rb').readlines
|
31
|
-
target_file = File.open(target,
|
29
|
+
target_file = File.open(target, 'w')
|
32
30
|
|
33
|
-
data.each
|
31
|
+
data.each do |entry|
|
34
32
|
if entry.include? assigner
|
35
|
-
keyvalue = entry.split(assigner,2)
|
33
|
+
keyvalue = entry.split(assigner, 2)
|
36
34
|
|
37
35
|
# convert all inputs to String
|
38
|
-
if keyvalue[0].class != String
|
39
|
-
|
40
|
-
|
41
|
-
if keyvalue[1].class != String
|
42
|
-
keyvalue[1] = keyvalue[1].to_s
|
43
|
-
end
|
44
|
-
if properties_hash[keyvalue[0].strip].class != String
|
45
|
-
properties_hash[keyvalue[0].strip] = properties_hash[keyvalue[0].strip].to_s
|
46
|
-
end
|
36
|
+
keyvalue[0] = keyvalue[0].to_s if keyvalue[0].class != String
|
37
|
+
keyvalue[1] = keyvalue[1].to_s if keyvalue[1].class != String
|
38
|
+
properties_hash[keyvalue[0].strip] = properties_hash[keyvalue[0].strip].to_s if properties_hash[keyvalue[0].strip].class != String
|
47
39
|
|
48
40
|
if not properties_hash[keyvalue[0].strip].nil? and
|
49
41
|
not properties_hash[keyvalue[0].strip].empty?
|
@@ -63,63 +55,56 @@ module Processor
|
|
63
55
|
end
|
64
56
|
end
|
65
57
|
target_file.puts entry
|
66
|
-
|
58
|
+
end
|
67
59
|
|
68
60
|
target_file.close
|
69
|
-
|
70
61
|
end
|
71
62
|
|
72
63
|
### patch strings
|
73
64
|
def substitute(source, target)
|
74
|
-
|
75
|
-
if not File.file? source
|
65
|
+
unless File.file? source
|
76
66
|
$log.writer.error "File #{source} does not exists"
|
77
67
|
exit 1
|
78
68
|
end
|
79
69
|
|
80
70
|
data = File.open(source, 'rb').readlines
|
81
|
-
target_file = File.open(target,
|
71
|
+
target_file = File.open(target, 'w')
|
82
72
|
|
83
|
-
data.each
|
84
|
-
properties_hash.keys.each
|
73
|
+
data.each do |entry|
|
74
|
+
properties_hash.keys.each do |hashkey|
|
85
75
|
hashkey = hashkey.to_s
|
86
76
|
entry = entry.sub(hashkey, properties_hash[hashkey].to_s)
|
87
77
|
### patch global variable
|
88
|
-
if
|
89
|
-
|
90
|
-
|
91
|
-
if not entry.nil? and entry.include?('<t:db_endpoint_2/>')
|
92
|
-
entry = entry.sub(/<t\:db_endpoint_2\/>/, properties_hash['db_endpoint_2'])
|
93
|
-
end
|
78
|
+
next if entry.nil?
|
79
|
+
entry = entry.sub(/<t\:db_endpoint_1\/>/, properties_hash['db_endpoint_1']) if entry.include?('<t:db_endpoint_1/>')
|
80
|
+
entry = entry.sub(/<t\:db_endpoint_2\/>/, properties_hash['db_endpoint_2']) if entry.include?('<t:db_endpoint_2/>')
|
94
81
|
|
95
|
-
|
82
|
+
end
|
96
83
|
target_file.puts entry
|
97
|
-
|
84
|
+
end
|
98
85
|
|
99
86
|
target_file.close
|
100
|
-
|
101
87
|
end
|
102
88
|
|
103
89
|
### patch all recursive directory
|
104
90
|
def substitute_r(source, target)
|
105
|
-
|
106
|
-
if not File.directory? source
|
91
|
+
unless File.directory? source
|
107
92
|
$log.writer.error "Directory #{source} does not exists"
|
108
93
|
exit 1
|
109
94
|
end
|
110
95
|
|
111
96
|
basepath_array = source.split('/')
|
112
97
|
|
113
|
-
Dir.glob(
|
98
|
+
Dir.glob(source + '/**/*') do |file|
|
114
99
|
keep_path = File.join(file.split('/') - basepath_array)
|
115
100
|
if File.file? file
|
116
|
-
target_path = File.join(
|
117
|
-
target_basepath = File.join(
|
101
|
+
target_path = File.join(target, keep_path)
|
102
|
+
target_basepath = File.join(File.split(target_path).first)
|
118
103
|
|
119
|
-
|
104
|
+
unless File.directory?(target_basepath)
|
120
105
|
begin
|
121
106
|
FileUtils.mkdir_p target_basepath
|
122
|
-
rescue
|
107
|
+
rescue => e
|
123
108
|
$log.writer.error "Can not create directory #{target_basepath}"
|
124
109
|
$log.writer.error e.message
|
125
110
|
exit 1
|
@@ -128,31 +113,24 @@ module Processor
|
|
128
113
|
substitute(file, target_path)
|
129
114
|
end
|
130
115
|
end
|
131
|
-
|
132
116
|
end
|
133
117
|
|
134
118
|
### append strings
|
135
119
|
def add(source, target)
|
136
|
-
|
137
|
-
if not File.file? source
|
120
|
+
unless File.file? source
|
138
121
|
$log.writer.error "File #{source} does not exists"
|
139
|
-
|
122
|
+
fail "File #{source} does not exists"
|
140
123
|
end
|
141
124
|
|
142
|
-
if source.strip != target.strip
|
143
|
-
FileUtils.copy_file(source, target)
|
144
|
-
end
|
125
|
+
FileUtils.copy_file(source, target) if source.strip != target.strip
|
145
126
|
|
146
|
-
target_file = File.open(target,
|
127
|
+
target_file = File.open(target, 'a')
|
147
128
|
|
148
|
-
properties_hash.each_value
|
129
|
+
properties_hash.each_value do |value|
|
149
130
|
target_file.puts value
|
150
|
-
|
131
|
+
end
|
151
132
|
|
152
133
|
target_file.close
|
153
|
-
|
154
134
|
end
|
155
|
-
|
156
135
|
end
|
157
|
-
|
158
136
|
end
|
@@ -1,40 +1,36 @@
|
|
1
1
|
module Sed
|
2
|
-
|
3
2
|
def self.copy(source, target, pattern, replacement)
|
4
|
-
|
3
|
+
unless File.file? source
|
5
4
|
$log.writer.error "File #{source} does not exists"
|
6
5
|
exit 1
|
7
6
|
end
|
8
|
-
|
9
|
-
File.open(source,
|
7
|
+
|
8
|
+
File.open(source, 'r:UTF-8') do |source_file|
|
10
9
|
content = source_file.read
|
11
10
|
content.gsub!(pattern, replacement)
|
12
|
-
File.open(target,
|
11
|
+
File.open(target, 'w:UTF-8') do |target_file|
|
13
12
|
target_file.write(content)
|
14
13
|
target_file.close
|
15
14
|
end
|
16
15
|
source_file.close
|
17
16
|
end
|
18
|
-
|
19
17
|
end
|
20
18
|
|
21
19
|
def self.patch(filename, pattern, replacement)
|
22
|
-
|
20
|
+
unless File.file? filename
|
23
21
|
$log.writer.error "File #{filename} does not exists"
|
24
22
|
exit 1
|
25
23
|
end
|
26
24
|
|
27
|
-
content =
|
28
|
-
File.open(filename,
|
25
|
+
content = ''
|
26
|
+
File.open(filename, 'r:UTF-8') do |source_file|
|
29
27
|
content = source_file.read
|
30
28
|
content.gsub!(pattern, replacement)
|
31
29
|
source_file.close
|
32
30
|
end
|
33
|
-
File.open(filename,
|
31
|
+
File.open(filename, 'w:UTF-8') do |target_file|
|
34
32
|
target_file.write(content)
|
35
33
|
target_file.close
|
36
34
|
end
|
37
|
-
|
38
35
|
end
|
39
|
-
|
40
36
|
end
|
@@ -2,21 +2,21 @@ module Processor
|
|
2
2
|
def load_tags(content, cdb)
|
3
3
|
begin
|
4
4
|
context = Radius::Context.new do |c|
|
5
|
-
# map all parameters from 'content' to a tag with the same name
|
5
|
+
# map all parameters from 'content' to a tag with the same name
|
6
6
|
content.each do |content_param|
|
7
|
-
c.define_tag "#{content_param.first}" do |
|
8
|
-
tag = content_param.last
|
7
|
+
c.define_tag "#{content_param.first}" do |_tag|
|
8
|
+
tag = content_param.last # rubocop:disable Lint/UselessAssignment
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
# include external file
|
13
13
|
c.define_tag 'include' do |tag|
|
14
14
|
result = ''
|
15
|
-
ext_file = File.join(
|
16
|
-
if File.
|
15
|
+
ext_file = File.join(ENV['WORKSPACE'], tag.attr['file'])
|
16
|
+
if File.exist?(ext_file)
|
17
17
|
result = File.open(ext_file).read
|
18
18
|
else
|
19
|
-
puts
|
19
|
+
puts 'Warning: can not read static data ' + ext_file
|
20
20
|
end
|
21
21
|
result
|
22
22
|
end
|
@@ -40,13 +40,13 @@ module Processor
|
|
40
40
|
puts "Warning: CDB not set for Template-Engine in tag 'feature_flag'"
|
41
41
|
end
|
42
42
|
result
|
43
|
-
end
|
43
|
+
end
|
44
44
|
|
45
|
-
c.define_tag
|
45
|
+
c.define_tag 'echo' do |tag|
|
46
46
|
tag.expand
|
47
47
|
end
|
48
48
|
end
|
49
|
-
rescue
|
49
|
+
rescue => e
|
50
50
|
$log.writer.error "Error in tag definition: #{e.message}"
|
51
51
|
$log.writer.error e.backtrace
|
52
52
|
exit 1
|
@@ -55,4 +55,3 @@ module Processor
|
|
55
55
|
context
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|