canzea 0.1.137 → 0.1.138
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canzea/version.rb +1 -1
- data/lib/commands/push-config.rb +85 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56e338100978ef4a62df216bc68d1cbc5cff2d59
|
4
|
+
data.tar.gz: 417dc132292f90c6e9b57ee2e2e185f39e9cf5f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 170a603e1503817f7a68aa7042386c5ce31d43cbb91a36d334a3b628aedf9cc638b824a9b0096c5349b74886df9d81eb1f9444c4e936b6c995e90a861f2ba291
|
7
|
+
data.tar.gz: 1b0929680026eba253c80b19a0cde0c5fd811d4d2d2cfed71bc7f3d03a722f0960eefe0089063d1da8b792b1bf7d0c2287283dea2daa363ead8ca758551fd5ac
|
data/lib/canzea/version.rb
CHANGED
data/lib/commands/push-config.rb
CHANGED
@@ -2,15 +2,97 @@
|
|
2
2
|
require 'git'
|
3
3
|
require 'json'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'logger'
|
6
|
+
require 'canzea'
|
5
7
|
|
6
8
|
# canzea --lifecycle=wire --solution=gogs --action=push-content --args='{"file":"metadata.json","path":"test/a/metadata.json", "comment":"V1.0"}'
|
7
|
-
# canzea --util=push-config git@165.227.87.135:root/ecosystem.git "Latest Input" --args='{"files":[{"file":"metadata.json","path":"test/a/metadata.json"}]}'
|
9
|
+
# canzea --util=push-config git@165.227.87.135:root/ecosystem.git "Latest Input" --args='{"files":[{"file":"metadata.json","path":"test/a/metadata.json"}]}'
|
10
|
+
|
11
|
+
# PushConfig.new.write "Test", "nr-global.flow", "new content and more and more"
|
12
|
+
|
13
|
+
# PushConfig.new.cp "Another bit of file", "nr-global.flow", "node-red/nr-global.flow"
|
14
|
+
|
8
15
|
|
9
16
|
class PushConfig
|
10
17
|
def initialize ()
|
11
18
|
@log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
|
12
19
|
end
|
13
20
|
|
21
|
+
def cp(filePath, destPath)
|
22
|
+
write destPath, File.read(filePath)
|
23
|
+
end
|
24
|
+
|
25
|
+
def write(filePath, contents)
|
26
|
+
path = "ecosystems/#{ENV['ECOSYSTEM']}/instances/#{ENV['HOSTNAME']}/config/#{filePath}"
|
27
|
+
|
28
|
+
begin
|
29
|
+
folder = "_working"
|
30
|
+
|
31
|
+
if File.exists? folder
|
32
|
+
g = Git.init(folder)
|
33
|
+
else
|
34
|
+
g = Git.clone(ENV['ECOSYSTEM_CONFIG_GIT'], folder, :path => '.')
|
35
|
+
end
|
36
|
+
FileUtils.mkdir_p File.dirname("#{folder}/#{path}")
|
37
|
+
|
38
|
+
open("#{folder}/#{path}", 'w') { |f|
|
39
|
+
f.puts contents
|
40
|
+
}
|
41
|
+
|
42
|
+
# do the actual copy to the real destination
|
43
|
+
FileUtils.copy_file "#{folder}/#{path}", filePath
|
44
|
+
|
45
|
+
g.add("#{path}")
|
46
|
+
|
47
|
+
rescue => exception
|
48
|
+
@log.error("PushConfig Failed")
|
49
|
+
@log.error(exception.to_s)
|
50
|
+
@log.error(exception.backtrace)
|
51
|
+
abort()
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def commit(comment)
|
57
|
+
folder = "_working"
|
58
|
+
|
59
|
+
begin
|
60
|
+
count = 0
|
61
|
+
|
62
|
+
|
63
|
+
g = Git.init(folder)
|
64
|
+
|
65
|
+
g.chdir do
|
66
|
+
g.status.changed.each do |file|
|
67
|
+
count = count +1
|
68
|
+
end
|
69
|
+
g.status.added.each do |file|
|
70
|
+
count = count +1
|
71
|
+
end
|
72
|
+
g.status.deleted.each do |file|
|
73
|
+
count = count +1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if count == 0
|
78
|
+
log "No changes"
|
79
|
+
else
|
80
|
+
log "#{count} changes committed."
|
81
|
+
g.commit(comment)
|
82
|
+
|
83
|
+
g.push
|
84
|
+
end
|
85
|
+
|
86
|
+
FileUtils.rm_rf(folder)
|
87
|
+
rescue => exception
|
88
|
+
FileUtils.rm_rf(folder)
|
89
|
+
@log.error("PushConfig Failed")
|
90
|
+
@log.error(exception.to_s)
|
91
|
+
@log.error(exception.backtrace)
|
92
|
+
abort()
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
14
96
|
def do(url, comment, params)
|
15
97
|
begin
|
16
98
|
|
@@ -50,8 +132,9 @@ class PushConfig
|
|
50
132
|
end
|
51
133
|
|
52
134
|
if count == 0
|
53
|
-
|
135
|
+
log "No changes"
|
54
136
|
else
|
137
|
+
log "#{count} changes committed."
|
55
138
|
g.commit(comment)
|
56
139
|
|
57
140
|
g.push
|