kpm 0.4.1 → 0.4.2

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: 472c2af6b9f4d6d74d5d82c9b8247ba5b8679b87
4
- data.tar.gz: c12d9370dc6a0929d2f74e9a9af3f4391e560694
3
+ metadata.gz: d38b77f40a5cdb50c139255664892b3f463a44bf
4
+ data.tar.gz: 41019b6c0119626701a6a89823237585d7588bf6
5
5
  SHA512:
6
- metadata.gz: 8fad17400301e6923130654b8aae6384c6e99ca197a3290a4de62e9970f1298d6fc8e4cd17da3adf8dcb94003b0e0c15e4ea85cd6b3e59fff4a090c0d97b4d4f
7
- data.tar.gz: ed8e4ecb4c036aa9cef65cd37ffb87b18f483632d7161340bb35d2c2aa3b1804b3003dbfc471c04075b8d88341defbc45859aa31ba2cfeb593e3abf48fca0066
6
+ metadata.gz: b0457be8ee32667355291e3b936ec9aeeaba943480a6006a5fe12f7cf7175d6445ca3663b8a4435b8cbabf0b9205f8ce8949f4dd5d535f8b64254e5cae04b4f4
7
+ data.tar.gz: 0a14351c90df0618a2013a1a12b43001b4e483228a5af3e7f8fb098028b30914081e13077c9db4c5e497ca0bd4d6e7b3a83b04759fd2b140d23882c188ea93b1
data/lib/kpm.rb CHANGED
@@ -17,6 +17,7 @@ module KPM
17
17
  autoload :Cli, 'kpm/cli'
18
18
  autoload :PluginsDirectory, 'kpm/plugins_directory'
19
19
  autoload :Migrations, 'kpm/migrations'
20
+ autoload :System, 'kpm/system'
20
21
 
21
22
  class << self
22
23
  def root
@@ -62,24 +62,27 @@ module KPM
62
62
  end
63
63
 
64
64
 
65
- def format(all_plugins)
66
- if all_plugins.size == 0
65
+ def format(data, labels = nil)
66
+ if data.nil? || data.size == 0
67
67
  return
68
68
  end
69
69
 
70
- # What we want to output
71
- labels = [{:label => :plugin_name},
72
- {:label => :plugin_key},
73
- {:label => :type},
74
- {:label => :group_id},
75
- {:label => :artifact_id},
76
- {:label => :packaging},
77
- {:label => :versions, :formatter => VersionFormatter.name}]
70
+ if labels.nil?
71
+
72
+ # What we want to output
73
+ labels = [{:label => :plugin_name},
74
+ {:label => :plugin_key},
75
+ {:label => :type},
76
+ {:label => :group_id},
77
+ {:label => :artifact_id},
78
+ {:label => :packaging},
79
+ {:label => :versions, :formatter => VersionFormatter.name}]
80
+ end
78
81
 
79
82
  # Compute label to print along with max size for each label
80
83
  labels_format_argument = []
81
- all_plugins.keys.each do |key|
82
- v = all_plugins[key]
84
+ data.keys.each do |key|
85
+ v = data[key]
83
86
  labels.each do |e|
84
87
  # sanitize entry at the same time
85
88
  v[e[:label]] = v[e[:label]] || "???"
@@ -106,8 +109,8 @@ module KPM
106
109
  puts "#{format}\n" % labels_format_argument
107
110
  puts "#{border}\n"
108
111
 
109
- all_plugins.keys.each do |key|
110
- v = all_plugins[key]
112
+ data.keys.each do |key|
113
+ v = data[key]
111
114
 
112
115
  arguments = []
113
116
  labels.inject(arguments) do |res, e|
@@ -157,7 +157,7 @@
157
157
  :versions:
158
158
  :0.16: 0.0.1
159
159
  :0.17: 0.1.0
160
- :0.18: 0.2.0
160
+ :0.18: 0.2.1
161
161
  :paypal:
162
162
  :type: :ruby
163
163
  :artifact_id: paypal-express-plugin
@@ -165,7 +165,7 @@
165
165
  :0.14: 2.0.0
166
166
  :0.15: 3.0.0
167
167
  :0.16: 4.1.7
168
- :0.18: 5.0.1
168
+ :0.18: 5.0.3
169
169
  :require:
170
170
  - :signature
171
171
  - :login
