lyp 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b51e26364d2db0d4433ba21cdff532f05afa846c
4
- data.tar.gz: 0305882ebc3ec0aee3a484f4bbea47cc39c6ccc1
3
+ metadata.gz: 7da1232df992cc03f2e059a9bc2b5f0c62ce567e
4
+ data.tar.gz: 3d39b6fa1cde695641532f14f9bdef006c891dfb
5
5
  SHA512:
6
- metadata.gz: 27f6770fa7d43f96e399c951cac4ef3afd45b952d01857113608bf95a8e62c3a05e2fa8530596255b28d3f38a7b45804808096521905439a800fede2b244019f
7
- data.tar.gz: 318b2daf11c8507e082ee493b91a4f5d79f0b9c6bc55048b4db2a07be36a6ac6489bf347cd05de71aca4e0b6b374c66f143349a87c75a597913074d155631c89
6
+ metadata.gz: 1a52d51cab0e4055d0880fed425c5227c5548fc173acedbd17b9b847b375bcb39ca56f728853db9b91d50d3996609199fd630ab7fce548adb2268503fa2d9f02
7
+ data.tar.gz: 91ef6fa48d124b7ea7c7d6c6cb971d825e9246bcf50096524d82b26fce7e091788bd4c43327e8fe4c7c4de96c0c8fe3649390112ba6fc00037c92d46ef1b6048
data/bin/lilypond CHANGED
@@ -19,10 +19,12 @@ OVERRIDING_LILYPOND_SWITCHES = %w{
19
19
  scheme-sandbox
20
20
  }
21
21
  LILYPOND_HELP_SWITCHES = %w{
22
- -h --help
22
+ -h --help -dhelp
23
23
  }
24
+
24
25
  LYP_LY_HELP = <<EOF
25
26
  Lyp-provided options:
27
+ -c, --cropped crop output (requires setting 0 margins)
26
28
  -E, --env use version specified in $LILYPOND_VERSION
27
29
  -n, --install install the specified version if not found
28
30
  -O, --open open the target file after compilation
@@ -39,7 +41,7 @@ when nil, *OVERRIDING_LILYPOND_SWITCHES
39
41
  when *LILYPOND_HELP_SWITCHES
40
42
  STDERR.puts "Lyp version #{Lyp::VERSION}"
41
43
  puts `#{$lilypond_path} #{$argv.join(' ')}`
42
- puts LYP_LY_HELP
44
+ puts LYP_LY_HELP unless $argv.first == '-dhelp'
43
45
  else
44
46
  begin
45
47
  Lyp::Lilypond.compile($argv, $options)
data/lib/lyp/cli.rb CHANGED
@@ -46,30 +46,30 @@ class Lyp::CLI < Thor
46
46
  map "-v" => :version
47
47
  check_unknown_options! :except => :compile
48
48
  class_option :verbose, aliases: '-V', :type => :boolean, desc: 'show verbose output'
49
-
49
+
50
50
  desc "version", "show Lyp version"
51
51
  def version
52
52
  $stderr.puts "Lyp #{Lyp::VERSION}"
53
53
  end
54
-
54
+
55
55
  desc "search [PATTERN|lilypond]", "List available packages matching PATTERN or versions of lilypond"
56
56
  def search(pattern = '')
57
57
  $cmd_options = options
58
58
 
59
59
  pattern =~ Lyp::PACKAGE_RE
60
60
  package, version = $1, $2
61
-
61
+
62
62
  if package == 'lilypond'
63
63
  search_lilypond(version)
64
64
  else
65
65
  search_package(pattern)
66
66
  end
67
67
  end
68
-
68
+
69
69
  no_commands do
70
70
  def search_lilypond(version)
71
71
  versions = Lyp::Lilypond.search(version)
72
-
72
+
73
73
  if versions.empty?
74
74
  puts "\nNo available versions of lilypond@#{version} found\n\n"
75
75
  else
@@ -81,9 +81,9 @@ class Lyp::CLI < Thor
81
81
  puts "\n * Currently installed\n\n"
82
82
  end
83
83
  end
84
-
84
+
85
85
  PACKAGE_FMT = "%-16s => %s"
