devinstall 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddb84669dfb3c1db3216c80b3412a4e176c94e52
4
- data.tar.gz: 0bb1e0dfc0ff1f3ee55d2e39a387574d31f9e9ff
3
+ metadata.gz: 51f4ddcf8ee4cb1806c0ee407aa1c6e582c7088c
4
+ data.tar.gz: 7317bd32282391c568339f534e23bd485bbf02b4
5
5
  SHA512:
6
- metadata.gz: a5b8578a2533246bf0da8caccbab886833b22f4b930bc0031e63653308a279239f456ab428726f9852c53035fe6c353cc436eda9b54e17adca795caf874f49f7
7
- data.tar.gz: 6152d2324a9fbe68d01adf94e297997df271d6f9d282dfdfae59a0a968f8d1ab7c00acda918b40be8f941a06b6b64888f59a23f3e5d58e031905d0a2d1efd588
6
+ metadata.gz: 8ac955e8f47abcfcf93f2ad3351ef78125d8d7e68b898ff4ff5812473fcf2fd3c159a35d4e576d04336b54630c52166b92efe7904fc9855f3884869753756b06
7
+ data.tar.gz: ae05a8d213cf8570eeb9c7a4016de3dbe31f39da88e1db182d6a187b339e81c8cb4699577983ea3c77348adef9944a35ef5a2d8018764c0a5861a3b7b7182b06
data/bin/pkg-tool CHANGED
@@ -1,69 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'getopt/long'
4
- require 'devinstall'
5
- require 'devinstall/settings'
3
+ require 'devinstall/cli'
6
4
 
7
- begin
8
- opt =Getopt::Long.getopts(
9
- ['--version', '-v',],
10
- ['--package', '-p', Getopt::REQUIRED],
11
- ['--config', '-c', Getopt::REQUIRED],
12
- ['--type', '-t', Getopt::REQUIRED],
13
- ['--env', '-e', Getopt::REQUIRED],
14
- ['--build', '-b',],
15
- ['--upload', '-u',],
16
- ['--install', '-i',],
17
- ['--test', '-t,'],
18
- ['--help', '-h',],
19
- )
20
- rescue
21
- puts 'Invalid option in command line'
22
- help!
23
- exit! 1
24
- end
25
-
26
- def help!
27
- puts 'Usage: pkg-install --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment> --build|--upload|--install'
28
- end
29
-
30
- if opt['version']
31
- puts "devinstall version #{Devinstall::VERSION}"
32
- puts "pkg-tool version #{Devinstall::VERSION}"
33
- exit(0)
34
- end
35
-
36
- if opt['help']
37
- help!
38
- exit!(0)
39
- end
40
- unless opt['config']
41
- puts 'You must specify the config file'
42
- exit! 1 # Exit
43
- end
44
- Settings.load! opt['config']
45
-
46
- ['package', 'env', 'type'].each do |o|
47
- if Settings.defaults[o.to_sym]
48
- opt[o]=Settings.defaults[o.to_sym]
49
- end
50
- end
51
-
52
- unless opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install'] || opt['test'])
53
- puts 'You must speciffy --config file, --package, --type and --env and one of the actions (--build, --install, --upload or --test)'
54
- exit! 1
55
- end
56
- package=Devinstall::Pkg.new(opt['package'])
5
+ command = ARGV.shift
57
6
 
58
- if opt['build']
59
- package.build(opt['type'].to_sym)
60
- elsif opt['install']
61
- package.build(opt['type'].to_sym)
62
- package.install(opt['env'].to_sym)
63
- elsif opt['upload']
64
- package.build(opt['type'].to_sym)
65
- package.run_tests(opt['env'].to_sym)
66
- package.upload(opt['env'].to_sym)
67
- elsif opt['test']
68
- package.run_tests(opt['env'].to_sym)
7
+ unless %w"build install upload help version test".include? command
8
+ puts "Unknown command #{command}"
9
+ exit 1
69
10
  end
