lib/polisher/git.rb in polisher-0.5.1 vs lib/polisher/git.rb in polisher-0.6.1

- old
+ new

@@ -3,10 +3,12 @@ # Licensed under the MIT license # Copyright (C) 2013 Red Hat, Inc. # TODO use ruby git api and others +require 'tmpdir' +require 'awesome_spawn' require 'polisher/rpmspec' module Polisher class GitPackage attr_accessor :name @@ -48,11 +50,11 @@ # @return [Polisher::GitPackage] git package instance representing cloned package def self.clone(name) rpm_name = "#{RPM_PREFIX}#{name}" unless File.directory? rpm_name - `#{PKG_CMD} clone #{rpm_name}` + AwesomeSpawn.run "#{PKG_CMD} clone #{rpm_name}" end # cd into working directory Dir.chdir rpm_name @@ -60,53 +62,53 @@ raise Exception, "Dead package detected" end # checkout the latest rawhide # TODO allow other branches to be specified - `#{GIT_CMD} checkout master` - `#{GIT_CMD} reset HEAD~ --hard` - `#{GIT_CMD} pull` + AwesomeSpawn.run "#{GIT_CMD} checkout master" + AwesomeSpawn.run "#{GIT_CMD} reset HEAD~ --hard" + AwesomeSpawn.run "#{GIT_CMD} pull" self.new :name => name end # Update the locally cloned package to the specified gem version # # @param [Polisher::Gem] gem instance of gem containing metadata to update to def update_to(gem) # TODO use Polisher::RPMSpec to update spec - `#{SED_CMD} -i "s/Version.*/Version: #{gem.version}/" #{spec}` - `#{SED_CMD} -i "s/Release:.*/Release: 1%{?dist}/" #{spec}` - `#{MD5SUM_CMD} #{gem.name}-#{gem.version}.gem > sources` + AwesomeSpawn.run "#{SED_CMD} -i 's/Version.*/Version: #{gem.version}/' #{spec}" + AwesomeSpawn.run "#{SED_CMD} -i 's/Release:.*/Release: 1%{?dist}/' #{spec}" + AwesomeSpawn.run "#{MD5SUM_CMD} #{gem.name}-#{gem.version}.gem > sources" File.open(".gitignore", "w") { |f| f.write "#{gem.name}-#{gem.version}.gem" } end # Build the locally cloned package using the configured build command def build # build srpm - `#{PKG_CMD} srpm` + AwesomeSpawn.run "#{PKG_CMD} srpm" # attempt to build packages - `#{BUILD_CMD} build --scratch #{BUILD_TGT} #{srpm}` + AwesomeSpawn.run "#{BUILD_CMD} build --scratch #{BUILD_TGT} #{srpm}" # TODO if build fails, spit out error, exit end # Return boolean indicating if package spec has a %check section # # @return [Boolean] true/false depending on whether or not spec has %check def has_check? - open(spec, "r") do |spec| + File.open(spec, "r") do |spec| spec.lines.any? { |line| line.include?("%check") } end end # Command the local package to the local git repo def commit # git add spec, git commit w/ message - `#{GIT_CMD} add #{spec} sources .gitignore` + AwesomeSpawn.run "#{GIT_CMD} add #{spec} sources .gitignore" #`git add #{gem_name}-#{version}.gem` - `#{GIT_CMD} commit -m 'updated to #{self.version}'` + AwesomeSpawn.run "#{GIT_CMD} commit -m 'updated to #{self.version}'" end # Retrieve list of the version of the specified package in git # # @param [String] name name of package to lookup @@ -117,10 +119,10 @@ version = nil Dir.mktmpdir do |dir| Dir.chdir(dir) do |path| version = nil - `#{GIT_CMD} clone #{DIST_GIT_URL}#{rpm_name}.git . >& /dev/null` + AwesomeSpawn.run "#{GIT_CMD} clone #{DIST_GIT_URL}#{rpm_name}.git ." begin spec = Polisher::RPMSpec.parse(File.read("#{rpm_name}.spec")) version = spec.version rescue => e end