Module: Lyp::System
- Defined in:
- lib/lyp/system.rb,
lib/lyp/windows.rb
Constant Summary collapse
- RUGGED_REQ =
Lyp.version_req('>=0.23.0')
- INSTALL_MSG =
<<EOF Warning! Lyp is not yet properly installed in your home directory. To install lyp run 'lyp install self'. lyp will then: 1. Setup ~/.lyp as its base directory. 2. Add the lyp and lilypond scripts to ~/.lyp/bin. 3. Add ~/.lyp/bin to front of $PATH. You can uninstall lyp at any time by running 'lyp uninstall self'. EOF
- PROFILE_FILES =
%w{ .profile .bash_profile .bash_login .bashrc .zshenv .zshrc .mkshrc }.map {|fn| File.join(Dir.home, fn)}
- LYP_LOAD_CODE =
<<EOF [[ ":${PATH}:" == *":${HOME}/.lyp/bin:"* ]] || PATH="$HOME/.lyp/bin:$PATH" EOF
- RELEASE_BIN_PATH =
"lib/app/bin"- SELF_DIR =
File.(File.dirname($0))
Class Method Summary collapse
- .copy_package_files ⇒ Object
- .create_wrapper_batch_files ⇒ Object
- .find_rugged_gem ⇒ Object
-
.install! ⇒ Object
-
Copy the entire directory to ~/.lyp - Create wrappers in Windows/System32 that call ~/.lyp/bin.
-
- .installed? ⇒ Boolean
- .is_gem? ⇒ Boolean
- .require_rugged_gem ⇒ Object
- .setup_bin_path ⇒ Object
- .setup_files ⇒ Object
- .setup_gem_files ⇒ Object
- .setup_release_files ⇒ Object
- .test_installed_status! ⇒ Object
- .test_rugged_gem! ⇒ Object
- .uninstall! ⇒ Object
- .use_git_based_rugged_gem ⇒ Object
Class Method Details
.copy_package_files ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/lyp/windows.rb', line 108 def copy_package_files package_root = File.('../../../..', File.dirname(__FILE__)) FileUtils.rm_rf("#{Lyp::LYP_DIRECTORY}/lib") FileUtils.rm_rf("#{Lyp::LYP_DIRECTORY}/bin") FileUtils.cp_r("#{package_root}/lib", "#{Lyp::LYP_DIRECTORY}/lib") FileUtils.cp_r("#{package_root}/bin", "#{Lyp::LYP_DIRECTORY}/bin") end |
.create_wrapper_batch_files ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lyp/windows.rb', line 116 def create_wrapper_batch_files system32_dir = File.join(ENV["SystemRoot"], "System32") bin_dir = "#{Lyp::LYP_DIRECTORY}/bin" %w{lyp lilypond}.each do |name| File.open("#{system32_dir}/#{name}.bat", "w+") do |f| f << "@#{bin_dir}\\#{name}.bat %*" end end end |
.find_rugged_gem ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/lyp/system.rb', line 18 def find_rugged_gem found = Gem::Specification.find_all_by_name('rugged').find do |s| RUGGED_REQ =~ s.version end require_rugged_gem if found found end |
.install! ⇒ Object
-
Copy the entire directory to ~/.lyp
-
Create wrappers in Windows/System32 that call ~/.lyp/bin
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lyp/system.rb', line 67 def install! puts "\nInstalling lyp...\n\nAdding ~/.lyp/bin to $PATH..." profile_fn = setup_bin_path puts "Setting up binary scripts..." setup_files if installed?(no_path_check: true) puts "\nTo finish installation, open a new shell or run 'source ~/#{File.basename(profile_fn)}'.\n\n" else raise "Failed to install lyp" end end |
.installed? ⇒ Boolean
58 59 60 61 62 63 |
# File 'lib/lyp/system.rb', line 58 def installed?(opts = {}) path_is_there = ":#{::ENV['PATH']}:" =~ /#{Lyp::LYP_BIN_DIRECTORY}/ file_is_there = File.file?("#{Lyp::LYP_BIN_DIRECTORY}/lyp") (opts[:no_path_check] || path_is_there) && file_is_there end |
.is_gem? ⇒ Boolean
112 113 114 |
# File 'lib/lyp/system.rb', line 112 def is_gem? SELF_DIR !~ /#{RELEASE_BIN_PATH}$/ end |
.require_rugged_gem ⇒ Object
27 28 29 30 |
# File 'lib/lyp/system.rb', line 27 def require_rugged_gem gem 'rugged', RUGGED_REQ.to_s require 'rugged' end |
.setup_bin_path ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lyp/system.rb', line 89 def setup_bin_path fn = PROFILE_FILES.find {|f| File.file?(f)} unless fn raise "Could not find a shell profile file" end unless (IO.read(fn) =~ /\.lyp\/bin/) File.open(fn, 'a') {|f| f << LYP_LOAD_CODE} end fn end |
.setup_files ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/lyp/system.rb', line 101 def setup_files if is_gem? setup_gem_files else setup_release_files end end |
.setup_gem_files ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/lyp/system.rb', line 116 def setup_gem_files FileUtils.rm_rf(Lyp::LYP_BIN_DIRECTORY) FileUtils.mkdir_p(Lyp::LYP_BIN_DIRECTORY) %w{lyp lilypond}.each do |fn| FileUtils.ln_sf("#{SELF_DIR}/#{fn}", "#{Lyp::LYP_BIN_DIRECTORY}/#{fn}") end end |
.setup_release_files ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/lyp/system.rb', line 125 def setup_release_files FileUtils.rm_rf(Lyp::LYP_BIN_DIRECTORY) FileUtils.mkdir_p(Lyp::LYP_BIN_DIRECTORY) release_dir = File.(File.join(SELF_DIR, '../../../')) puts "Copying Ruby runtime & gems..." lib_dir = File.join(release_dir, 'lib') FileUtils.rm_rf(Lyp::LYP_LIB_DIRECTORY) FileUtils.cp_r(lib_dir, Lyp::LYP_LIB_DIRECTORY) puts "Copying binary scripts..." wrapper_bin_dir = File.join(release_dir, 'bin') %w{lyp lilypond}.each do |f| FileUtils.cp("#{wrapper_bin_dir}/#{f}", "#{Lyp::LYP_BIN_DIRECTORY}/#{f}") end end |
.test_installed_status! ⇒ Object
52 53 54 55 56 |
# File 'lib/lyp/system.rb', line 52 def test_installed_status! if !is_gem? && !installed? STDERR.puts INSTALL_MSG end end |
.test_rugged_gem! ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/lyp/system.rb', line 7 def test_rugged_gem! return if @already_tested return if find_rugged_gem || use_git_based_rugged_gem STDERR.puts "Lyp needs git in order to be able to install packages. Please install git and then try again." exit 1 ensure @already_tested = true end |
.uninstall! ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/lyp/system.rb', line 143 def uninstall! puts "\nUninstalling lyp...\n\nRemoving ~/.lyp/bin from $PATH..." # Remove ~/.lyp/bin from $PATH PROFILE_FILES.each do |fn| next unless File.file?(fn) content = IO.read(fn) if (content =~ /\.lyp\/bin/) content.gsub!(/\n?.*\.lyp\/bin.*\n/, '') File.open(fn, 'w+') {|f| f << content} end end puts "Removing binary scripts..." # Delete bin scripts Dir["#{Lyp::LYP_BIN_DIRECTORY}/*"].each do |fn| FileUtils.rm_f(fn) rescue nil end puts "\nTo completely remove installed packages and lilyponds run 'rm -rf ~/.lyp'.\n\n" end |
.use_git_based_rugged_gem ⇒ Object
32 33 34 35 36 37 |
# File 'lib/lyp/system.rb', line 32 def use_git_based_rugged_gem git_available = `git --version` rescue nil return false unless git_available require File.('git_based_rugged', File.dirname(__FILE__)) end |