11
+ cli=Cli.new
12
+ cli.send(command.to_sym)
@@ -0,0 +1,83 @@
1
+ require 'devinstall'
2
+ require 'getopt/long'
3
+ require 'devinstall/settings'
4
+ module Devinstall
5
+ class Cli
6
+ # extend self
7
+ # make this module a singleton also
8
+ # See why
9
+
10
+ def get_config(fnames)
11
+ fnames.each do |f|
12
+ (@opt['config'] ||= (File.expand_path(f) if File.exist? f)) and break
13
+ end
14
+ @opt['config']
15
+ end
16
+
17
+ def initialize
18
+ begin
19
+ @opt = Getopt::Long.getopts(
20
+ ['--package', '-p', Getopt::REQUIRED],
21
+ ['--config', '-c', Getopt::REQUIRED],
22
+ ['--type', '-t', Getopt::REQUIRED],
23
+ ['--env', '-e', Getopt::REQUIRED],
24
+ )
25
+ rescue
26
+ puts 'Invalid option in command line'
27
+ help
28
+ exit! 1
29
+ end
30
+ # get config file
31
+ unless get_config(["./devinstall.yml"])
32
+ puts 'You must specify the config file'
33
+ exit! 1 # Exit
34
+ end
35
+ # parse config file
36
+ Settings.load!(@opt['config'])
37
+ # complete from default values
38
+ %w"package env type".each { |o| @opt[o] ||= Settings.defaults[o.to_sym] if Settings.defaults[o.to_sym] }
39
+ # verify all informations
40
+ %w"package type env".each do |k|
41
+ unless @opt[k]
42
+ puts "You must specify option '#{k}' either as default or in command line"
43
+ help
44
+ end
45
+ end
46
+ # create package
47
+ @package=Devinstall::Pkg.new(@opt['package'])
48
+ end
49
+
50
+ def version
51
+ puts "devinstall version #{Devinstall::VERSION}"
52
+ puts "pkg-tool version #{Devinstall::VERSION}"
53
+ exit(0)
54
+ end
55
+
56
+ def help
57
+ puts 'Usage:'
58
+ puts 'pkg-install command --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment>'
59
+ puts 'where command is one of the: build, install, upload, help, version'
60
+ exit! 0
61
+ end
62
+
63
+ def build
64
+ @package.build(@opt['type'].to_sym)
65
+ end
66
+
67
+ def install
68
+ package.build(@opt['type'].to_sym)
69
+ package.install(@opt['env'].to_sym)
70
+ end
71
+
72
+ def upload
73
+ package.build(@opt['type'].to_sym)
74
+ package.run_tests(@opt['env'].to_sym)
75
+ package.upload(@opt['env'].to_sym)
76
+ end
77
+
78
+ def test
79
+ package.run_tests(@opt['env'].to_sym)
80
+ end
81
+
82
+ end
83
+ end
@@ -1,17 +1,3 @@
1
- # Symbolizes all of hash's keys and subkeys.
2
- # Also allows for custom pre-processing of keys (e.g. downcasing, etc)
3
- # if the block is given:
4
- #
5
- # somehash.deep_symbolize { |key| key.downcase }
6
- #
7
- # Usage: either include it into global Hash class to make it available to
8
- # to all hashes, or extend only your own hash objects with this
9
- # module.
10
- # E.g.:
11
- # 1) class Hash; include DeepSymbolizable; end
12
- # 2) myhash.extend DeepSymbolizable
13
-
14
-
15
1
  module DeepSymbolizable
16
2
 
17
3
  def deep_symbolize(&block)
@@ -23,35 +9,22 @@ module DeepSymbolizable
23
9
  module Symbolizers
24
10
  extend self
25
11
 
26
- # the primary method - symbolizes keys of the given hash,
27
- # preprocessing them with a block if one was given, and recursively
28
- # going into all nested enumerables
29
12
  def hash(hash, &block)
30
13
  hash.inject({}) do |result, (key, value)|
31
- # Recursively deep-symbolize subhashes
32
14
  value = _recurse_(value, &block)
33
-
34
- # Pre-process the key with a block if it was given
35
15
  key = yield key if block_given?
36
- # Symbolize the key string if it responds to to_sym
37
16
  sym_key = key.to_sym rescue key
38
-
39
- # write it back into the result and return the updated hash
40
17
  result[sym_key] = value
41
18
  result
42
19
  end
43
20
  end
44
21
 
45
- # walking over arrays and symbolizing all nested elements
46
22
  def array(ary, &block)
47
23
  ary.map { |v| _recurse_(v, &block) }
48
24
  end
49
25
 
50
- # handling recursion - any Enumerable elements (except String)
51
- # is being extended with the module, and then symbolized
52
26
  def _recurse_(value, &block)
53
27
  if value.is_a?(Enumerable) && !value.is_a?(String)
54
- # support for a use case without extended core Hash
55
28
  value.extend DeepSymbolizable unless value.class.include?(DeepSymbolizable)
56
29
  value = value.deep_symbolize(&block)
57
30
  end
@@ -23,8 +23,9 @@ module Settings
23
23
  end
24
24
 
25
25
  def deep_merge!(target, data)
