Module: Spider::AppManager
- Defined in:
- lib/spiderfw/setup/app_manager.rb
Class Method Summary collapse
- .git_install(spec, home_path, options = {}) ⇒ Object
- .git_update(spec, home_path, options = {}) ⇒ Object
- .install(specs, home_path, options) ⇒ Object
- .pack_install(spec, home_path, options = {}) ⇒ Object
- .pack_update(spec, home_path, options = {}) ⇒ Object
- .post_setup(specs, options = {}) ⇒ Object
- .pre_setup(specs, options = {}) ⇒ Object
- .update(specs, home_path, options) ⇒ Object
Instance Method Summary collapse
Class Method Details
.git_install(spec, home_path, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spiderfw/setup/app_manager.rb', line 23 def self.git_install(spec, home_path, ={}) require 'grit' if ::File.exist?("apps/#{spec.id}") puts _("%s already installed, skipping") % spec.id return end repo = Grit::Repo.new(home_path) puts _("Fetching %s from %s") % [spec.app_id, spec.git_repo] repo_url = spec.git_repo if [:ssh_user] && repo_url =~ /ssh:\/\/([^@]+@)?(.+)/ repo_url = "ssh://#{[:ssh_user]}@#{$2}" end `#{Grit::Git.git_binary} submodule add #{repo_url} apps/#{spec.id}` repo.git.submodule({}, "init") repo.git.submodule({}, "update") repo.add('.gitmodules', "apps/#{spec.id}") repo.commit_index(_("Added app %s") % spec.id) end |
.git_update(spec, home_path, options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/spiderfw/setup/app_manager.rb', line 102 def self.git_update(spec, home_path, ={}) require 'grit' home_repo = Grit::Repo.new(home_path) app_path = File.join(home_path, "apps/#{spec.id}") app_repo = Grit::Repo.new(app_path) puts _("Updating %s from %s") % [spec.app_id, spec.git_repo] Dir.chdir(app_path) do app_repo.git.checkout({}, "master") end cmd = "#{Grit::Git.git_binary} --git-dir='#{app_path}/.git' pull" response = err = nil Dir.chdir(app_path) do response, err = app_repo.git.wild_sh(cmd) end if response =~ /Aborting/ puts err return end Dir.chdir(app_path) do app_repo.git.reset({:hard => true}, 'HEAD') app_repo.git.checkout end home_repo.add("apps/#{spec.id}") home_repo.commit_index(_("Updated app %s") % spec.id) end |
.install(specs, home_path, options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spiderfw/setup/app_manager.rb', line 8 def self.install(specs, home_path, ) [:use_git] = true unless [:use_git] == false [:home_path] = home_path specs = [specs] unless specs.is_a?(Array) pre_setup(specs, ) specs.each do |spec| if spec.git_repo && [:use_git] git_install(spec, home_path, ) else pack_install(spec, home_path, ) end end post_setup(specs, ) end |
.pack_install(spec, home_path, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/spiderfw/setup/app_manager.rb', line 42 def self.pack_install(spec, home_path, ={}) require 'rubygems/package' client = AppServerClient.new(spec.app_server) print _("Fetching %s from server... ") % spec.app_id tmp_path = client.fetch_app(spec.app_id) puts _("Fetched.") dest = File.join(home_path, "apps/#{spec.app_id}") FileUtils.mkdir_p(dest) open tmp_path, Gem.binary_mode do |io| Gem::Package::TarReader.new(io) do |reader| reader.each do |entry| dest_path = File.join(dest, entry.full_name) if entry.directory? FileUtils.mkdir(dest_path) elsif entry.file? File.open(dest_path, 'w') do |f| f << entry.read end end end end end end |
.pack_update(spec, home_path, options = {}) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/spiderfw/setup/app_manager.rb', line 129 def self.pack_update(spec, home_path, ={}) require 'fileutils' require 'date' require 'time' app_path = File.join(home_path, "apps/#{spec.id}") tmp_path = File.join(home_path, 'tmp') FileUtils.mkdir_p(tmp_path) tmp_app_path = File.join(tmp_path, "#{spec.id}-update-#{DateTime.now}") FileUtils.mv(app_path, tmp_app_path) begin pack_install(spec, home_path) FileUtils.rmdir(tmp_app_path) rescue puts _("Update of %s failed" % spec.id) FileUtils.mv(tmp_app_path, app_path) end end |
.post_setup(specs, options = {}) ⇒ Object
83 84 85 86 |
# File 'lib/spiderfw/setup/app_manager.rb', line 83 def self.post_setup(specs, ={}) #require 'bundler' #Bundler::Installer.install(options[:home_path], Bundler.definitions, {}) end |
.pre_setup(specs, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/spiderfw/setup/app_manager.rb', line 67 def self.pre_setup(specs, ={}) require 'rubygems' require 'rubygems/command.rb' require 'rubygems/dependency_installer.rb' unless [:no_gems] unless Gem.available?('bundler') puts _("Installing bundler gem") inst = Gem::DependencyInstaller.new inst.install 'bundler' end end end |
.update(specs, home_path, options) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/spiderfw/setup/app_manager.rb', line 88 def self.update(specs, home_path, ) [:use_git] = true unless [:use_git] == false specs = [specs] unless specs.is_a?(Array) pre_setup(specs, ) pre_update(specs, option) specs.each do |spec| if spec.git_repo && [:use_git] git_update(spec, home_path, ) else pack_update(spec, home_path, ) end end end |
Instance Method Details
#pre_update ⇒ Object
80 81 |
# File 'lib/spiderfw/setup/app_manager.rb', line 80 def pre_update end |