devinstall 1.0.0 → 1.0.1

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: a72a20aa430bcf037ca21512a32d6e143087f0f8
4
- data.tar.gz: 5db3417f1ebd025f01da2c84dd9766050b29f9f2
3
+ metadata.gz: 020bb3bf72c1b2c8c0028b4f3325535ac560bd89
4
+ data.tar.gz: dee754076fd8134e9f29ddd04e985495c62ed0ce
5
5
  SHA512:
6
- metadata.gz: 705c0e2eac77b70d570246ea152a64be626a58a8f9762fb2367af6f49ca4bf55b9b23c6fb3c0f5837be82ddb1f8d26b2bc26bc2d7c9534a4427ea9d4dbdedf94
7
- data.tar.gz: 7ff04e301b68ce8ca10615f98d647a150d8977bd95c61a15db0c28a9fa5bc2f3eed0b5ca2face0b84eaca1d090099887ebde781615d7dab25cb6fd7ae14b73fd
6
+ metadata.gz: bc609fc9b54577ebc424b47b106af5892c8af416d27634936302162546e084eb4ac273c3518a88a71f60c579d0c70f3763f158bafdf73aa31fc3442e0dd373ed
7
+ data.tar.gz: df8ca74a6cddefa371bb4c7cc78a619ee0608396b022cd834a43fd55b78de47bc017688c1fb35dab9e269872de683642e9039363a4b1626439492caca7c1d789
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .idea
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/bin/pkg-tool CHANGED
@@ -4,8 +4,8 @@ require 'bundler/setup'
4
4
  require 'devinstall/cli'
5
5
 
6
6
  unless ARGV[0]
7
- puts "You must specify an action"
8
- exit! ""
7
+ puts 'You must specify an action'
8
+ exit! ''
9
9
  end
10
10
 
11
11
  package = [] # creata a new Array
data/devinstall.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'getopt'
24
+ spec.add_development_dependency 'rspec'
24
25
  end
data/doc/example.yml CHANGED
@@ -1,8 +1,15 @@
1
1
  base:
2
2
  rsync: /usr/bin/rsync
3
- ssh: /usr/bin/ssh
4
3
  scp: /usr/bin/scp
5
4
  sudo: sshsudo
5
+ ssh: /usr/bin/ssh
6
+ provider: ## NOT YET Implemented!
7
+ vagrant1:
8
+ init: vagrant up
9
+ destroy: vagrant destroy
10
+ openstack1:
11
+ node: node.dev.local
12
+ arch: debian64
6
13
  defaults:
7
14
  package: devinstall
8
15
  env: dev
@@ -25,6 +32,9 @@ build:
25
32
  # target - the folder where packages will be generated (defaults to folder)
26
33
  # user - for ssh / rsync
27
34
  # arch is the architecture for the generated package (like amd64 or i686)
35
+ # provider can be ssh or local (in the future vagrant and openstack)
36
+ # note: the ssh in provider have nothing to do with ssh command in base
37
+ provider: ssh
28
38
  user: dboca
29
39
  host: vm-dboca.dev.local
30
40
  folder: rs
@@ -35,6 +45,7 @@ install:
35
45
  # user - for scp / ssh / rsync (defaults to base[user])
36
46
  # environment - live/qa/dev/...
37
47
  dev:
48
+ provider: ssh
38
49
  user: dboca
39
50
  host:
40
51
  - server1.lan
@@ -1,77 +1,69 @@
1
1
  require 'devinstall'
2
2
  require 'getopt/long'
3
3
  require 'devinstall/settings'
4
+
4
5
  module Devinstall
5
6
  class Cli
6
7
 
7
8
  include Utils
8
9
 
9
- def get_config(fnames)
10
+ def get_config(*fnames)
11
+ config=nil
10
12
  fnames.each do |f|
11
- (@opt['config'] ||= (File.expand_path(f) if File.exist? f)) and break
13
+ (config ||= (File.expand_path(f) if File.exist? f)) and break
12
14
  end
