lib/boxgrinder-build/helpers/package-helper.rb in boxgrinder-build-0.7.1 vs lib/boxgrinder-build/helpers/package-helper.rb in boxgrinder-build-0.8.0
- old
+ new
@@ -14,19 +14,20 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+require 'boxgrinder-core/helpers/log-helper'
+
module BoxGrinder
class PackageHelper
- def initialize(config, appliance_config, dir, options = {})
- @config = config
+ def initialize(config, appliance_config, options = {})
+ @config = config
@appliance_config = appliance_config
- @dir = dir
- @log = options[:log] || Logger.new(STDOUT)
- @exec_helper = options[:exec_helper] || ExecHelper.new({:log => @log})
+ @log = options[:log] || LogHelper.new
+ @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
end
def package(dir, package, type = :tar)
if File.exists?(package)
@log.info "Package of #{type} type for #{@appliance_config.name} appliance already exists, skipping."
@@ -36,20 +37,16 @@
@log.info "Packaging #{@appliance_config.name} appliance to #{type}..."
case type
when :tar
package_name = File.basename(package, '.tgz')
- symlink = "#{File.dirname(package)}/#{package_name}"
+ symlink = "#{File.dirname(package)}/#{package_name}"
FileUtils.ln_s(File.expand_path(dir), symlink)
-
- Dir.chdir(File.dirname(package)) do
- @exec_helper.execute "tar -hcvzf #{package_name}.tgz #{package_name}"
- end
-
+ @exec_helper.execute "tar -C '#{File.dirname(package)}' -hcvzf '#{package}' '#{package_name}'"
FileUtils.rm(symlink)
else
- raise "Only tar format is currently supported."
+ raise "Specified format: '#{type}' is currently unsupported."
end
@log.info "Appliance #{@appliance_config.name} packaged."
package