lyp-win 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ require 'yaml'
2
+
3
+ module Lyp::Settings
4
+ class << self
5
+ def get
6
+ YAML.load(IO.read(Lyp.settings_file)) rescue {}
7
+ end
8
+
9
+ def set(o)
10
+ File.open(Lyp.settings_file, 'w+') {|f| f << YAML.dump(o)}
11
+ end
12
+
13
+ def [](path)
14
+ h = get
15
+ while path =~ /^([^\/]+)\/(.+)$/
16
+ h = h[$1.to_sym] ||= {}
17
+ path = $2
18
+ end
19
+
20
+ h[path.to_sym]
21
+ end
22
+
23
+ def []=(path, value)
24
+ h = settings = get
25
+ while path =~ /^([^\/]+)\/(.+)$/
26
+ h = h[$1.to_sym] ||= {}
27
+ path = $2
28
+ end
29
+
30
+ h[path.to_sym] = value
31
+
32
+ set(settings)
33
+
34
+ value
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,135 @@
1
+ require 'fileutils'
2
+
3
+ module Lyp::System
4
+ class << self
5
+ INSTALL_MSG = <<EOF
6
+
7
+ Warning! Lyp is not yet properly installed in your home directory.
8
+
9
+ To install lyp run 'lyp install self'. lyp will then:
10
+ 1. Setup ~/.lyp as its base directory.
11
+ 2. Add the lyp and lilypond scripts to ~/.lyp/bin.
12
+ 3. Add ~/.lyp/bin to front of $PATH.
13
+
14
+ You can uninstall lyp at any time by running 'lyp uninstall self'.
15
+
16
+ EOF
17
+
18
+ def test_installed_status!
19
+ unless installed?
20
+ puts INSTALL_MSG
21
+ end
22
+ end
23
+
24
+ def installed?(opts = {})
25
+ path_is_there = ":#{::ENV['PATH']}:" =~ /#{Lyp::LYP_BIN_DIRECTORY}/
26
+ file_is_there = File.file?("#{Lyp::LYP_BIN_DIRECTORY}/lyp")
27
+
28
+ (opts[:no_path_check] || path_is_there) && file_is_there
29
+ end
30
+
31
+ # Adds ~/.lyp/bin to $PATH to the first profile file that exists, then
32
+ # returns the profile filename
33
+ def install!
34
+ puts "\nInstalling lyp...\n\nAdding ~/.lyp/bin to $PATH..."
35
+ profile_fn = setup_bin_path
36
+ puts "Setting up binary scripts..."
37
+ setup_files
38
+
39
+ if installed?(no_path_check: true)
40
+ puts "\nTo finish installation, open a new shell or run 'source ~/#{File.basename(profile_fn)}'.\n\n"
41
+ else
42
+ raise "Failed to install lyp"
43
+ end
44
+ end
45
+
46
+ PROFILE_FILES = %w{
47
+ .profile .bash_profile .bash_login .bashrc .zshenv .zshrc .mkshrc
48
+ }.map {|fn| File.join(Dir.home, fn)}
49
+
50
+ LYP_LOAD_CODE = <<EOF
51
+
52
+ [[ ":${PATH}:" == *":${HOME}/.lyp/bin:"* ]] || PATH="$HOME/.lyp/bin:$PATH"
53
+ EOF
54
+
55
+ def setup_bin_path
56
+ fn = PROFILE_FILES.find {|f| File.file?(f)}
57
+ unless fn
58
+ raise "Could not find a shell profile file"
59
+ end
60
+
61
+ unless (IO.read(fn) =~ /\.lyp\/bin/)
62
+ File.open(fn, 'a') {|f| f << LYP_LOAD_CODE}
63
+ end
64
+ fn
65
+ end
66
+
67
+ def setup_files
68
+ bin_dir = File.expand_path(File.dirname($0))
69
+
70
+ if is_gem?(bin_dir)
71
+ setup_gem_files(bin_dir)
72
+ else
73
+ setup_release_files(bin_dir)
74
+ end
75
+ end
76
+
77
+ RELEASE_BIN_PATH = "lib/app/bin"
78
+
79
+ def is_gem?(bin_dir)
80
+ bin_dir !~ /#{RELEASE_BIN_PATH}$/
81
+ end
82
+
83
+ def setup_gem_files(bin_dir)
84
+
85
+ FileUtils.rm_rf(Lyp::LYP_BIN_DIRECTORY)
86
+ FileUtils.mkdir_p(Lyp::LYP_BIN_DIRECTORY)
87
+
88
+ %w{lyp lilypond}.each do |fn|
89
+ FileUtils.ln_sf("#{bin_dir}/#{fn}", "#{Lyp::LYP_BIN_DIRECTORY}/#{fn}")
90
+ end
91
+ end
92
+
93
+ def setup_release_files(bin_dir)
94
+ FileUtils.rm_rf(Lyp::LYP_BIN_DIRECTORY)
95
+ FileUtils.mkdir_p(Lyp::LYP_BIN_DIRECTORY)
96
+
97
+ release_dir = File.expand_path(File.join(bin_dir, '../../../'))
98
+
99
+ puts "Copying Ruby runtime & gems..."
100
+ lib_dir = File.join(release_dir, 'lib')
101
+ FileUtils.rm_rf(Lyp::LYP_LIB_DIRECTORY)
102
+ FileUtils.cp_r(lib_dir, Lyp::LYP_LIB_DIRECTORY)
103
+
104
+ puts "Copying binary scripts..."
105
+ wrapper_bin_dir = File.join(release_dir, 'bin')
106
+ %w{lyp lilypond}.each do |f|
107
+ FileUtils.cp("#{wrapper_bin_dir}/#{f}", "#{Lyp::LYP_BIN_DIRECTORY}/#{f}")
108
+ end
109
+ end
110
+
111
+ def uninstall!
112
+ puts "\nUninstalling lyp...\n\nRemoving ~/.lyp/bin from $PATH..."
113
+
114
+ # Remove ~/.lyp/bin from $PATH
115
+ PROFILE_FILES.each do |fn|
116
+ next unless File.file?(fn)
117
+
118
+ content = IO.read(fn)
119
+ if (content =~ /\.lyp\/bin/)
120
+ content.gsub!(/\n?.*\.lyp\/bin.*\n/, '')
121
+ File.open(fn, 'w+') {|f| f << content}
122
+ end
123
+ end
124
+
125
+ puts "Removing binary scripts..."
126
+ # Delete bin scripts
127
+ Dir["#{Lyp::LYP_BIN_DIRECTORY}/*"].each do |fn|
128
+ FileUtils.rm_f(fn) rescue nil
129
+ end
130
+
131
+ puts "\nTo completely remove installed packages and lilyponds run 'rm -rf ~/.lyp'.\n\n"
132
+ end
133
+ end
134
+ end
135
+
@@ -0,0 +1,59 @@
1
+ module Lyp
2
+ class Template
3
+ EMIT_DELIMITER = '`'.freeze
4
+ EMIT_RE = /#{EMIT_DELIMITER}(((?!#{EMIT_DELIMITER}).)*)#{EMIT_DELIMITER}/m
5
+
6
+ INTERPOLATION_START = "{{".freeze
7
+ INTERPOLATION_END = "}}".freeze
8
+ INTERPOLATION_RE = /#{INTERPOLATION_START}((?:(?!#{INTERPOLATION_END}).)*)#{INTERPOLATION_END}/m
9
+
10
+ ESCAPED_QUOTE = '\\"'.freeze
11
+ QUOTE = '"'.freeze
12
+
13
+ # From the metaid gem
14
+ def metaclass; class << self; self; end; end
15
+
16
+ def initialize(templ)
17
+ templ = templ.gsub(EMIT_RE) {|m| convert_literal($1)}
18
+ method_str = <<EOF
19
+ define_method(:render) do |_ = {}, env = {}|
20
+ __buffer__ = env[:buffer] ||= ''
21
+ __emit__ = env[:emit] ||= lambda {|s| __buffer__ << s}
22
+ __render_l__ = env[:render] ||= lambda {|n, o| Template.render(n, o, env)}
23
+ metaclass.instance_eval "define_method(:__render__) {|n, o| __render_l__[n, o]}"
24
+ begin
25
+ #{templ}
26
+ end
27
+ __buffer__
28
+ end
29
+ EOF
30
+
31
+ metaclass.instance_eval method_str
32
+ end
33
+
34
+ def convert_literal(s)
35
+ # look for interpolated values, wrap them with #{}
36
+ s = s.inspect.gsub(INTERPOLATION_RE) do
37
+ code = $1.gsub(ESCAPED_QUOTE, QUOTE)
38
+ "\#{#{code}}"
39
+ end
40
+ "__emit__[#{s}]"
41
+ end
42
+
43
+ # Global template registry
44
+ @@templates = {}
45
+
46
+ def self.load_templates(path)
47
+ Dir["#{path}/*.rb"].each {|fn| set(File.basename(fn), IO.read(fn))}
48
+ end
49
+
50
+ def self.set(name, templ)
51
+ @@templates[name.to_sym] = new(templ)
52
+ end
53
+
54
+ def self.render(name, arg = {}, env = {})
55
+ raise unless @@templates[name.to_sym]
56
+ @@templates[name.to_sym].render(arg, env)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ # Expect _ to be a hash of the form:
2
+ # {
3
+ # user_file: <path>
4
+ # package_paths: {
5
+ # <specifier> => <package path>
6
+ # ...
7
+ # }
8
+ # }
9
+
10
+ require 'fileutils'
11
+
12
+ user_filename = File.expand_path(_[:user_file])
13
+ user_dirname = File.dirname(user_filename)
14
+
15
+ quote_path = lambda do |path|
16
+ path = path.gsub("\\", "/") if $WINDOWS
17
+ path.inspect
18
+ end
19
+
20
+ current_package_dir = _[:current_package_dir] || FileUtils.pwd
21
+
22
+ # The wrapper defines a few global variables:
23
+ #
24
+ # lyp:input-filename - the absolute path to the input file name
25
+ # lyp:input-dirname - the absolute path to the input file directory name
26
+ # lyp:current-package-dir - the directory for the package currently being loaded
27
+ # lyp:package-refs - a hash table mapping package refs to package entry
28
+ # point absolute paths
29
+ # lyp:package-loaded - a hash table for keeping track of loaded packages
30
+ # lyp:file-included - a hash table for keeping track of include files
31
+
32
+ `
33
+ #(ly:set-option 'relative-includes #t)
34
+ \include "{{Lyp::LYP_LY_LIB_PATH}}"
35
+
36
+ #(begin
37
+ (define lyp:cwd {{quote_path[FileUtils.pwd]}})
38
+ (define lyp:input-filename {{quote_path[user_filename]}})
39
+ (define lyp:input-dirname {{quote_path[user_dirname]}})
40
+ (define lyp:current-package-dir {{quote_path[current_package_dir]}})
41
+ `
42
+
43
+ _[:package_refs].each do |spec, name|
44
+ `
45
+ (hash-set! lyp:package-refs "{{spec}}" "{{name}}")`
46
+ end
47
+
48
+ _[:package_dirs].each do |package, path|
49
+ `
50
+ (hash-set! lyp:package-dirs "{{package}}" {{quote_path[path]}})`
51
+ end
52
+
53
+
54
+ `
55
+ )
56
+
57
+ #(ly:debug "package loader is ready")
58
+ \include {{quote_path[user_filename]}}
59
+ `
@@ -0,0 +1,3 @@
1
+ module Lyp
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,110 @@
1
+ module Process
2
+ def self.getsid
3
+ if `tasklist` =~ /^ruby\.exe\s+#{Process.pid}\s+[^\s]+\s+([0-9]+)/
4
+ $1.to_i
5
+ else
6
+ 0
7
+ end
8
+ end
9
+ end
10
+
11
+ module Lyp::Lilypond
12
+ class << self
13
+ def get_system_lilyponds_paths
14
+ []
15
+ end
16
+
17
+ def lyp_lilypond_path(version)
18
+ "#{Lyp.lilyponds_dir}/#{version}/usr/bin/lilypond.exe"
19
+ end
20
+
21
+ def lyp_lilypond_share_dir(version)
22
+ File.join(Lyp.lilyponds_dir, version, 'usr/share')
23
+ end
24
+
25
+ def lyp_lilyponds
26
+ list = []
27
+
28
+ Dir["#{Lyp.lilyponds_dir}/*"].each do |path|
29
+ next unless File.directory?(path) && File.basename(path) =~ /^[\d\.]+$/
30
+
31
+ root_path = path
32
+ version = File.basename(path)
33
+ path = File.join(path, "usr/bin/lilypond.exe")
34
+ list << {
35
+ root_path: root_path,
36
+ path: path,
37
+ version: version
38
+ }
39
+ end
40
+
41
+ list
42
+ end
43
+
44
+ def download_lilypond(url, fn, opts)
45
+ STDERR.puts "Downloading #{url}" unless opts[:silent]
46
+
47
+ if opts[:silent]
48
+ `curl -s -o "#{fn}" "#{url}"`
49
+ else
50
+ `curl -o "#{fn}" "#{url}"`
51
+ end
52
+ end
53
+
54
+ def uninstall_lilypond_version(path)
55
+ # run installer
56
+ uninstaller_path = File.join(path, 'uninstall.exe')
57
+ if File.file?(uninstaller_path)
58
+ cmd = "#{uninstaller_path} /S _?=#{path.gsub('/', '\\')}"
59
+ `#{cmd}`
60
+
61
+ # wait for installer to finish
62
+ t1 = Time.now
63
+ while !File.directory?("#{target_dir}/usr")
64
+ sleep 0.5
65
+ raise "Uninstallation failed" if Time.now - t1 >= 60
66
+ end
67
+ end
68
+
69
+ FileUtils.rm_rf(path)
70
+ end
71
+ end
72
+ end
73
+
74
+ module Lyp::Package
75
+ class << self
76
+
77
+ def prepare_local_package_fonts(local_path, package_path)
78
+ # create fonts directory symlink if needed
79
+ fonts_path = File.join(local_path, 'fonts')
80
+ if File.directory?(fonts_path)
81
+ FileUtils.cp_r(fonts_path, File.join(package_path, 'fonts'))
82
+ end
83
+ end
84
+
85
+ def lilypond_fonts_path
86
+ 'usr/share/lilypond/current/fonts'
87
+ end
88
+
89
+ def lyp_index
90
+ @lyp_index ||= YAML.load(`curl -s #{LYP_INDEX_URL}`)
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ module Lyp::System
97
+ class << self
98
+ def installed?
99
+ true
100
+ end
101
+
102
+ def install!
103
+ puts "\ninstall self curently not supported on Windows.\n\n"
104
+ end
105
+
106
+ def uninstall!
107
+ puts "\nuninstall self curently not supported on Windows.\n\n"
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,22 @@
1
+ require 'tempfile'
2
+
3
+ module Lyp
4
+ WRAPPER_TEMPLATE = Lyp::Template.new(IO.read(
5
+ File.expand_path('templates/deps_wrapper.rb', File.dirname(__FILE__))
6
+ ))
7
+
8
+ def self.wrap(fn, opts = {})
9
+ r = Lyp::Resolver.new(fn).resolve_package_dependencies
10
+
11
+ # copy current_package_dir option
12
+ r[:current_package_dir] = opts[:current_package_dir]
13
+
14
+ if !r[:package_dirs].empty? || opts[:force_wrap]
15
+ FileUtils.mkdir_p("#{$TMP_ROOT}/wrappers")
16
+ fn = "#{$TMP_ROOT}/wrappers/#{File.basename(fn)}"
17
+
18
+ File.open(fn, 'w+') {|f| f << WRAPPER_TEMPLATE.render(r)}
19
+ end
20
+ fn
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lyp-win
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Sharon Rosner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.7.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-progressbar
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.7.5
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.7.5
53
+ - !ruby/object:Gem::Dependency
54
+ name: thor
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.19'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.19.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.19'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.19.1
73
+ description: Lyp is a tool for managing lilypond versions and lilypond packages
74
+ email: ciconia@gmail.com
75
+ executables:
76
+ - lyp
77
+ - lilypond
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - LICENSE
82
+ - README.md
83
+ - bin/install_release.sh
84
+ - bin/lilypond
85
+ - bin/lyp
86
+ - bin/release_wrapper_lilypond.sh
87
+ - bin/release_wrapper_lyp.sh
88
+ - lib/lyp.rb
89
+ - lib/lyp/base.rb
90
+ - lib/lyp/cli.rb
91
+ - lib/lyp/etc/font.scm
92
+ - lib/lyp/etc/lyp.ly
93
+ - lib/lyp/git_based_rugged.rb
94
+ - lib/lyp/lilypond.rb
95
+ - lib/lyp/package.rb
96
+ - lib/lyp/resolver.rb
97
+ - lib/lyp/settings.rb
98
+ - lib/lyp/system.rb
99
+ - lib/lyp/template.rb
100
+ - lib/lyp/templates/deps_wrapper.rb
101
+ - lib/lyp/version.rb
102
+ - lib/lyp/windows.rb
103
+ - lib/lyp/wrapper.rb
104
+ homepage: http://github.com/noteflakes/lyp
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Lyp is a package manager for lilypond
128
+ test_files: []