13
- @opt['config']
15
+ config
14
16
  end
15
17
 
16
18
  def initialize(*package)
17
19
  begin
18
- @opt = Getopt::Long.getopts(
19
- ['--config', '-c', Getopt::REQUIRED],
20
- ['--type', '-t', Getopt::REQUIRED],
21
- ['--env', '-e', Getopt::REQUIRED],
22
- ['--verbose', '-v'],
23
- ['--dry-run', '-d'],
20
+ opt = Getopt::Long.getopts(
21
+ %w(--config -c),
22
+ %w(--type -t),
23
+ %w(--env -e),
24
+ %w(--verbose -v),
25
+ %w(--dry-run -d),
24
26
  )
25
27
  rescue
26
28
  puts 'Invalid option at command line'
27
29
  help
28
30
  end
29
31
  #verbose and dry-run
30
- $verbose ||= @opt['verbose']
31
- $dry ||= @opt['dry-run']
32
+ $verbose ||= opt['verbose']
33
+ $dry ||= opt['dry-run']
32
34
  # get config file
33
- get_config(["./devinstall.yml", "~/.devinstall.yml"])
34
- # add packages
35
- @opt['package']=[] # reset the package array because commandline have priority
36
- if package # a package was supplied on command line
37
- package.each { |p| @opt['package'] << p } # now this overrides everything
38
- end
39
- #get default packages
40
- if @opt['package'].empty?
41
- config = Devinstall::Settings.new(@opt['config'], nil, @opt['env'], @opt['type']) # Just for pkg :D
42
- @opt['package'] = config.pkg # we DO have accessor
43
- end
35
+ config = Devinstall::Settings.instance # is a singleton so we don't use new here
36
+ cfgfile = get_config('./devinstall.yml', '~/.devinstall.yml', opt['config'])
37
+ exit! 'You must specify the config file' if cfgfile.empty?
38
+ config.load! cfgfile # load cfgfile
39
+ config.env = opt['env'] || config.env
40
+ config.type = opt['type'] || config.type
41
+ @packages = package || []
42
+ @packages = config.defaults(:package) if @packages.empty?
43
+ exit! 'You must ask for a package' if @packages.empty?
44
+ config.validate
45
+ rescue KeyNotDefinedError => e
46
+ exit! e.message
44
47
  end
45
48
 
46
49
  def build
47
- if @opt['config'].empty?
48
- exit! 'You must specify the config file'
49
- end
50
- # create package
51
- @opt['package'].each do |package|
52
- pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']))
50
+ @packages.each do |package|
51
+ pk=Devinstall::Pkg.new(package)
53
52
  pk.build
54
53
  end
55
54
  end
56
55
 
57
56
  def install
58
- if @opt['config'].empty?
59
- exit! 'You must specify the config file'
60
- end
61
- @opt['package'].each do |package|
62
- pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']))
57
+ @packages.each do |package|
58
+ pk=Devinstall::Pkg.new(package)
63
59
  pk.build
64
60
  pk.install
65
61
  end
66
62
  end
67
63
 
68
64
  def upload
69
- if @opt['config'].empty?
70
- exit! 'You must specify the config file'
71
- end
72
- @opt['package'].each do |package|
73
- config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])
74
- pk=Devinstall::Pkg.new(config)
65
+ @packages.each do |package|
66
+ pk=Devinstall::Pkg.new(package)
75
67
  pk.build
76
68
  pk.run_tests
77
69
  pk.upload
@@ -79,12 +71,8 @@ module Devinstall
79
71
  end
80
72
 
81
73
  def test
82
- if @opt['config'].empty?
83
- exit! 'You must specify the config file'
84
- end
85
- @opt['package'].each do |package|
86
- config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])
87
- pk=Devinstall::Pkg.new(config)
74
+ @packages.each do |package|
75
+ pk=Devinstall::Pkg.new(package)
88
76
  pk.run_tests
89
77
  end
90
78
  end
@@ -93,13 +81,13 @@ module Devinstall
93
81
  puts 'Usage:'
