Class: Pkgr::Dispatcher
- Inherits:
-
Object
- Object
- Pkgr::Dispatcher
- Defined in:
- lib/pkgr/dispatcher.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path, opts = {}) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #remote? ⇒ Boolean
- #setup ⇒ Object
- #tarify ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Dispatcher
Returns a new instance of Dispatcher.
8 9 10 11 12 13 |
# File 'lib/pkgr/dispatcher.rb', line 8 def initialize(path, opts = {}) opts = opts.dup @path = path == '-' ? path : File.(path) @host = opts.delete(:host) @config = Config.new(opts) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/pkgr/dispatcher.rb', line 6 def config @config end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/pkgr/dispatcher.rb', line 6 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/pkgr/dispatcher.rb', line 6 def path @path end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pkgr/dispatcher.rb', line 19 def call setup if remote? command = %{ ( cat "#{path}" | ssh "#{host}" pkgr package - #{config.to_args.join(" ")} ) && rsync -av --include './' --include '*.deb' --include '*.rpm' --exclude '*' "#{host}":~/ .} Pkgr.debug command IO.popen(command) do |io| until io.eof? data = io.gets print data end end raise "Error when running remote packaging command. Please make sure to run `sudo apt-get install -y ruby1.9.1-full build-essential git-core && sudo gem install pkgr --version #{Pkgr::VERSION}`" unless $?.exitstatus.zero? else Builder.new(path, config).call end end |
#remote? ⇒ Boolean
55 56 57 |
# File 'lib/pkgr/dispatcher.rb', line 55 def remote? !host.nil? end |
#setup ⇒ Object
15 16 17 |
# File 'lib/pkgr/dispatcher.rb', line 15 def setup tarify if File.directory?(path) end |
#tarify ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pkgr/dispatcher.rb', line 37 def tarify tmpfile = Tempfile.new(["pkgr-tarball", ".tar.gz"]) system("tar czf #{tmpfile.path} --exclude .svn -C \"#{path}\" .") || raise(Pkgr::Errors::Base, "Can't compress input directory") # Remove any non-digit characters that may be before the version number config.version ||= begin v = (Git.new(path).latest_tag || "").gsub(/^[^\d]+(\d.*)/, '\1') # If it's not a Git archive, try to figure out svn revision number begin v = `cd #{path.to_s} && svn info 2>/dev/null | grep Revision`.to_s.gsub!(/\D/, "") if (v !~ /^\d/) rescue end v = "0.0.0" if v !~ /^\d/ v end config.name ||= File.basename(path) @path = tmpfile.path end |