86
-
86
+
87
87
  def search_package(pattern)
88
88
  packages = Lyp::Package.list_lyp_index(pattern)
89
89
  if packages.empty?
@@ -109,7 +109,7 @@ class Lyp::CLI < Thor
109
109
  Lyp::System.test_installed_status!
110
110
  Lyp::Lilypond.compile(argv, opts)
111
111
  end
112
-
112
+
113
113
  desc "test [<option>...] [.|PATTERN]", "Runs package tests on installed packages or local directory"
114
114
  method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of lilypond if not present'
115
115
  method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
@@ -124,7 +124,7 @@ class Lyp::CLI < Thor
124
124
  end
125
125
  options[:use] = ENV['LILYPOND_VERSION']
126
126
  end
127
-
127
+
128
128
  if options[:use]
129
129
  if options[:install]
130
130
  Lyp::Lilypond.install_if_missing(options[:use], no_version_test: true)
@@ -134,7 +134,7 @@ class Lyp::CLI < Thor
134
134
 
135
135
  # check lilypond default / current settings
136
136
  Lyp::Lilypond.check_lilypond!
137
-
137
+
138
138
  $stderr.puts "Lyp #{Lyp::VERSION}"
139
139
  case args
140
140
  when ['.']
@@ -151,7 +151,7 @@ class Lyp::CLI < Thor
151
151
  $cmd_options = options
152
152
 
153
153
  raise "No package specified" if args.empty?
154
-
154
+
155
155
  args.each do |package|
156
156
  case package
157
157
  when 'self'
@@ -187,7 +187,7 @@ class Lyp::CLI < Thor
187
187
  end
188
188
  end
189
189
  end
190
-
190
+
191
191
  desc "use [lilypond@]<VERSION>", "Switch version of lilypond"
192
192
  method_option :default, aliases: '-d', type: :boolean, desc: 'Set default lilypond version'
193
193
  def use(version)
@@ -198,7 +198,7 @@ class Lyp::CLI < Thor
198
198
  if version =~ Lyp::LILYPOND_RE
199
199
  version = $1
200
200
  end
201
-
201
+
202
202
  lilypond = Lyp::Lilypond.use(version, options)
203
203
  puts "Using lilypond version #{lilypond[:version]}"
204
204
  end
@@ -227,11 +227,11 @@ class Lyp::CLI < Thor
227
227
  return puts "\nNo packages are currently installed\n\n"
228
228
  end
229
229
  end
230
-
230
+
231
231
  by_package = list.inject({}) do |m, p|
232
232
  p =~ Lyp::PACKAGE_RE; (m[$1] ||= []) << $2; m
233
233
  end
234
-
234
+
235
235
  puts "\nInstalled packages:\n\n"
236
236
  by_package.keys.sort.each do |p|
237
237
  puts " #{p} => (#{by_package[p].sort.join(', ')})"
@@ -239,7 +239,7 @@ class Lyp::CLI < Thor
239
239
  puts "\n\n"
240
240
  end
241
241
  end
242
-
242
+
243
243
  desc "which [PATTERN|lilypond]", "List locations of installed packages matching PATTERN or versions of lilypond"
244
244
  def which(pattern = nil)
245
245
  $cmd_options = options
@@ -257,37 +257,46 @@ class Lyp::CLI < Thor
257
257
  Lyp::Package.which(args.first).each {|p| puts p}
258
258
  end
259
259
  end
260
-
260
+
261
261
  desc "deps FILE", "Lists dependencies found in user's files"
262
262
  def deps(fn)
263
263
  $cmd_options = options
264
264
 
265
- resolver = Lyp::Resolver.new(fn)
266
- tree = resolver.get_dependency_tree(ignore_missing: true)
267
- tree[:dependencies].each do |package, leaf|
268
- versions = leaf[:versions].keys.map {|k| k =~ Lyp::PACKAGE_RE; $2 }.sort
265
+ resolver = Lyp::DependencyResolver.new(fn)
266
+ tree = resolver.compile_dependency_tree(ignore_missing: true)
267
+ tree.dependencies.each do |package, spec|
268
+ versions = spec.versions.keys.map {|k| k =~ Lyp::PACKAGE_RE; $2 }.sort
269
269
  if versions.empty?
