canzea 0.1.137 → 0.1.138

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ef42df3dd357dcded825cd4344b69d12c3ba3c
4
- data.tar.gz: 316dbd380aa93d64a3e7020ca8763437c5f52f24
3
+ metadata.gz: 56e338100978ef4a62df216bc68d1cbc5cff2d59
4
+ data.tar.gz: 417dc132292f90c6e9b57ee2e2e185f39e9cf5f7
5
5
  SHA512:
6
- metadata.gz: 4ebe898121792821b229ddafe2616ab2fd528e4b07fe708f0af01f287dcb36be5f3a02c1e2b43211494f208a2652fd1ba5cd021141044b309252ae3ac14fdd48
7
- data.tar.gz: cfeeec5b9dc4748108b5005252b37ee3fb735a4385c2f2c14576a4908502426bd91ef97bb8fa74f308dbaed03ab90d9d074c948efb713c6c2c0e2b32e380e460
6
+ metadata.gz: 170a603e1503817f7a68aa7042386c5ce31d43cbb91a36d334a3b628aedf9cc638b824a9b0096c5349b74886df9d81eb1f9444c4e936b6c995e90a861f2ba291
7
+ data.tar.gz: 1b0929680026eba253c80b19a0cde0c5fd811d4d2d2cfed71bc7f3d03a722f0960eefe0089063d1da8b792b1bf7d0c2287283dea2daa363ead8ca758551fd5ac
@@ -1,3 +1,3 @@
1
1
  module Canzea
2
- VERSION = "0.1.137"
2
+ VERSION = "0.1.138"
3
3
  end
@@ -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
- puts "No changes"
135
+ log "No changes"
54
136
  else
137
+ log "#{count} changes committed."
55
138
  g.commit(comment)
56
139
 
57
140
  g.push
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canzea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.137
4
+ version: 0.1.138
5
5
  platform: ruby
6
6
  authors:
7
7
  - Canzea Technologies