26
- merger = proc { |_, v1, v2|
27
- Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
26
+ merger = proc do |_, v1, v2|
27
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
28
+ end
28
29
  target.merge! data, &merger
29
30
  end
30
31
 
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = "0.2.2" # first test
2
+ VERSION = '0.2.3' # first test
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -13,35 +13,41 @@ module Devinstall
13
13
  # @param [Symbol] type
14
14
  def get_version(type)
15
15
  if type == :deb
16
- deb_changelog = File.expand_path "#{Settings.local[:folder]}/#{@package}/debian/changelog" # This is the folder that should be checked
17
- deb_package_version =File.open(deb_changelog, 'r').gets.chomp.sub(/^.*\((.*)\).*$/, '\1')
18
- @_package_version[:deb]=deb_package_version
16
+ begin
17
+ deb_changelog = File.expand_path "#{Settings.local[:folder]}/#{@package}/debian/changelog" # This is the folder that should be checked
18
+ deb_package_version = File.open(deb_changelog, 'r') { |f| f.gets.chomp.sub(/^.*\((.*)\).*$/, '\1') }
19
+ @_package_version[:deb] = deb_package_version
20
+
21
+ rescue IOError => e
22
+ puts "IO Error while opening #{deb_changelog}"
23
+ puts "Aborting \n #{e}"
24
+ exit! 1
25
+ end
19
26
  end
20
27
  end
21
28
 
22
29
  # @param [String] package
23
30
  def initialize (package)
24
31
  # curently implemented only for .deb packages (for .rpm later :D)
25
- @package =package.to_sym
26
- @_package_version =Hash.new # versions for types:
27
- @package_files =Hash.new
28
- arch =Settings.build[:arch]
29
- pname ="#{package}_#{get_version :deb}"
30
- @package_files[:deb] ={deb: "#{pname}_#{arch}.deb",
31
- tgz: "#{pname}.tar.gz",
32
- dsc: "#{pname}.dsc",
33
- chg: "#{pname}_amd64.changes"}
32
+ @package = package.to_sym
33
+ @_package_version = Hash.new # versions for types:
34
+ @package_files = Hash.new
35
+ arch = Settings.build[:arch]
36
+ pname = "#{package}_#{get_version :deb}"
37
+ @package_files[:deb] = {deb: "#{pname}_#{arch}.deb",
38
+ tgz: "#{pname}.tar.gz",
39
+ dsc: "#{pname}.dsc",
40
+ chg: "#{pname}_amd64.changes"}
34
41
  end
35
42
 
36
- def upload (environment)
37
- scp =Settings.base[:scp]
38
- repo =Hash.new
39
- type =Settings.repos[:environments][environment][:type]
43
+ def upload (env)
44
+ scp = Settings.base[:scp]
45
+ repo = {}
46
+ type = Settings.repos[:environments][env][:type]
40
47
  [:user, :host, :folder].each do |k|
41
- fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[:environments][environment].has_key?(k)
42
- repo[k]=Settings.repos[:environments][environment][k]
48
+ fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[:environments][env].has_key?(k)
49
+ repo[k] = Settings.repos[:environments][env][k]
43
50
  end
44
- build(type)
45
51
  @package_files[type].each do |p|
46
52
  system("#{scp} #{Settings.local[:temp]}/#{p} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
47
53
  end
@@ -50,25 +56,25 @@ module Devinstall
50
56
  # @param [Symbol] type
51
57
  def build (type)
52
58
  puts "Building package #{@package} type #{type.to_s}"
53
- unless Settings.packages[@package].has_key?(type)
54
- puts("Package '#{@package}' cannot be built for the required environment")
55
- puts("undefined build configuration for '#{type.to_s}'")
56
- exit!(1)
59
+ unless Settings.packages[@package].has_key? type
60
+ puts "Package '#{@package}' cannot be built for the required environment"
61
+ puts "undefined build configuration for '#{type.to_s}'"
62
+ exit! 1
57
63
  end
58
- build =Hash.new
64
+ build = {}
59
65
  [:user, :host, :folder, :target].each do |k|
60
- unless Settings.build.has_key?(k)
61
- puts("Undefined key 'build:#{k.to_s}:'")
62
- exit!(1)
66
+ unless Settings.build.has_key? k
67
+ puts "Undefined key 'build:#{k.to_s}:'"
68
+ exit! 1
63
69
  end
64
- build[k]=Settings.build[k]
70
+ build[k] = Settings.build[k]
65
71
  end
66
72
 
67
- ssh =Settings.base[:ssh]
68
- build_command=Settings.packages[@package][type][:build_command]
69
- rsync =Settings.base[:rsync]
70
- local_folder =File.expand_path Settings.local[:folder]
71
- local_temp =File.expand_path Settings.local[:temp]
73
+ ssh = Settings.base[:ssh]
74
+ build_command = Settings.packages[@package][type][:build_command]
75
+ rsync = Settings.base[:rsync]
76
+ local_folder = File.expand_path Settings.local[:folder]
77
+ local_temp = File.expand_path Settings.local[:temp]
72
78
 
73
79
  build_command = build_command.gsub('%f', build[:folder]).
74
80
  gsub('%t', Settings.build[:target]).
@@ -76,41 +82,51 @@ module Devinstall
76
82
  gsub('%T', type.to_s)
77
83
 
78
84
  upload_sources("#{local_folder}/", "#{build[:user]}@#{build[:host]}:#{build[:folder]}")
79
- system("#{ssh} #{build[:user]}@#{build[:host]} \"#{build_command}\"")
85
+ res = system("#{ssh} #{build[:user]}@#{build[:host]} \"#{build_command}\"")
86
+ unless res
87
+ puts 'Build error'
88
+ puts 'Aborting!'
89
+ exit! 1
90
+ end
80
91
  @package_files[type].each do |p, t|
81
92
  puts "Receiving target #{p.to_s} for #{t.to_s}"
82
- system("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
93
+ res = system("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
94
+ unless res
95
+ puts 'File downloading error'
96
+ puts 'Aborting!'
97
+ exit! 1
98
+ end
83
99
  end
84
100
  end
85
101
 
86
- def run_tests(environment)
102
+ def run_tests(env)
87
103
  # for tests we will use aprox the same setup as for build
88
- test =Hash.new
104
+ test = {}
89
105
  [:user, :machine, :command, :folder].each do |k|
90
- unless Settings.tests[environment].has_key?(k)
106
+ unless Settings.tests[env].has_key? k
91
107
  puts("Undefined key 'tests:#{environment}:#{k.to_s}:'")
92
- exit!(1)
108
+ exit! 1
93
109
  end
94
- test[k]=Settings.tests[environment][k]
110
+ test[k] = Settings.tests[env][k]
95
111
  end
96
- ssh =Settings.base[:ssh]
112
+ ssh = Settings.base[:ssh]
97
113
 
98
114
  test[:command] = test[:command].gsub('%f', test[:folder]).
99
115
  gsub('%t', Settings.build[:target]).
100
116
  gsub('%p', @package.to_s)
101
117
 
102
- local_folder =File.expand_path Settings.local[:folder] #take the sources from the local folder
118
+ local_folder = File.expand_path Settings.local[:folder] #take the sources from the local folder
103
119
 
104
120
  upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}") # upload them to the test machine
105
121
 
106
122
  puts "Running all tests for the #{environment} environment"
107
123
  puts "This will take some time"
108
- ret=system("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
124
+ ret = system("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
109
125
  if ret
110
126
  puts "Errors during test. Aborting current procedure"
111
127
  exit! 1
112
128
  end
113
- rescue Exception => ee
129
+ rescue => ee
114
130
  puts "Unknown exception during parsing config file"
115
131
  puts "Aborting (#{ee})"
116
132
  exit! 1
@@ -118,17 +134,17 @@ module Devinstall
118
134
 
119
135
  def install (environment)
120
136
  puts "Installing #{@package} in #{environment} environment."
121
- sudo =Settings.base[:sudo]
122
- scp =Settings.base[:scp]
123
- type=Settings.install[:environments][environment][:type].to_sym
124
- local_temp =Settings.local[:temp]
125
- install=Hash.new
137
+ local_temp = Settings.local[:temp]
138
+ sudo = Settings.base[:sudo]
139
+ scp = Settings.base[:scp]
140
+ type = Settings.install[:environments][environment][:type].to_sym
141
+ install = {}
126
142
  [:user, :host, :folder].each do |k|
127
- unless Settings.install[:environments][environment].has_key?(k)
143
+ unless Settings.install[:environments][environment].has_key? k
128
144
  puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
129
145
  exit! 1
130
146
  end
131
- install[k]=Settings.install[:environments][environment][k]
147
+ install[k] = Settings.install[:environments][environment][k]
132
148
  end
133
149
  case type
134
150
  when :deb
@@ -141,8 +157,14 @@ module Devinstall
141
157
  end
142
158
 
143
159
  def upload_sources (source, dest)
144
- rsync =Settings.base[:rsync]
145
- system("#{rsync} -az #{source} #{dest}")
160
+ rsync = Settings.base[:rsync]
161
+ res = system("#{rsync} -az #{source} #{dest}")
162
+ unless res
163
+ puts "Rsync error"
164
+ puts "Aborting!"
165
+ exit! 1
166
+ end
167
+ res
146
168
  end
147
169
  end
148
170
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devinstall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dragos Boca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-17 00:00:00.000000000 Z
11
+ date: 2013-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - devinstall.gemspec
81
81
  - doc/example.yml
82
82
  - lib/devinstall.rb
83
+ - lib/devinstall/cli.rb
83
84
  - lib/devinstall/deep_symbolize.rb
84
85
  - lib/devinstall/settings.rb
85
86
  - lib/devinstall/version.rb