94
82
  puts 'pkg-tool command [package_name ... ] --config|-c <file> --type|-t <package_type> --env|-e <environment>'
95
83
  puts 'where command is one of the: build, install, upload, help, version'
96
- exit! ""
84
+ exit! ''
97
85
  end
98
86
 
99
87
  def version
100
88
  puts "devinstall version #{Devinstall::VERSION}"
101
89
  puts "pkg-tool version #{Devinstall::VERSION}"
102
- exit! ""
90
+ exit! ''
103
91
  end
104
92
 
105
93
  end
@@ -1,4 +1,7 @@
1
1
  require 'yaml'
2
+ require 'devinstall/deep_symbolize'
3
+ require 'singleton'
4
+ require 'pp'
2
5
 
3
6
  class Hash
4
7
  include DeepSymbolizable
@@ -6,52 +9,67 @@ end
6
9
 
7
10
  module Devinstall
8
11
 
9
- class KeyNotDefinedError < RuntimeError; end
12
+ class KeyNotDefinedError < RuntimeError;
13
+ end
10
14
 
11
- class UnknownKeyError < RuntimeError; end
15
+ class UnknownKeyError < RuntimeError;
16
+ end
12
17
 
13
18
  class Settings
14
- include Utils
15
- attr_accessor :pkg, :env, :type
16
-
17
- def initialize (filename, pkg = nil, env = nil, type = nil)
18
- @@_files ||= []
19
- @@_settings ||= {}
20
- load! filename
21
- self.pkg = pkg ? pkg : defaults(:package)
22
- self.env = env ? env.to_sym : defaults(:env).to_sym
23
- self.type = type ? type.to_sym : defaults(:type).to_sym
19
+ include Singleton
20
+
21
+ attr_accessor :env, :type
22
+ FILES = []
23
+ SETTINGS = {}
24
+
25
+ def pkg=(pkg)
26
+ if Array === pkg and pkg.length == 1
27
+ @pkg = pkg[0]
28
+ elsif pkg.class.method_defined? :to_sym
29
+ @pkg = pkg.to_sym
30
+ else
31
+ @pkg = pkg
32
+ end
33
+ end
34
+
35
+ def pkg
36
+ @pkg
37
+ end
38
+
39
+ def validate
40
+ raise KeyNotDefinedError, 'Missing package' unless self.pkg
41
+ raise KeyNotDefinedError, 'Missing environment' unless self.env
42
+ raise KeyNotDefinedError, 'Missing package type' unless self.type
24
43
  if Array === self.pkg
25
44
  self.pkg.each do |p|
26
- raise KeyNotDefinedError, "Package '#{p}' not defined" unless @@_settings[:packages].has_key? p.to_sym
27
- raise KeyNotDefinedError, "Package #{p} type '#{type}' not defined " unless @@_settings[:packages][p.to_sym].has_key? self.type
45
+ raise KeyNotDefinedError, "Package '#{p}' not defined" unless SETTINGS[:packages].has_key? p.to_sym
46
+ raise KeyNotDefinedError, "Package #{p} type '#{type}' not defined " unless SETTINGS[:packages][p.to_sym].has_key? self.type
28
47
  end
29
48
  else
30
- raise KeyNotDefinedError, "Package '#{p}' not defined" unless @@_settings[:packages].has_key? self.pkg.to_sym
31
- raise KeyNotDefinedError, "Package #{p} type '#{type}' not defined " unless @@_settings[:packages][self.pkg.to_sym].has_key? self.type
49
+ raise KeyNotDefinedError, "Package '#{pkg}' not defined" unless SETTINGS[:packages].has_key? self.pkg.to_sym
50
+ raise KeyNotDefinedError, "Package #{pkg} type '#{type}' not defined " unless SETTINGS[:packages][self.pkg.to_sym].has_key? self.type
32
51
  end
33
- raise KeyNotDefinedError, "Missing package" unless self.pkg
34
- raise KeyNotDefinedError, "Missing environment" unless self.env
35
- raise KeyNotDefinedError, "Missing package type" unless self.type
36
52
  rescue KeyNotDefinedError => e