270
- puts " #{leaf[:clause]} => (no local version found)"
270
+ puts " #{spec.clause} => (no local version found)"
271
271
  else
272
- puts " #{leaf[:clause]} => #{versions.join(', ')}"
272
+ puts " #{spec.clause} => #{versions.join(', ')}"
273
273
  end
274
274
  end
275
275
  end
276
-
276
+
277
277
  desc "resolve FILE", "Resolves and installs missing dependencies found in user's files"
278
278
  method_option :all, aliases: '-a', type: :boolean, desc: 'Install all found dependencies'
279
279
  def resolve(fn)
280
280
  $cmd_options = options
281
281
 
282
- resolver = Lyp::Resolver.new(fn)
283
- tree = resolver.get_dependency_tree(ignore_missing: true)
284
- tree[:dependencies].each do |package, leaf|
285
- if options[:all] || leaf[:versions].empty?
286
- Lyp::Package.install(leaf[:clause])
282
+ resolver = Lyp::DependencyResolver.new(fn)
283
+ tree = resolver.compile_dependency_tree(ignore_missing: true)
284
+ tree.dependencies.each do |package, spec|
285
+ if options[:all] || spec.versions.empty?
286
+ Lyp::Package.install(spec.clause)
287
287
  end
288
288
  end
289
289
  end
290
-
290
+
291
+ desc "cleanup", "Cleanup temporary files"
292
+ def cleanup
293
+ $stderr.puts "Lyp #{Lyp::VERSION}"
294
+ Dir["#{Lyp::TMP_ROOT}/*"].each do |fn|
295
+ puts "Cleaning up #{fn}"
296
+ FileUtils.rm_rf(fn)
297
+ end
298
+ end
299
+
291
300
  def self.run
292
301
  start(ARGV)
293
302
  rescue => e
@@ -296,4 +305,3 @@ class Lyp::CLI < Thor
296
305
  exit(1)
297
306
  end
298
307
  end
299
-
data/lib/lyp/lilypond.rb CHANGED
@@ -32,6 +32,8 @@ module Lyp::Lilypond
32
32
  options[:install] = true
33
33
  when '-O', '--open'
34
34
  options[:open] = true
35
+ when '-c', '--cropped'
36
+ argv_clean += ['-dbackend=eps', '-daux-files=#f']
35
37
  else
36
38
  argv_clean << arg
37
39
  end
@@ -39,7 +41,7 @@ module Lyp::Lilypond
39
41
 
40
42
  [options, argv_clean]
41
43
  end
42
-
44
+
43
45
  def select_lilypond_version(opts)
44
46
  if opts[:use_version]
45
47
  if opts[:install]
@@ -58,19 +60,19 @@ module Lyp::Lilypond
58
60
  STDERR.puts e.message
59
61
  exit 1
60
62
  end
61
-
63
+
62
64
  def compile(argv, opts = {})
63
65
  unless argv.last == '-'
64
66
  fn = Lyp.wrap(argv.pop, opts)
65
67
  argv << fn
66
68
  end
67
-
69
+
68
70
  invoke(argv, opts)
69
71
  end
70
-
72
+
71
73
  def invoke(argv, opts = {})
72
74
  lilypond = current_lilypond
73
-
75
+
74
76
  case opts[:mode]
75
77
  when :system
76
78
  system("#{lilypond} #{argv.join(" ")}")
@@ -78,30 +80,30 @@ module Lyp::Lilypond
78
80
  Kernel.exec(lilypond, *argv)
79
81
  end
80
82
  end
81
-
83
+
82
84
  def default_lilypond
83
85
  Lyp::Settings['lilypond/default']
84
86
  end
85
-
87
+
86
88
  def set_default_lilypond(path)
87
89
  Lyp::Settings['lilypond/default'] = path
88
90
  end
89
-
90
- # The current lilypond path is stored in a temporary file named by the
91
+
92
+ # The current lilypond path is stored in a temporary file named by the
91
93
  # session id. Thus we can persist the version selected by the user
92
94
  def current_lilypond
93
95
  return forced_lilypond if @forced_version
94
-
96
+
95
97
  settings = get_session_settings