@@ -0,0 +1,344 @@
1
+ require 'yaml'
2
+
3
+ module KPM
4
+
5
+ module OS
6
+ def OS.windows?
7
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RbConfig::CONFIG["host_os"]) != nil
8
+ end
9
+
10
+ def OS.mac?
11
+ (/darwin/ =~ RbConfig::CONFIG["host_os"]) != nil
12
+ end
13
+
14
+ def OS.unix?
15
+ !OS.windows?
16
+ end
17
+
18
+ def OS.linux?
19
+ OS.unix? and not OS.mac?
20
+ end
21
+ end
22
+
23
+ class System
24
+
25
+ MAX_VALUE_COLUMN_WIDTH = 60
26
+ DEFAULT_BUNDLE_DIR = Dir['/var' + File::SEPARATOR + 'lib' + File::SEPARATOR + 'killbill' + File::SEPARATOR + 'bundles'][0] || Dir['/var' + File::SEPARATOR + 'tmp' + File::SEPARATOR + 'bundles'][0]
27
+ DEFAULT_KAUI_SEARCH_BASE_DIR = '**' + File::SEPARATOR + 'kaui'
28
+ DEFAULT_KILLBILL_SEARCH_BASE_DIR = '**' + File::SEPARATOR + 'ROOT'
29
+
30
+ def initialize
31
+ @formatter = KPM::Formatter.new
32
+ end
33
+
34
+ def information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil)
35
+ puts 'Retrieving system information'
36
+ set_config(config_file)
37
+ killbill_information = show_killbill_information(kaui_web_path,killbill_web_path,output_as_json)
38
+
39
+ java_version = `java -version 2>&1`.split("\n")[0].split('"')[1]
40
+
41
+ environment_information = show_environment_information(java_version, output_as_json)
42
+ os_information = show_os_information(output_as_json)
43
+
44
+ if not java_version.nil?
45
+ command = get_command
46
+ java_system_information = show_java_system_information(command,output_as_json)
47
+ end
48
+
49
+ plugin_information = show_plugin_information(get_plugin_path || bundles_dir || DEFAULT_BUNDLE_DIR, output_as_json)
50
+
51
+ if output_as_json
52
+ json_data = Hash.new
53
+ json_data[:killbill_information] = killbill_information
54
+ json_data[:environment_information] = environment_information
55
+ json_data[:os_information] = os_information
56
+ json_data[:java_system_information] = java_system_information
57
+ json_data[:plugin_information] = plugin_information
58
+
59
+ puts json_data.to_json
60
+ end
61
+ end
62
+
63
+ def show_killbill_information(kaui_web_path, killbill_web_path, output_as_json)
64
+
65
+ kpm_version = KPM::VERSION
66
+ kaui_version = get_kaui_version(get_kaui_web_path || kaui_web_path)
67
+ killbill_version = get_killbill_version(get_killbill_web_path || killbill_web_path)
68
+
69
+ environment = Hash[:kpm => {:system=>'KPM',:version => kpm_version},
70
+ :kaui => {:system=>'Kaui',:version => kaui_version.nil? ? 'not found' : kaui_version},
71
+ :killbill => {:system=>'Killbill',:version => killbill_version.nil? ? 'not found' : killbill_version}]
72
+
73
+ labels = [{:label => :system},
74
+ {:label => :version}]
75
+
76
+ if not output_as_json
77
+ @formatter.format(environment,labels)
78
+ end
79
+
80
+ environment
81
+ end
82
+
83
+ def show_environment_information(java_version, output_as_json)
84
+
85
+ environment = Hash[:ruby => {:environment=>'Ruby',:version => RUBY_VERSION},
86
+ :java => {:environment=>'Java',:version => java_version.nil? ? 'no version found' : java_version}]
87
+
88
+ labels = [{:label => :environment},
89
+ {:label => :version}]
90
+
91
+ if not output_as_json
92
+ @formatter.format(environment,labels)
93
+ end
94
+
95
+ environment
96
+ end
97
+
98
+ def show_os_information(output_as_json)
99
+ os = Hash.new
100
+ os_data = nil
101
+
102
+ if OS.windows?
103
+ os_data = `systeminfo | findstr /C:"OS"`
104
+
105
+ elsif OS.linux?
106
+ os_data = `lsb_release -a 2>&1`
107
+
108
+ elsif OS.mac?
109
+ os_data = `sw_vers`
110
+
111
+ end
112
+
113
+ if os_data != nil
114
+ os_data.split("\n").each do |info|
115
+
116
+ infos = info.split(':')
117
+ os[infos[0]] = {:os_detail => infos[0], :value => infos[1].to_s.strip}
118
+
119
+ end
120
+ end
121
+
122
+ labels = [{:label => :os_detail},
123
+ {:label => :value}]
124
+
125
+ if not output_as_json
126
+ @formatter.format(os,labels)
127
+ end
128
+
129
+ os
130
+ end
131
+
132
+ def show_java_system_information(command, output_as_json)
133
+ java_system = Hash.new
134
+ property_count = 0;
135
+ last_key = ''
136
+
137
+ `#{command}`.split("\n").each do |prop|
138
+
139
+ if prop.to_s.strip.empty?
140
+ break;
141
+ end
142
+
143
+ if property_count > 0
144
+ props = prop.split('=')
145
+
146
+ if (not props[1].nil? && props[1].to_s.strip.size > MAX_VALUE_COLUMN_WIDTH) && output_as_json == false
147
+
148
+ chunks = ".{1,#{MAX_VALUE_COLUMN_WIDTH}}"
149
+ props[1].to_s.scan(/#{chunks}/).each_with_index do |p, index|
150
+
151
+ java_system[property_count] = {:java_property => index.equal?(0) ? props[0] : '', :value => p}
152
+ property_count += 1
153
+
154
+ end
155
+ elsif output_as_json
156
+ key = (props[1].nil? ? last_key : props[0]).to_s.strip
157
+ value = props[1].nil? ? props[0] : props[1]
158
+
159
+ if java_system.has_key?(key)
160
+ java_system[key][:value] = java_system[key][:value].to_s.concat(' ').concat(value)
161
+ else
162
+ java_system[key] = {:java_property => key, :value => value}
163
+ end
164
+
165
+ else
166
+
167
+ java_system[property_count] = {:java_property => props[1].nil? ? '' : props[0], :value => props[1].nil? ? props[0] : props[1]}
168
+
169
+ end
170
+
171
+ last_key = props[1].nil? ? last_key : props[0]
172
+ end
173
+
174
+ property_count += 1
175
+
176
+ end
177
+ labels = [{:label => :java_property},
178
+ {:label => :value}]
179
+
180
+
181
+ if not output_as_json
182
+ @formatter.format(java_system,labels)
183
+ end
184
+
185
+ java_system
186
+
187
+ end
188
+
189
+ def show_plugin_information(bundles_dir, output_as_json)
190
+
191
+ if bundles_dir.nil?
192
+ all_plugins = nil
193
+ else
194
+ inspector = KPM::Inspector.new
195
+ all_plugins = inspector.inspect(bundles_dir)
196
+ end
197
+
198
+ if not output_as_json
199
+ if all_plugins.nil? || all_plugins.size == 0
200
+ puts "\e[91;1mNo KB plugin information available\e[0m\n\n"
201
+ else
202
+ @formatter.format(all_plugins)
203
+ end
204
+ end
205
+
206
+ if output_as_json && (all_plugins.nil? || all_plugins.size == 0)
207
+ all_plugins = 'No KB plugin information available'
208
+ end
209
+ all_plugins
210
+ end
211
+
212
+ def get_kaui_version(kaui_web_path = nil)
213
+ puts kaui_web_path
214
+ kaui_search_default_dir = Dir[kaui_web_path.nil? ? '' : kaui_web_path][0] || DEFAULT_KAUI_SEARCH_BASE_DIR
215
+ version = nil
216
+
217
+ gemfile = Dir[kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'Gemfile']
218
+
219
+ if not gemfile[0].nil?
220
+ absolute_gemfile_path = File.absolute_path(gemfile[0])
221
+
222
+ version = open(absolute_gemfile_path) do |f|
223
+ f.each_line.detect do |line|
224
+ if /kaui/.match(line)
225
+ version = /(\d+)\.(\d+)\.(\d+)/.match(line)
226
+
227
+ if not version.nil?
228
+ break;
229
+ end
230
+ end
231
+ end
232
+ version
233
+ end
234
+
235
+ end
236
+
237
+ version
238
+ end
239
+
240
+ def get_killbill_version(killbill_web_path = nil)
241
+ killbill_search_default_dir = Dir[killbill_web_path.nil? ? '' : killbill_web_path][0] || DEFAULT_KILLBILL_SEARCH_BASE_DIR
242
+
243
+ file = Dir[killbill_search_default_dir + File::SEPARATOR + 'META-INF' + File::SEPARATOR + '**' + File::SEPARATOR + 'pom.properties']
244
+ version = nil
245
+ if not file[0].nil?
246
+ absolute_file_path = File.absolute_path(file[0])
247
+
248
+ version = open(absolute_file_path) do |f|
249
+ f.each_line.detect do |line|
250
+ version = /(\d+)\.(\d+)\.(\d+)/.match(line)
251
+
252
+ if not version.nil?
253
+ break;
254
+ end
255
+ end
256
+ version
257
+ end
258
+
259
+ end
260
+
261
+ version
262
+ end
263
+
264
+ def get_command
265
+ command = 'java -XshowSettings:properties -version 2>&1'
266
+ apache_tomcat_pid = get_apache_tomcat_pid
267
+
268
+ if not apache_tomcat_pid.nil?
269
+ command = "jcmd #{apache_tomcat_pid} VM.system_properties"
270
+ end
271
+
272
+ command
273
+ end
274
+
275
+ def get_apache_tomcat_pid
276
+ apache_tomcat_pid = nil;
277
+ `jcmd -l 2>&1`.split("\n").each do |line|
278
+
279
+ if /org.apache.catalina/.match(line)
280
+ words = line.split(' ')
281
+ apache_tomcat_pid = words[0]
282
+ end
283
+
284
+ end
285
+
286
+ apache_tomcat_pid
287
+ end
288
+
289
+ def set_config(config_file = nil)
290
+ @config = nil
291
+
292
+ if not config_file.nil?
293
+ if not Dir[config_file][0].nil?
294
+ @config = YAML::load_file(config_file)
295
+ end
296
+ end
297
+
298
+ end
299
+
300
+ def get_kaui_web_path
301
+ kaui_web_path = nil;
302
+
303
+ if not @config.nil?
304
+ config_kaui = @config['kaui']
305
+
306
+ if not config_kaui.nil?
307
+ kaui_web_path = Dir[config_kaui['webapp_path']][0]
308
+ end
309
+ end
310
+
311
+ kaui_web_path
312
+ end
313
+
314
+ def get_killbill_web_path
315
+ killbill_web_path = nil;
316
+
317
+ if not @config.nil?
318
+ config_killbill = @config['killbill']
319
+
320
+ if not config_killbill.nil?
321
+ killbill_web_path = Dir[config_killbill['webapp_path']][0]
322
+ end
323
+ end
324
+
325
+ killbill_web_path
326
+ end
327
+
328
+ def get_plugin_path
329
+ plugin_path = nil;
330
+
331
+ if not @config.nil?
332
+ config_killbill = @config['killbill']
333
+
334
+ if not config_killbill.nil?
335
+ plugin_path = Dir[config_killbill['plugins_dir']][0]
336
+ end
337
+ end
338
+
339
+ plugin_path
340
+ end
341
+
342
+ end
343
+
344
+ end
@@ -399,11 +399,39 @@ module KPM
399
399
  desc 'inspect', 'Inspect current deployment'
400
400
  def inspect
401
401
  inspector = KPM::Inspector.new
402
+ puts options[:destination]
402
403
  all_plugins = inspector.inspect(options[:destination])
403
404
  #puts all_plugins.to_json
404
405
  inspector.format(all_plugins)
405
406
  end
406
407
 
408
+ method_option :bundles_dir,
409
+ :type => :string,
410
+ :default => nil,
411
+ :desc => 'A different folder other than the default bundles directory.'
412
+ method_option :config_file,
413
+ :type => :string,
414
+ :default => nil,
415
+ :desc => 'KPM configuration file (yml file)'
416
+ method_option :as_json,
417
+ :type => :boolean,
418
+ :default => false,
419
+ :desc => 'Set the output format as JSON when true'
420
+ method_option :kaui_web_path,
421
+ :type => :string,
422
+ :default => nil,
423
+ :desc => 'Path for the KAUI web app'
424
+ method_option :killbill_web_path,
425
+ :type => :string,
426
+ :default => nil,
427
+ :desc => 'Path for the killbill web app'
428
+ desc 'system', 'Gather information about the system'
429
+ def system
430
+ system = KPM::System.new
431
+ system.information(options[:bundles_dir], options[:as_json], options[:config_file], options[:kaui_web_path],
432
+ options[:killbill_web_path])
433
+ end
434
+
407
435
  map :pull_ruby_plugin => :install_ruby_plugin,
408
436
  :pull_java_plugin => :install_java_plugin
409
437
 
@@ -1,3 +1,3 @@
1
1
  module KPM
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +131,7 @@ files:
131
131
  - lib/kpm/plugins_directory.yml
132
132
  - lib/kpm/plugins_manager.rb
133
133
  - lib/kpm/sha1_checker.rb
134
+ - lib/kpm/system.rb
134
135
  - lib/kpm/tasks.rb
135
136
  - lib/kpm/tomcat_manager.rb
136
137
  - lib/kpm/uninstaller.rb