37
- puts "#{e.message}"
38
- exit! "" #here should be raise
53
+ raise e
39
54
  rescue UnknownKeyError => e
40
55
  puts "Program error: #{e.message} at:"
41
56
  puts e.backtrace
42
57
  exit!
43
58
  end
44
59
 
45
- def load!(filename) # Multiple load -> merge settings
46
- unless File.exist?(filename)
47
- puts "Unable to find config file \"#{filename}\""
60
+ def load! (filename) # Multiple load -> merge settings
61
+ unless File.exist?(File.expand_path(filename))
62
+ puts "Unable to find config file \"#{File.expand_path(filename)}\""
48
63
  exit!
49
64
  end
50
- unless @@_files.include? filename
51
- @@_files << filename
65
+ unless FILES.include? filename
66
+ FILES << filename
52
67
  newsets = YAML::load_file(filename).deep_symbolize
53
- deep_merge!(@@_settings, newsets)
68
+ deep_merge!(SETTINGS, newsets)
54
69
  end
70
+ ### initialize type, env from defaults unless already defined
71
+ self.env ||= defaults(:env).to_sym
72
+ self.type ||= defaults(:type).to_sym
55
73
  end
56
74
 
57
75
  def deep_merge!(target, data)
@@ -61,68 +79,70 @@ module Devinstall
61
79
  target.merge! data, &merger
62
80
  end
63
81
 
82
+ def self.defaults(key=nil)
83
+ return SETTINGS.has_key? :defaults if key.nil?
84
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:package, :type, :env, :providers].include? key
85
+ SETTINGS[:defaults][key] or raise KeyNotDefinedError, "Undefined key :default:#{key.to_s}"
86
+ end
87
+
64
88
  def defaults(key=nil)
65
- return @@_settings.has_key? :defaults if key.nil?
66
- raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:package, :type, :env].include? key
67
- @@_settings[:defaults][key] or raise KeyNotDefinedError, "Undefined key :default:#{key.to_s}"
89
+ self.class.defaults key
68
90
  end
69
91
 
70
- def base(key=nil)
71
- return @@_settings.has_key? :base if key.nil?
92
+ def self.base(key=nil)
93
+ return SETTINGS.has_key? :base if key.nil?
72
94
  raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:rsync, :ssh, :sudo, :scp].include? key
73
- @@_settings[:base][key] or raise KeyNotDefinedError, "Undefined key :base:#{key.to_s}"
95
+ SETTINGS[:base][key] or raise KeyNotDefinedError, "Undefined key :base:#{key.to_s}"
74
96
  end
75
97
 
76
- def local(key)
77
- raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:folder, :temp].include? key
78
- ret=@@_settings[:local][key]
79
- if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :local
80
- ret = @@_settings[:packages][self.pgk.to_sym][self.type][:local][key] || ret
81
- end
82
- ret or raise KeyNotDefinedError, "Undefined key :local:#{key} or :#{self.pkg}:local:#{key}"
98
+ def base(key=nil)
99
+ self.class.base key
83
100
  end
84
101
 
85
- def build(key)
86
- raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :target, :arch, :command].include? key
87
- ret=@@_settings[:build][key]
88
- if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :build
89
- ret = @@_settings[:packages][self.pkg.to_sym][self.type][:build][key] || ret
102
+ def global_or_local(section, key)
103
+ ret = nil
104
+ if SETTINGS[:packages][self.pkg][self.type].has_key? section
105
+ ret ||= SETTINGS[:packages][self.pkg][self.type][section][self.env][key] if SETTINGS[:packages][self.pkg][self.type][section].has_key? self.env
106
+ ret ||= SETTINGS[:packages][self.pkg][self.type][section][key] # or nil
90
107
  end