96
98
 
97
99
  if !settings[:current]
98
100
  settings[:current] = default_lilypond
99
101
  set_session_settings(settings)
100
102
  end
101
-
103
+
102
104
  settings[:current]
103
105
  end
104
-
106
+
105
107
  def current_lilypond_version
106
108
  path = current_lilypond
107
109
  version = File.basename(File.expand_path("#{File.dirname(path)}/../.."))
@@ -114,13 +116,13 @@ module Lyp::Lilypond
114
116
  end
115
117
  version
116
118
  end
117
-
119
+
118
120
  def set_current_lilypond(path)
119
121
  settings = get_session_settings
120
122
  settings[:current] = path
121
123
  set_session_settings(settings)
122
124
  end
123
-
125
+
124
126
  def forced_lilypond
125
127
  lilypond = filter_installed_list(@forced_version)[0]
126
128
  if lilypond
@@ -129,32 +131,32 @@ module Lyp::Lilypond
129
131
  raise "No installed version found matching '#{@forced_version}'"
130
132
  end
131
133
  end
132
-
134
+
133
135
  def force_env_version!
134
136
  @forced_version = ENV['LILYPOND_VERSION']
135
137
  unless @forced_version
136
138
  raise "LILYPOND_VERSION not set"
137
139
  end
138
140
  end
139
-
141
+
140
142
  def force_version!(version)
141
143
  @forced_version = version
142
144
  end
143
-
145
+
144
146
  attr_reader :forced_version
145
-
147
+
146
148
  def check_lilypond!
147
149
  path = default_lilypond
148
150
  select_default_lilypond! unless path && path =~ /lilypond$/
149
-
151
+
150
152
  path = current_lilypond
151
153
  set_current_lilypond(default_lilypond) unless path && path =~ /lilypond$/
152
154
  end
153
-
155
+
154
156
  def valid_lilypond?(path)
155
157
  (File.file?(path) rescue nil) && (`#{path} -v` =~ /^GNU LilyPond/)
156
158
  end
157
-
159
+
158
160
  def select_default_lilypond!
159
161
  latest = system_lilyponds.sort(&CMP_VERSION).last || lyp_lilyponds.sort(&CMP_VERSION).last
160
162
  if latest
@@ -164,34 +166,34 @@ module Lyp::Lilypond
164
166
  raise Lyp::LILYPOND_NOT_FOUND_MSG
165
167
  end
166
168
  end
167
-
169
+
168
170
  def get_session_settings
169
171
  YAML.load(IO.read(session_settings_filename)) rescue {}
170
172
  end
171
-
173
+
172
174
  def set_session_settings(settings)
173
175
  File.open(session_settings_filename, 'w+') do |f|
174
176
  f << YAML.dump(settings)
175
177
  end
176
178
  end
177
-
179
+
178
180
  def session_settings_filename
179
181
  "#{Lyp::TMP_ROOT}/session.#{Process.getsid}.yml"
180
182
  end
181
-
183
+
182
184
  CMP_VERSION = proc do |x, y|
183
185
  Gem::Version.new(x[:version]) <=> Gem::Version.new(y[:version])
184
186
  end
185
-
187
+
186
188
  def filter_installed_list(version_specifier)
187
189
  list = (system_lilyponds + lyp_lilyponds).sort!(&CMP_VERSION)
188
190
  list.select {|l| version_match(l[:version], version_specifier, list)}
189
191
  end
190
-
192
+
191
193
  def list(opts = {})
192
194
  system_list = opts[:lyp_only] ? [] : system_lilyponds
193
195
  lyp_list = opts[:system_only] ? [] : lyp_lilyponds
194
-
196
+
195
197
  default = default_lilypond
196
198
  unless default
197
199
  latest = system_list.sort(&CMP_VERSION).last || lyp_list.sort(&CMP_VERSION).last
@@ -201,24 +203,24 @@ module Lyp::Lilypond
201
203
  end
202
204
  end
203
205
  current = current_lilypond
204
-
206
+
205
207
  lilyponds = system_list + lyp_list
206
208
 
207
209
  lilyponds.each do |l|
208
210
  l[:default] = l[:path] == default
209
211
  l[:current] = l[:path] == current
