Class: Pkgr::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pkgr/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, opts = {}) ⇒ Dispatcher



8
9
10
11
12
13
# File 'lib/pkgr/dispatcher.rb', line 8

def initialize(path, opts = {})
  opts = opts.dup
  @path = File.expand_path(path)
  @host = opts.delete(:host)
  @config = Config.new(opts)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/pkgr/dispatcher.rb', line 6

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/pkgr/dispatcher.rb', line 6

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/pkgr/dispatcher.rb', line 6

def path
  @path
end

Instance Method Details

#callObject



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 "#{host}":~/*.deb .}
    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



51
52
53
# File 'lib/pkgr/dispatcher.rb', line 51

def remote?
  !host.nil?
end

#setupObject



15
16
17
# File 'lib/pkgr/dispatcher.rb', line 15

def setup
  tarify if File.directory?(path)
end

#tarifyObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pkgr/dispatcher.rb', line 37

def tarify
  tmpfile = Tempfile.new(["pkgr-tarball", ".tar.gz"])
  system("tar czf #{tmpfile.path} --exclude .git --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')
    v = "0.0.0" if v !~ /^\d/
    v
  end
  config.compile_cache_dir ||= File.join(path, ".git", "cache")
  config.name ||= File.basename(path)
  @path = tmpfile.path
end