91
- ret or raise KeyNotDefinedError, "Undefined key :build:#{key} or :#{self.pkg}:#{self.type}:build:#{key}"
108
+ ret ||= SETTINGS[section][self.env][key] if SETTINGS[section].has_key? self.env
109
+ ret ||= SETTINGS[section][key] # or nil
110
+ ret
92
111
  end
93
112
 
94
- def install(key)
95
- raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :type, :arch].include? key
96
- ret=@@_settings[:install][self.env][key]
97
- if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :install and @@_settings[:packages][:install].has_key? self.env
98
- ret = @@_settings[:packages][self.pgk.to_sym][self.type][:install][self.env][key] || ret
99
- end
100
- ret or raise KeyNotDefinedError, "Undefined key :install:#{self.env.to_s}:#{key} or :#{self.pkg}:install:#{self.env.to_s}:#{key}"
113
+ def local(key=nil)
114
+ return SETTINGS.has_key? :local if key.nil?
115
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:folder, :temp].include? key
116
+ global_or_local(:local, key) or raise KeyNotDefinedError, "Undefined key :local:#{key} or :#{self.pkg}:local:#{key}"
117
+ end
118
+
119
+ def build(key=nil)
120
+ return (SETTINGS.has_key? :build or SETTINGS[:packages][self.pkg][self.type].has_key? :build) if key.nil?
121
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :target, :arch, :command, :provider].include? key
122
+ global_or_local(:build, key) or raise KeyNotDefinedError, "Undefined key :build:#{key} or :#{self.pkg}:#{self.type}:build:#{key}"
123
+ end
124
+
125
+ def install(key=nil)
126
+ return SETTINGS.has_key? :install if key.nil?
127
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :type, :arch, :provider].include? key
128
+ global_or_local(:install, key) or raise KeyNotDefinedError, "Undefined key :install:#{self.env.to_s}:#{key} or :#{self.pkg}:install:#{self.env.to_s}:#{key}"
101
129
  end
102
130
 
103
131
  def tests(key=nil) # tests don't have 'env'
104
- return @@_settings.has_key?(:tests) if key.nil?
105
- raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:machine, :folder, :user, :command].include? key
106
- ret=@@_settings[:tests][key]
107
- if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :tests
108
- ret = @@_settings[:packages][self.pkg.to_sym][self.type][:tests][key] || ret
109
- end
110
- ret or raise KeyNotDefinedError, "Undefined key :tests:#{self.env.to_s}:#{key} or :#{self.pkg}:tests:#{self.env.to_s}:#{key}"
132
+ return SETTINGS.has_key?(:tests) if key.nil?
133
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:machine, :folder, :user, :command, :provider].include? key
134
+ global_or_local(:tests, key) or raise KeyNotDefinedError, "Undefined key :tests:#{self.env.to_s}:#{key} or :#{self.pkg}:tests:#{self.env.to_s}:#{key}"
111
135
  end
112
136
 
113
- def repos(key)
137
+ def repos(key=nil)
138
+ return SETTINGS.has_key?(:repos) if key.nil?
114
139
  raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :type, :arch].include? key
115
- ret=@@_settings[:repos][self.env][key]
116
- if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :repos and @@_settings[:packages][:repos].has_key? self.env
117
- ret = @@_settings[:packages][self.pkg.to_sym][self.type][:repos][self.env][key] || ret
118
- end
119
- ret or raise KeyNotDefinedError, "Undefined key :repos:environments:#{self.env.to_s}:#{key} or :#{self.pkg}:repos:#{self.env.to_s}:#{key}"
140
+ global_or_local(:repos, key) or raise KeyNotDefinedError, "Undefined key :repos:environments:#{self.env.to_s}:#{key} or :#{self.pkg}:repos:#{self.env.to_s}:#{key}"
120
141
  end
121
142
 
122
- %w(repos packages).each do |m|
123
- define_method(m) do
124
- @@_settings[m.to_sym]
125
- end
143
+ def packages(key=nil)
144
+ return SETTINGS.has_key?(:packages) if key.nil?
145
+ SETTINGS[:packages][key] ## no checks here!
126
146
  end