210
212
  end
211
-
213
+
212
214
  # sort by version
213
215
  lilyponds.sort!(&CMP_VERSION)
214
216
  end
215
-
217
+
216
218
  def lyp_lilyponds
217
219
  list = []
218
-
220
+
219
221
  Dir["#{Lyp.lilyponds_dir}/*"].each do |path|
220
222
  next unless File.directory?(path) && File.basename(path) =~ /^[\d\.]+$/
221
-
223
+
222
224
  root_path = path
223
225
  version = File.basename(path)
224
226
  path = File.join(path, "bin/lilypond")
@@ -229,14 +231,14 @@ module Lyp::Lilypond
229
231
  version: version
230
232
  }
231
233
  end
232
-
234
+
233
235
  list
234
236
  end
235
-
237
+
236
238
  def system_lilyponds
237
239
  list = get_system_lilyponds_paths
238
240
  return list if list.empty?
239
-
241
+
240
242
  list.inject([]) do |m, path|
241
243
  begin
242
244
  resp = `#{path} #{Lyp::DETECT_SYSTEM_LILYPOND_FILENAME} 2>/dev/null`
@@ -257,32 +259,32 @@ module Lyp::Lilypond
257
259
  m
258
260
  end
259
261
  end
260
-
262
+
261
263
  def get_system_lilyponds_paths
262
264
  self_bin_dir = File.dirname(File.expand_path($0))
263
-
265
+
264
266
  list = `which -a lilypond`
265
267
  list = list.lines.map {|f| f.chomp}.uniq.reject do |l|
266
268
  dir = File.dirname(l)
267
269
  (dir == Gem.bindir) || (dir == Lyp::LYP_BIN_DIRECTORY) || (dir == self_bin_dir)
268
270
  end
269
271
  end
270
-
272
+
271
273
  BASE_URL = "http://download.linuxaudio.org/lilypond/binaries"
272
-
274
+
273
275
  # Returns a list of versions of lilyponds available for download
274
276
  def search(version_specifier = nil)
275
277
  require 'open-uri'
276
278
 
277
279
  platform = detect_lilypond_platform
278
280
  url = "#{BASE_URL}/#{platform}/"
279
-
281
+
280
282
  versions = []
