Class: Pkgr::Addon

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

Defined Under Namespace

Classes: LiveStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nickname, addons_dir, config) ⇒ Addon

Returns a new instance of Addon.



6
7
8
9
10
# File 'lib/pkgr/addon.rb', line 6

def initialize(nickname, addons_dir, config)
  @nickname = nickname
  @addons_dir = addons_dir
  @config = config
end

Instance Attribute Details

#addons_dirObject (readonly)

Returns the value of attribute addons_dir.



3
4
5
# File 'lib/pkgr/addon.rb', line 3

def addons_dir
  @addons_dir
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/pkgr/addon.rb', line 4

def config
  @config
end

#nicknameObject (readonly)

Returns the value of attribute nickname.



3
4
5
# File 'lib/pkgr/addon.rb', line 3

def nickname
  @nickname
end

Instance Method Details

#branchObject



32
33
34
# File 'lib/pkgr/addon.rb', line 32

def branch
  nickname.split("#")[1] || "master"
end

#debconfigObject



56
57
58
59
60
61
62
63
# File 'lib/pkgr/addon.rb', line 56

def debconfig
  debconfig_file = File.join(dir, "debian", "config")
  if File.exists?(debconfig_file)
    File.new(debconfig_file)
  else
    StringIO.new
  end
end

#debian_dependency_nameObject



40
41
42
43
44
45
# File 'lib/pkgr/addon.rb', line 40

def debian_dependency_name
  [
    [config.name, name].join("-"),
    "(= #{config.version}-#{config.iteration})"
  ].join(" ")
end

#debtemplatesObject



47
48
49
50
51
52
53
54
# File 'lib/pkgr/addon.rb', line 47

def debtemplates
  debtemplates_file = File.join(dir, "debian", "templates")
  if File.exists?(debtemplates_file)
    File.new(debtemplates_file)
  else
    StringIO.new
  end
end

#dirObject



89
90
91
92
93
94
95
# File 'lib/pkgr/addon.rb', line 89

def dir
  @dir ||= begin
    directory = File.join(addons_dir, File.basename(name))
    FileUtils.mkdir_p(directory)
    directory
  end
end

#install!(src_dir) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/pkgr/addon.rb', line 65

def install!(src_dir)
  install_addon = Mixlib::ShellOut.new %{curl -L --max-redirs 3 --retry 5 -s '#{tarball_url}' | tar xzf - --strip-components=1 -C '#{dir}'}
  install_addon.logger = Pkgr.logger
  install_addon.run_command
  install_addon.error!

  # TODO: remove args from command once all addons use env variables
  compile_addon = Mixlib::ShellOut.new(%{#{dir}/bin/compile '#{config.name}' '#{config.version}' '#{config.iteration}' '#{src_dir}' 2>&1}, {
    :environment => {
      "APP_NAME" => config.name,
      "APP_VERSION" => config.version,
      "APP_ITERATION" => config.iteration,
      "APP_SAFE_NAME" => config.name.gsub("-", "_"),
      "APP_USER" => config.user,
      "APP_GROUP" => config.group,
      "APP_WORKSPACE" => src_dir
    }
  })
  compile_addon.logger = Pkgr.logger
  compile_addon.live_stream = LiveStream.new(STDOUT)
  compile_addon.run_command
  compile_addon.error!
end

#nameObject



12
13
14
# File 'lib/pkgr/addon.rb', line 12

def name
  File.basename(url_without_branch, ".git").sub("addon-", "")
end

#tarball_urlObject



36
37
38
# File 'lib/pkgr/addon.rb', line 36

def tarball_url
  "#{url}/archive/#{branch}.tar.gz"
end

#urlObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pkgr/addon.rb', line 20

def url
  if nickname.start_with?("http")
    url_without_branch
  else
    user, repo = nickname.split("/", 2)
    user, repo = "pkgr", user if repo.nil?
    repo = "addon-#{repo}" unless repo.start_with?("addon-")

    "https://github.com/#{user}/#{repo}"
  end
end

#url_without_branchObject



16
17
18
# File 'lib/pkgr/addon.rb', line 16

def url_without_branch
  nickname.split("#")[0].sub(/\.git$/,'')
end