127
147
 
128
148
  end
@@ -1,29 +1,36 @@
1
1
  module Utils
2
+ class CommandError < RuntimeError
3
+ attr_accessor :command_output, :return_code
4
+
5
+ def verbose_message
6
+ if $verbose
7
+ puts self.message
8
+ puts '#'*20
9
+ puts self.command_output
10
+ puts '#'*20
11
+ puts "Exit code: #{self.return_code}"
12
+ end
13
+ end
14
+ end
2
15
 
3
16
  def command(cmd)
4
17
  puts cmd if $verbose
5
18
  ret=''
6
19
  unless $dry
7
- ret = `#{cmd}` unless $dry
20
+ ret = `#{cmd}`
8
21
  if $?.exitstatus != 0 ## return failure
9
- puts "While executing:"
10
- puts cmd
11
- puts "The command failed with exitstatus #{$?.exitstatus}"
12
- puts "Full output of command follows"
13
- puts "="*40
14
- puts ret
15
- puts "="*40
16
- puts "Nothing to do. Aborting!"
17
- exit! "Done"
22
+ err=CommandError.new "ErrorRunning #{cmd}"
23
+ err.command_output = ret
24
+ err.return_code = $?.exitstatus
25
+ raise err
18
26
  end
19
27
  end
20
28
  ret
21
29
  end
22
30
 
23
- def exit! msg
24
- puts msg || "Aborting!"
31
+ def exit!(msg=nil)
32
+ puts msg || 'Aborting!'
25
33
  Kernel.exit 1
26
34
  end
27
35
 
28
-
29
36
  end #module
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = '1.0.0' # Working!
2
+ VERSION = '1.0.1' # Working!
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -32,11 +32,10 @@ module Devinstall
32
32
  end
33
33
 
34
34
  # @param [String] package
35
- # @param [String] config
36
- def initialize (config)
37
- @config=config #class variable,first thing!
38
- # currently implemented only for .deb packages (for .rpm later :D)
39
- @package = @config.pkg.to_sym
35
+ def initialize(package)
36
+ @config=Settings.instance #class variable,first thing!
37
+ @config.pkg=package # very important!
38
+ @package = package # currently implemented only for .deb packages (for .rpm later :D)
40
39
  @_package_version = {} # versions for types:
41
40
  @package_files = {}
42
41
  arch = @config.build(:arch)
@@ -51,12 +50,18 @@ module Devinstall
51
50
  scp = @config.base(:scp)
52
51
  repo = {}
53
52
  [:user, :host, :folder, :type].each do |k|
54
- repo[k] = @config.repos(k) # looks stupid
53
+ repo[k] = @config.repos(k) # looks stupid
55
54
  end
56
55
  @package_files[type].each do |p, f|
57
56
  puts "Uploading #{f}\t\t[#{p}] to $#{repo[:host]}"