281
-
282
- open(url).read.scan(/a href=\"lilypond-([0-9\.]+)[^>]+\"/) do |m|
283
+
284
+ open(url).read.scan(/a href=\"lilypond-([0-9\.]+)[^>]+\"/) do |m|
283
285
  versions << $1
284
286
  end
285
-
287
+
286
288
  installed_versions = list.map {|l| l[:version]}
287
289
  versions.select! {|v| version_match(v, version_specifier, versions)}
288
290
  versions.map do |v|
@@ -292,7 +294,7 @@ module Lyp::Lilypond
292
294
  }
293
295
  end
294
296
  end
295
-
297
+
296
298
  def version_match(version, specifier, all_versions)
297
299
  case specifier
298
300
  when 'latest'
@@ -305,29 +307,29 @@ module Lyp::Lilypond
305
307
  Gem::Requirement.new(specifier) =~ Gem::Version.new(version)
306
308
  end
307
309
  end
308
-
310
+
309
311
  def latest_stable_version
310
312
  search.reverse.find {|l| Gem::Version.new(l[:version]).segments[1].even?}[:version]
311
313
  end
312
-
314
+
313
315
  def latest_unstable_version
314
316
  search.reverse.find {|l| Gem::Version.new(l[:version]).segments[1].odd?}[:version]
315
317
  end
316
-
318
+
317
319
  def latest_version
318
320
  search.last[:version]
319
321
  end
320
-
322
+
321
323
  def install_if_missing(version_specifier, opts = {})
322
324
  if filter_installed_list(version_specifier).empty?
323
325
  install(version_specifier, opts)
324
326
  end
325
327
  end
326
-
328
+
327
329
  def install(version_specifier, opts = {})
328
330
  version = detect_version_from_specifier(version_specifier)
329
331
  raise "No version found matching specifier #{version_specifier}" unless version
330
-
332
+
331
333
  STDERR.puts "Installing version #{version}" unless opts[:silent]
332
334
  install_version(version, opts)
333
335
 
@@ -335,11 +337,11 @@ module Lyp::Lilypond
335
337
  set_current_lilypond(lilypond_path)
336
338
  set_default_lilypond(lilypond_path) if opts[:default]
337
339
  end
338
-
340
+
339
341
  def lyp_lilypond_path(version)
340
342
  "#{Lyp.lilyponds_dir}/#{version}/bin/lilypond"
341
343
  end
342
-
344
+
343
345
  def detect_version_from_specifier(version_specifier)
344
346
  case version_specifier
345
347
  when /^\d/
@@ -360,7 +362,7 @@ module Lyp::Lilypond
360
362
  end
361
363
  end
362
364
  end
363
-
365
+
364
366
  def detect_lilypond_platform
365
367
  case RUBY_PLATFORM
366
368
  when /x86_64-darwin/
@@ -377,7 +379,7 @@ module Lyp::Lilypond
377
379
  "mingw"
378
380
  end
379
381
  end
380
-
382
+
381
383
  def install_version(version, opts)
382
384
  platform = detect_lilypond_platform
383
385
  url = lilypond_install_url(platform, version, opts)
@@ -385,7 +387,7 @@ module Lyp::Lilypond
385
387
 
386
388
  download_lilypond(url, fn, opts) unless File.file?(fn)
387
389
  install_lilypond_files(fn, platform, version, opts)
388
-
390
+
389
391
  patch_font_scm(version)
390
392
  copy_fonts_from_all_packages(version, opts)
391
393
  end
@@ -400,15 +402,15 @@ module Lyp::Lilypond
400
402
  ".exe"
401
403
  end
402
404
  filename = "lilypond-#{version}-1.#{platform}"
403
-
405
+
404
406
  "#{BASE_URL}/#{platform}/#{filename}#{ext}"
405
407
  end
406
-
408
+
407
409
  def temp_install_filename(url)
408
410
  u = URI(url)
409
411
  "#{Lyp::TMP_ROOT}/#{File.basename(u.path)}"
410
412
  end
411
-
413
+
412
414
  def download_lilypond(url, fn, opts)
413
415
  require 'httpclient'
414
416
 
@@ -435,7 +437,7 @@ module Lyp::Lilypond
435
437
  end
436
438
  pbar.finish unless opts[:silent]
437
439
  end
438
-
440
+
439
441
  def install_lilypond_files(fn, platform, version, opts)
440
442
  tmp_target = "#{Lyp::TMP_ROOT}/lilypond-#{version}"
441
443
  FileUtils.mkdir_p(tmp_target)
@@ -448,19 +450,19 @@ module Lyp::Lilypond
448
450
  when /mingw/
449
451
  install_lilypond_files_windows(fn, tmp_target, platform, version, opts)
450
452
  end
451
-
453
+
452
454
  ensure
453
455
  FileUtils.rm_rf(tmp_target)
454
456
  end
455
-
457
+
456
458
  def install_lilypond_files_osx(fn, target, platform, version, opts)
457
459
  STDERR.puts "Extracting..." unless opts[:silent]
458
460
  exec "tar -xjf #{fn} -C #{target}"
459
-
461
+
460
462
  copy_lilypond_files("#{target}/LilyPond.app/Contents/Resources", version, opts)
461
463
  end
462
-
463
- # Since linux versions are distributed as sh archives, we need first to
464
+
465
+ # Since linux versions are distributed as sh archives, we need first to
464
466
  # extract the sh archive, then extract the resulting tar file
465
467
  def install_lilypond_files_linux(fn, target, platform, version, opts)
466
468
  STDERR.puts "Extracting..." unless opts[:silent]
@@ -468,30 +470,30 @@ module Lyp::Lilypond
468
470
  # create temp directory in which to extract .sh file
469
471
  tmp_dir = "#{Lyp::TMP_ROOT}/#{Time.now.to_f}"
470
472
  FileUtils.mkdir_p(tmp_dir)
471
-
473
+
472
474
  FileUtils.cd(tmp_dir) do
473
475
  exec "sh #{fn} --tarball >/dev/null"
474
476
  end
475
-
477
+
476
478
  tmp_fn = "#{tmp_dir}/lilypond-#{version}-1.#{platform}.tar.bz2"
477
-
479
+
478
480
  exec "tar -xjf #{tmp_fn} -C #{target}"
479
-
481
+
480
482
  copy_lilypond_files("#{target}/usr", version, opts)
481
483
  ensure
482
484
  FileUtils.rm_rf(tmp_dir)
483
485
  end
484
-
486
+
485
487
  def install_lilypond_files_windows(fn, target, platform, version, opts)
486
488
  STDERR.puts "Running NSIS Installer..." unless opts[:silent]
487
-
489
+
488
490
  target_dir = File.join(Lyp.lilyponds_dir, version)
489
491
  FileUtils.mkdir_p(target_dir)
490
-
492
+
491
493
  # run installer
492
494
  cmd = "#{fn} /S /D=#{target_dir.gsub('/', '\\')}"
493
495
  `#{cmd}`
494
-
496
+
495
497
  # wait for installer to finish
496
498
  t1 = Time.now
497
499
  while !File.file?("#{target_dir}/usr/bin/lilypond.exe")
@@ -505,44 +507,44 @@ module Lyp::Lilypond
505
507
 
506
508
  def copy_lilypond_files(base_path, version, opts)
507
509
  target_dir = File.join(Lyp.lilyponds_dir, version)
508
-
510
+
509
511
  FileUtils.rm_rf(target_dir) if File.exists?(target_dir)
510
-
512
+
511
513
  # create directory for lilypond files
512
514
  FileUtils.mkdir_p(target_dir)
513
-
515
+
514
516
  # copy files
515
517
  STDERR.puts "Copying..." unless opts[:silent]
516
518
  %w{bin etc lib lib64 share var}.each do |entry|
517
519
  dir = File.join(base_path, entry)
518
520
  FileUtils.cp_r(dir, target_dir, remove_destination: true) if File.directory?(dir)
519
521
  end
520
-
522
+
521
523
  # Show lilypond versions
522
524
  STDERR.puts `#{target_dir}/bin/lilypond -v` unless opts[:silent] || opts[:no_version_test]
523
525
  rescue => e
524
526
  puts e.message
525
527
  end
526
-
528
+
527
529
  def patch_font_scm(version)
528
530
  return unless Lyp::FONT_PATCH_REQ =~ Gem::Version.new(version)
529
-
531
+
530
532
  target_fn = File.join(lyp_lilypond_share_dir(version), 'lilypond/current/scm/font.scm')
531
533
  FileUtils.cp(Lyp::FONT_PATCH_FILENAME, target_fn)
532
534
  end
533
535
 
534
536
  SYSTEM_LILYPOND_PATCH_WARNING = <<-EOF.gsub(/^\s{6}/, '').chomp
535
- The system-installed lilypond version %s needs to be patched in
537
+ The system-installed lilypond version %s needs to be patched in
536
538
  order to support custom music fonts. This operation will replace the file
537
-
539
+
538
540
  %s
539
-
540
- Would you like to overwrite this file? (y/n):
541
+
542
+ Would you like to overwrite this file? (y/n):
541
543
  EOF
542
-
544
+
543
545
  def patch_system_lilypond_font_scm(lilypond, opts)
544
546
  return false unless Lyp::FONT_PATCH_REQ =~ Gem::Version.new(lilypond[:version])
545
-
547
+
546
548
  target_fn = File.join(lilypond[:data_path], '/scm/font.scm')
547
549
  # do nothing if alredy patched
548
550
  if IO.read(target_fn) == IO.read(Lyp::FONT_PATCH_FILENAME)
@@ -551,7 +553,7 @@ module Lyp::Lilypond
551
553
 
552
554
  prompt = SYSTEM_LILYPOND_PATCH_WARNING % [lilypond[:version], target_fn]
553
555
  return unless Lyp.confirm_action(prompt)
554
-
556
+
555
557
  puts "Patching #{target_fn}:" unless opts[:silent]
556
558
  if File.writeable?(target_fn)
557
559
  FileUtils.cp(target_fn, "#{target_fn}.old")
@@ -561,38 +563,38 @@ module Lyp::Lilypond
561
563
  Lyp.sudo_cp(Lyp::FONT_PATCH_FILENAME, target_fn)
562
564
  end
563
565
  end
564
-
566
+
565
567
  def copy_fonts_from_all_packages(version, opts)
566
568
  return unless Lyp::FONT_COPY_REQ =~ Gem::Version.new(version)
567
-
569
+
568
570
  ly_fonts_dir = File.join(lyp_lilypond_share_dir(version), 'lilypond/current/fonts')
569
-
571
+
570
572
  Dir["#{Lyp.packages_dir}/**/fonts"].each do |package_fonts_dir|
571
573
 
572
574
  Dir["#{package_fonts_dir}/*.otf"].each do |fn|
573
575
  target_fn = File.join(ly_fonts_dir, 'otf', File.basename(fn))
574
576
  FileUtils.cp(fn, target_fn)
575
577
  end
576
-
578
+
577
579
  Dir["#{package_fonts_dir}/*.svg"].each do |fn|
578
580
  target_fn = File.join(ly_fonts_dir, 'svg', File.basename(fn))
579
581
  FileUtils.cp(fn, target_fn)
580
582
  end
581
-
583
+
582
584
  Dir["#{package_fonts_dir}/*.woff"].each do |fn|
583
585
  target_fn = File.join(ly_fonts_dir, 'svg', File.basename(fn))
584
586
  FileUtils.cp(fn, target_fn)
585
587
  end
586
588
  end
587
589
  end
588
-
590
+
589
591
  def lyp_lilypond_share_dir(version)
590
592
  File.join(Lyp.lilyponds_dir, version, 'share')
591
593
  end
592
-
594
+
593
595
  def use(version, opts)
594
596
  lilypond_list = list.reverse
595
-
597
+
596
598
  case version
597
599
  when 'system'
598
600
  lilypond = lilypond_list.find {|v| v[:system] }
@@ -614,17 +616,17 @@ module Lyp::Lilypond
614
616
  req = Gem::Requirement.new(version)
615
617
  lilypond = lilypond_list.find {|v| req =~ Gem::Version.new(v[:version])}
616
618
  end
617
-
619
+
618
620
  unless lilypond
619
621
  raise "Could not find a lilypond matching \"#{version}\""
620
622
  end
621
-
623
+
622
624
  set_current_lilypond(lilypond[:path])
623
625
  set_default_lilypond(lilypond[:path]) if opts[:default]
624
-
626
+
625
627
  lilypond
626
628
  end
627
-
629
+
628
630
  def uninstall(version_specifier, opts = {})
629
631
  list = list(lyp_only: true)
630
632
  if version_specifier
@@ -633,7 +635,7 @@ module Lyp::Lilypond
633
635
  # if no version is specified
634
636
  raise "No version specifier given.\nTo uninstall all versions run 'lyp uninstall lilypond -a'.\n"
635
637
  end
636
-
638
+
637
639
  if list.empty?
638
640
  if version_specifier
639
641
  raise "No lilypond found matching #{version_specifier}"
@@ -641,7 +643,7 @@ module Lyp::Lilypond
641
643
  raise "No lilypond found"
642
644
  end
643
645
  end
644
-
646
+
645
647
  list.each do |l|
646
648
  puts "Uninstalling lilypond #{l[:version]}" unless opts[:silent]
647
649
  set_current_lilypond(nil) if l[:current]
@@ -649,11 +651,11 @@ module Lyp::Lilypond
649
651
  uninstall_lilypond_version(l[:root_path])
650
652
  end
651
653
  end
652
-
654
+
653
655
  def uninstall_lilypond_version(path)
654
656
  FileUtils.rm_rf(path)
655
657
  end
656
-
658
+
657
659
  def exec(cmd, raise_on_failure = true)
658
660
  $_out = ""
659
661
  $_err = ""
@@ -669,9 +671,9 @@ module Lyp::Lilypond
669
671
  end
670
672
  success
671
673
  end
672
-
674
+
673
675
  def parse_error_msg(msg)
674
676
  (msg =~ /[^\n]+: error.+failed files: ".+"/m) ? $& : msg
675
677
  end
676
678
  end
677
- end
679
+ end