module Lyp::System
Constants
- INSTALL_MSG
- LYP_LOAD_CODE
- PROFILE_FILES
- RELEASE_BIN_PATH
- RUGGED_REQ
- SELF_DIR
Public Class Methods
copy_package_files()
click to toggle source
# File lib/lyp/windows.rb, line 108 def copy_package_files package_root = File.expand_path('../../../..', 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()
click to toggle source
# 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()
click to toggle source
# File lib/lyp/system.rb, line 16 def find_rugged_gem dep = Gem::Dependency.new("rugged", RUGGED_REQ) found = !dep.matching_specs.empty? require_rugged_gem if found found end
install!()
click to toggle source
Adds ~/.lyp/bin to $PATH to the first profile file that exists, then returns the profile filename
# File lib/lyp/system.rb, line 64 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?(opts = {})
click to toggle source
# File lib/lyp/system.rb, line 55 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?()
click to toggle source
# File lib/lyp/system.rb, line 109 def is_gem? SELF_DIR !~ /#{RELEASE_BIN_PATH}$/ end
require_rugged_gem()
click to toggle source
# File lib/lyp/system.rb, line 24 def require_rugged_gem gem 'rugged', RUGGED_REQ.to_s req_ext 'rugged' end
rewrite_gem_scripts()
click to toggle source
# File lib/lyp/system.rb, line 113 def rewrite_gem_scripts %w{lyp lilypond}.each do |script_name| src_path = Gem.bin_path('lyp', script_name) dest_path = File.join(Gem.bindir, script_name) puts "cp #{src_path} #{dest_path}" FileUtils.cp(src_path, dest_path) end end
setup_bin_path()
click to toggle source
# File lib/lyp/system.rb, line 86 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()
click to toggle source
# File lib/lyp/system.rb, line 98 def setup_files if is_gem? setup_gem_files else setup_release_files end end
setup_gem_files()
click to toggle source
# File lib/lyp/system.rb, line 122 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()
click to toggle source
# File lib/lyp/system.rb, line 131 def setup_release_files FileUtils.rm_rf(Lyp::LYP_BIN_DIRECTORY) FileUtils.mkdir_p(Lyp::LYP_BIN_DIRECTORY) release_dir = File.expand_path(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!()
click to toggle source
# File lib/lyp/system.rb, line 49 def test_installed_status! if !is_gem? && !installed? STDERR.puts INSTALL_MSG end end
test_rugged_gem!()
click to toggle source
# File lib/lyp/system.rb, line 5 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!()
click to toggle source
# File lib/lyp/system.rb, line 149 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()
click to toggle source
# File lib/lyp/system.rb, line 29 def use_git_based_rugged_gem git_available = `git --version` rescue nil return false unless git_available require File.expand_path('git_based_rugged', File.dirname(__FILE__)) end