OLD | NEW |
1 #!@TARGET_PYTHON@ | 1 #!@TARGET_PYTHON@ |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # This file is part of LilyPond, the GNU music typesetter. | 4 # This file is part of LilyPond, the GNU music typesetter. |
5 # | 5 # |
6 # LilyPond is free software: you can redistribute it and/or modify | 6 # LilyPond is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License as published by | 7 # it under the terms of the GNU General Public License as published by |
8 # the Free Software Foundation, either version 3 of the License, or | 8 # the Free Software Foundation, either version 3 of the License, or |
9 # (at your option) any later version. | 9 # (at your option) any later version. |
10 # | 10 # |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 import codecs | 48 import codecs |
49 import glob | 49 import glob |
50 import os | 50 import os |
51 import re | 51 import re |
52 import stat | 52 import stat |
53 import sys | 53 import sys |
54 import tempfile | 54 import tempfile |
55 import imp | 55 import imp |
56 from optparse import OptionGroup | 56 from optparse import OptionGroup |
| 57 from functools import reduce |
57 | 58 |
58 | 59 |
59 """ | 60 """ |
60 @relocate-preamble@ | 61 @relocate-preamble@ |
61 """ | 62 """ |
62 | 63 |
63 import lilylib as ly | 64 import lilylib as ly |
64 import fontextract | 65 import fontextract |
65 import langdefs | 66 import langdefs |
66 global _;_=ly._ | 67 global _;_=ly._ |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 """NB - ignore_error is deliberately set to the same value | 388 """NB - ignore_error is deliberately set to the same value |
388 as redirect_output - this is not a typo.""" | 389 as redirect_output - this is not a typo.""" |
389 retval = ly.system(cmd, | 390 retval = ly.system(cmd, |
390 be_verbose=ly.is_verbose (), | 391 be_verbose=ly.is_verbose (), |
391 redirect_output=global_options.redirect_output, | 392 redirect_output=global_options.redirect_output, |
392 log_file=logfile, | 393 log_file=logfile, |
393 progress_p=1, | 394 progress_p=1, |
394 ignore_error=global_options.redirect_output) | 395 ignore_error=global_options.redirect_output) |
395 if retval != 0: | 396 if retval != 0: |
396 print ("Error trapped by lilypond-book") | 397 print ("Error trapped by lilypond-book") |
397 print ("\nPlease see " + logfile + ".log\n") | 398 print(("\nPlease see " + logfile + ".log\n")) |
398 sys.exit(1) | 399 sys.exit(1) |
399 | 400 |
400 os.chdir (current) | 401 os.chdir (current) |
401 | 402 |
402 | 403 |
403 def process_snippets (cmd, snippets, | 404 def process_snippets (cmd, snippets, |
404 formatter, lily_output_dir): | 405 formatter, lily_output_dir): |
405 """Run cmd on all of the .ly files from snippets.""" | 406 """Run cmd on all of the .ly files from snippets.""" |
406 | 407 |
407 if not snippets: | 408 if not snippets: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 input_base = os.path.basename ( | 562 input_base = os.path.basename ( |
562 os.path.splitext (input_filename)[0]) | 563 os.path.splitext (input_filename)[0]) |
563 | 564 |
564 # don't complain when global_options.output_dir is existing | 565 # don't complain when global_options.output_dir is existing |
565 if not global_options.output_dir: | 566 if not global_options.output_dir: |
566 global_options.output_dir = os.getcwd() | 567 global_options.output_dir = os.getcwd() |
567 else: | 568 else: |
568 global_options.output_dir = os.path.abspath(global_options.output_dir) | 569 global_options.output_dir = os.path.abspath(global_options.output_dir) |
569 | 570 |
570 if not os.path.isdir (global_options.output_dir): | 571 if not os.path.isdir (global_options.output_dir): |
571 os.mkdir (global_options.output_dir, 0777) | 572 os.mkdir (global_options.output_dir, 0o777) |
572 os.chdir (global_options.output_dir) | 573 os.chdir (global_options.output_dir) |
573 | 574 |
574 output_filename = os.path.join(global_options.output_dir, | 575 output_filename = os.path.join(global_options.output_dir, |
575 input_base + global_options.formatter.default
_extension) | 576 input_base + global_options.formatter.default
_extension) |
576 if (os.path.exists (input_filename) | 577 if (os.path.exists (input_filename) |
577 and os.path.exists (output_filename) | 578 and os.path.exists (output_filename) |
578 and samefile (output_filename, input_absname)): | 579 and samefile (output_filename, input_absname)): |
579 error ( | 580 error ( |
580 _ ("Output would overwrite input file; use --output.")) | 581 _ ("Output would overwrite input file; use --output.")) |
581 exit (2) | 582 exit (2) |
(...skipping 21 matching lines...) Expand all Loading... |
603 write_if_updated (output_filename, | 604 write_if_updated (output_filename, |
604 [s.replacement_text () | 605 [s.replacement_text () |
605 for s in chunks]) | 606 for s in chunks]) |
606 | 607 |
607 def process_include (snippet): | 608 def process_include (snippet): |
608 os.chdir (original_dir) | 609 os.chdir (original_dir) |
609 name = snippet.substring ('filename') | 610 name = snippet.substring ('filename') |
610 progress (_ ("Processing include: %s") % name) | 611 progress (_ ("Processing include: %s") % name) |
611 return do_file (name, included=True) | 612 return do_file (name, included=True) |
612 | 613 |
613 include_chunks = map (process_include, | 614 include_chunks = list(map (process_include, |
614 filter (lambda x: isinstance (x, BookSnippet.Inclu
deSnippet), | 615 [x for x in chunks if isinstance (x, BookSnippet.I
ncludeSnippet)])) |
615 chunks)) | |
616 | 616 |
617 return chunks + reduce (lambda x, y: x + y, include_chunks, []) | 617 return chunks + reduce (lambda x, y: x + y, include_chunks, []) |
618 | 618 |
619 except BookSnippet.CompileError: | 619 except BookSnippet.CompileError: |
620 os.chdir (original_dir) | 620 os.chdir (original_dir) |
621 progress (_ ("Removing `%s'") % output_filename) | 621 progress (_ ("Removing `%s'") % output_filename) |
622 raise BookSnippet.CompileError | 622 raise BookSnippet.CompileError |
623 | 623 |
624 def adjust_include_path (path, outpath): | 624 def adjust_include_path (path, outpath): |
625 """Rewrite an include path relative to the dir where lilypond is launched. | 625 """Rewrite an include path relative to the dir where lilypond is launched. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 warranty () | 685 warranty () |
686 exit (0) | 686 exit (0) |
687 if not args or len (args) > 1: | 687 if not args or len (args) > 1: |
688 opt_parser.print_help () | 688 opt_parser.print_help () |
689 exit (2) | 689 exit (2) |
690 | 690 |
691 return args | 691 return args |
692 | 692 |
693 def main (): | 693 def main (): |
694 # FIXME: 85 lines of `main' macramee?? | 694 # FIXME: 85 lines of `main' macramee?? |
695 if (os.environ.has_key ("LILYPOND_BOOK_LOGLEVEL")): | 695 if ("LILYPOND_BOOK_LOGLEVEL" in os.environ): |
696 ly.set_loglevel (os.environ["LILYPOND_BOOK_LOGLEVEL"]) | 696 ly.set_loglevel (os.environ["LILYPOND_BOOK_LOGLEVEL"]) |
697 files = do_options () | 697 files = do_options () |
698 | 698 |
699 basename = os.path.splitext (files[0])[0] | 699 basename = os.path.splitext (files[0])[0] |
700 basename = os.path.split (basename)[1] | 700 basename = os.path.split (basename)[1] |
701 | 701 |
702 if global_options.format: | 702 if global_options.format: |
703 # Retrieve the formatter for the given format | 703 # Retrieve the formatter for the given format |
704 for formatter in BookBase.all_formats: | 704 for formatter in BookBase.all_formats: |
705 if formatter.can_handle_format (global_options.format): | 705 if formatter.can_handle_format (global_options.format): |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 dep_file = os.path.join (global_options.output_dir, base_file_name + '.dep') | 761 dep_file = os.path.join (global_options.output_dir, base_file_name + '.dep') |
762 final_output_file = os.path.join (relative_output_dir, | 762 final_output_file = os.path.join (relative_output_dir, |
763 base_file_name + global_options.formatter.default_extension
) | 763 base_file_name + global_options.formatter.default_extension
) |
764 | 764 |
765 os.chdir (original_dir) | 765 os.chdir (original_dir) |
766 open (dep_file, 'w').write ('%s: %s\n' | 766 open (dep_file, 'w').write ('%s: %s\n' |
767 % (final_output_file, ' '.join (inputs))) | 767 % (final_output_file, ' '.join (inputs))) |
768 | 768 |
769 if __name__ == '__main__': | 769 if __name__ == '__main__': |
770 main () | 770 main () |
OLD | NEW |