class MsPac::Pellet
Public Class Methods
new(json, pm)
click to toggle source
# File lib/mspac/pellet.rb, line 110 def initialize(json, pm) json.keys.each do |key| self[key] = json[key] end @pm = pm @vcs = MsPac::VersionControl.new(self["vcs"]) end
Public Instance Methods
cached?()
click to toggle source
# File lib/mspac/pellet.rb, line 8 def cached? Pathname.new("#{@@cache_dir}/#{name}").expand_path.exist? end
desc()
click to toggle source
# File lib/mspac/pellet.rb, line 19 def desc return self["desc"] end
fetch()
click to toggle source
# File lib/mspac/pellet.rb, line 40 def fetch FileUtils.mkdir_p(@@cache_dir) FileUtils.mkdir_p(@@install_dir) get_deps puts hilight_status("Fetching #{name}...") if (Pathname.new("#{@@cache_dir}/#{name}").expand_path.exist?) Dir.chdir("#{@@cache_dir}/#{name}") do @vcs.update end else Dir.chdir(@@cache_dir) do @vcs.clone(self["repo"]) @vcs.ignore_file_perms(name) end end end
install()
click to toggle source
# File lib/mspac/pellet.rb, line 119 def install if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end link if (!installed?) compile puts hilight_status("Installing #{name}...") execute("install") end
installed?()
click to toggle source
# File lib/mspac/pellet.rb, line 131 def installed? Pathname.new("#{@@install_dir}/#{name}").expand_path.exist? end
link()
click to toggle source
# File lib/mspac/pellet.rb, line 135 def link if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") puts hilight_status("Linking #{name}...") FileUtils.ln_sf( "#{@@cache_dir}/#{name}", "#{@@install_dir}/#{name}" ) end
lock()
click to toggle source
# File lib/mspac/pellet.rb, line 149 def lock if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Locking #{name}...") FileUtils.touch("#{@@install_dir}/#{name}/.mspac_lock") end
name()
click to toggle source
# File lib/mspac/pellet.rb, line 158 def name return self["name"] end
purge()
click to toggle source
# File lib/mspac/pellet.rb, line 162 def purge if (!cached? && (self["vcs"] != "powerpellet")) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") puts hilight_status("Purging #{name}...") FileUtils.rm_rf("#{@@cache_dir}/#{name}") end
remove(nosave = false)
click to toggle source
# File lib/mspac/pellet.rb, line 173 def remove(nosave = false) if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Removing #{name}...") execute("remove") unlink purge if (nosave) end
repo()
click to toggle source
# File lib/mspac/pellet.rb, line 184 def repo return self["repo"] end
to_s()
click to toggle source
# File lib/mspac/pellet.rb, line 188 def to_s header = [ hilight_name(name), hilight_installed(installed?) || hilight_cached(cached?) ].join(" ") return [ header, " #{repo}", " #{desc}" ].join("\n") end
unlink()
click to toggle source
# File lib/mspac/pellet.rb, line 200 def unlink if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Unlinking #{name}...") FileUtils.rm_f("#{@@install_dir}/#{name}") end
unlock()
click to toggle source
# File lib/mspac/pellet.rb, line 209 def unlock if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end puts hilight_status("Unlocking #{name}...") FileUtils.rm_f("#{@@install_dir}/#{name}/.mspac_lock") end
update(force = false)
click to toggle source
# File lib/mspac/pellet.rb, line 218 def update(force = false) if (!installed?) raise MsPac::Error::PelletNotInstalled.new(name) end return if (self["vcs"] == "powerpellet") Dir.chdir("#{@@install_dir}/#{name}") do if (Pathname.new(".mspac_lock").expand_path.exist?) puts hilight_error("Locked: #{name}") return end puts hilight_status("Updating #{name}...") tip = @vcs.revision @vcs.update new_tip = @vcs.revision if ((tip != new_tip) || force) install end end end
Private Instance Methods
compile()
click to toggle source
# File lib/mspac/pellet.rb, line 12 def compile return if (self["compile"].empty?) puts hilight_status("Compiling #{name}...") execute("compile") end
execute(operation)
click to toggle source
# File lib/mspac/pellet.rb, line 23 def execute(operation) if (self["vcs"] != "powerpellet") Dir.chdir("#{@@install_dir}/#{name}") do system( ["umask 022"].concat(self[operation]).join("; ") ) end if (!self[operation].empty?) else if (!self[operation].empty?) system( ["umask 022"].concat(self[operation]).join("; ") ) end end end
get_deps()
click to toggle source
# File lib/mspac/pellet.rb, line 59 def get_deps puts hilight_status("Installing dependencies for #{name}...") deps = Array.new deps.push(self["vcs"]) if (self["vcs"] != "powerpellet") deps.push(self["deps"][@pm.pkgmgr]) @pm.install(deps) @pm.install(self["deps"]["mspac"], "mspac") @pm.install(self["deps"]["perl"], "perl") @pm.install(self["deps"]["python2"], "python2") @pm.install(self["deps"]["python3"], "python3") end
hilight_cached(cached)
click to toggle source
# File lib/mspac/pellet.rb, line 72 def hilight_cached(cached) if (!MsPac.hilight?) return "[cached]" if (cached) else return "[cached]".light_blue if (cached) end return "" end
hilight_error(error)
click to toggle source
# File lib/mspac/pellet.rb, line 82 def hilight_error(error) return error if (!MsPac.hilight?) return error.light_red end
hilight_installed(installed)
click to toggle source
# File lib/mspac/pellet.rb, line 88 def hilight_installed(installed) if (!MsPac.hilight?) return "[installed]" if (installed) else return "[installed]".light_green if (installed) end return "" end
hilight_name(name)
click to toggle source
# File lib/mspac/pellet.rb, line 98 def hilight_name(name) return name if (!MsPac.hilight?) return name.light_white end
hilight_status(status)
click to toggle source
# File lib/mspac/pellet.rb, line 104 def hilight_status(status) return status if (!MsPac.hilight?) return status.light_white end