58
57
  command("#{scp} #{@config.local(:temp)}/#{f} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
59
58
  end
59
+ rescue CommandError => e
60
+ puts e.verbose_message
61
+ exit! ''
62
+ rescue KeyNotdefinederror => e
63
+ puts e.message
64
+ exit! ''
60
65
  end
61
66
 
62
67
  def build
@@ -84,6 +89,12 @@ module Devinstall
84
89
  puts "Receiving target #{p.to_s} for #{t.to_s}"
85
90
  command("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
86
91
  end
92
+ rescue CommandError => e
93
+ puts e.verbose_message
94
+ exit! ''
95
+ rescue KeyNotdefinederror => e
96
+ puts e.message
97
+ exit! ''
87
98
  end
88
99
 
89
100
  def install
@@ -107,31 +118,37 @@ module Devinstall
107
118
  else
108
119
  exit! "unknown package type '#{type.to_s}'"
109
120
  end
121
+ rescue CommandError => e
122
+ puts e.verbose_message
123
+ exit! ''
124
+ rescue KeyNotdefinederror => e
125
+ puts e.message
126
+ exit! ''
110
127
  end
111
128
 
112
129
  def run_tests
113
130
  # check if we have the test section in the configuration file
114
131
  unless @config.tests
115
- puts "No test section in the config file."
116
- puts "Skipping tests"
117
- return;
132
+ puts 'No test section in the config file.'
133
+ puts 'Skipping tests'
134
+ return
118
135
  end
119
136
  # for tests we will use almost the same setup as for build
120
137
  test = {}
121
138
  [:user, :machine, :command, :folder].each do |k|
122
- test[k] = @config.(k)
139
+ test[k] = @config.tests(k)
123
140
  end
124
141
  ssh = @config.base(:ssh)
125
142
  # replace "variables" in commands
126
143
  test[:command] = test[:command].
127
- gsub('%f', test[:folder]). # %f is the folder where the sources are rsync-ed
128
- gsub('%t', @config.build(:target)). # %t is the folder where the build places the result
129
- gsub('%p', @package.to_s) # %p is the package name
144
+ gsub('%f', test[:folder]).# %f is the folder where the sources are rsync-ed
145
+ gsub('%t', @config.build(:target)).# %t is the folder where the build places the result
146
+ gsub('%p', @package.to_s) # %p is the package name
130
147
  # take the sources from the local folder
131
148
  local_folder = File.expand_path @config.local(:folder)
132
149
  # upload them to the test machine
133
150
  upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}")
134
- puts "Running all tests"
151
+ puts 'Running all tests'
135
152
  puts 'This will take some time and you have no output'
136
153
  command("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
137
154
  end
@@ -140,6 +157,12 @@ module Devinstall
140
157
  rsync = @config.base(:rsync)
141
158
  command("#{rsync} -az #{source} #{dest}")
142
159
  end
160
+ rescue CommandError => e
161
+ puts e.verbose_message
162
+ exit! ''
163
+ rescue KeyNotdefinederror => e
164
+ puts e.message
165
+ exit! ''
143
166
  end
144
167
 
145
168
  end
@@ -0,0 +1,31 @@
1
+ require 'rspec'
2
+
3
+ require 'devinstall/settings'
4
+
5
+ describe 'Settings' do
6
+ config=Devinstall::Settings.instance
7
+ config.load! "./doc/example.yml"
8
+
9
+ it 'should load at init' do
10
+ expect(config).to be_an_instance_of(Devinstall::Settings)
11
+ [:defaults, :base, :local, :build, :install, :tests, :packages, :repos].each do |p|
12
+ expect(config.send(p)).to be_true
13
+ end # all sections loaded!
14
+ end
15
+
16
+ it 'should have defaults' do
17
+ expect(config.defaults).to be_true
18
+ end
19
+
20
+ it 'should have a static default' do
21
+ expect(Devinstall::Settings.defaults(:package)).to be(config.defaults(:package))
22
+ end
23
+
24
+ it 'should raise errors for unknown keys' do
25
+ expect{config.defaults :none}.to raise_error(Devinstall::UnknownKeyError)
26
+ end
27
+
28
+ it 'should raise errors for undefined keys' do
29
+ expect{config.tests(:provider)}.to raise_error(Devinstall::KeyNotDefinedError)
30
+ end
31
+ 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: 1.0.0
4
+ version: 1.0.1
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-27 00:00:00.000000000 Z
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: remote builder and installer
56
70
  email:
57
71
  - dboca@mail.com
@@ -75,6 +89,7 @@ files:
75
89
  - lib/devinstall/settings.rb
76
90
  - lib/devinstall/utils.rb
77
91
  - lib/devinstall/version.rb
92
+ - spec/settings_spec.rb
78
93
  homepage: http://github.com/dboca/devinstall
79
94
  licenses:
80
95
  - MIT
@@ -100,4 +115,5 @@ signing_key:
100
115
  specification_version: 4
101
116
  summary: Copy the source files to a build host, build the packages and install builded
102
117
  packages
103
- test_files: []
118
+ test_files:
119
+ - spec/settings_spec.rb