lib/devinstall.rb in devinstall-1.0.0 vs lib/devinstall.rb in devinstall-1.0.1
- old
+ new
@@ -30,15 +30,14 @@
end
end
end
# @param [String] package
- # @param [String] config
- def initialize (config)
- @config=config #class variable,first thing!
- # currently implemented only for .deb packages (for .rpm later :D)
- @package = @config.pkg.to_sym
+ def initialize(package)
+ @config=Settings.instance #class variable,first thing!
+ @config.pkg=package # very important!
+ @package = package # currently implemented only for .deb packages (for .rpm later :D)
@_package_version = {} # versions for types:
@package_files = {}
arch = @config.build(:arch)
p_name = "#{@package}_#{get_version}"
@package_files[:deb] = {deb: "#{p_name}_#{arch}.deb",
@@ -49,16 +48,22 @@
def upload
scp = @config.base(:scp)
repo = {}
[:user, :host, :folder, :type].each do |k|
- repo[k] = @config.repos(k) # looks stupid
+ repo[k] = @config.repos(k) # looks stupid
end
@package_files[type].each do |p, f|
puts "Uploading #{f}\t\t[#{p}] to $#{repo[:host]}"
command("#{scp} #{@config.local(:temp)}/#{f} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
end
+ rescue CommandError => e
+ puts e.verbose_message
+ exit! ''
+ rescue KeyNotdefinederror => e
+ puts e.message
+ exit! ''
end
def build
type = @config.type
puts "Building package #{@package} type #{type}"
@@ -82,10 +87,16 @@
command("#{ssh} #{build[:user]}@#{build[:host]} \"#{build_command}\"")
@package_files[type].each do |p, t|
puts "Receiving target #{p.to_s} for #{t.to_s}"
command("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
end
+ rescue CommandError => e
+ puts e.verbose_message
+ exit! ''
+ rescue KeyNotdefinederror => e
+ puts e.message
+ exit! ''
end
def install
env = @config.env
puts "Installing #{@package} in #{env} environment."
@@ -105,42 +116,54 @@
command("#{sudo} #{install[:user]}@#{host} /usr/bin/dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
end
else
exit! "unknown package type '#{type.to_s}'"
end
+ rescue CommandError => e
+ puts e.verbose_message
+ exit! ''
+ rescue KeyNotdefinederror => e
+ puts e.message
+ exit! ''
end
def run_tests
# check if we have the test section in the configuration file
unless @config.tests
- puts "No test section in the config file."
- puts "Skipping tests"
- return;
+ puts 'No test section in the config file.'
+ puts 'Skipping tests'
+ return
end
# for tests we will use almost the same setup as for build
test = {}
[:user, :machine, :command, :folder].each do |k|
- test[k] = @config.(k)
+ test[k] = @config.tests(k)
end
ssh = @config.base(:ssh)
# replace "variables" in commands
test[:command] = test[:command].
- gsub('%f', test[:folder]). # %f is the folder where the sources are rsync-ed
- gsub('%t', @config.build(:target)). # %t is the folder where the build places the result
- gsub('%p', @package.to_s) # %p is the package name
+ gsub('%f', test[:folder]).# %f is the folder where the sources are rsync-ed
+ gsub('%t', @config.build(:target)).# %t is the folder where the build places the result
+ gsub('%p', @package.to_s) # %p is the package name
# take the sources from the local folder
local_folder = File.expand_path @config.local(:folder)
# upload them to the test machine
upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}")
- puts "Running all tests"
+ puts 'Running all tests'
puts 'This will take some time and you have no output'
command("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
end
def upload_sources (source, dest)
rsync = @config.base(:rsync)
command("#{rsync} -az #{source} #{dest}")
end
+ rescue CommandError => e
+ puts e.verbose_message
+ exit! ''
+ rescue KeyNotdefinederror => e
+ puts e.message
+ exit! ''
end
end