X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Flilypond-book.py;h=41df22da59ee4aafe1547f2159dd15f32f1925e7;hb=820bbcbc38981f5a1866f291cdf40042ea686db0;hp=9e5777284982a924aac8f74db7e76b22cb0e81f7;hpb=08560a1b8076630c4fc6cb9b902614d8b74fd6fc;p=lilypond.git diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 9e57772849..41df22da59 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -96,13 +96,12 @@ def exit (i): else: sys.exit (i) -def identify (): - ly.encoded_write (sys.stdout, '%s (GNU LilyPond) %s\n' % (ly.program_name, ly.program_version)) - progress = ly.progress warning = ly.warning error = ly.error +def identify (): + progress('%s (GNU LilyPond) %s' % (ly.program_name, ly.program_version)) def warranty (): identify () @@ -143,7 +142,7 @@ def get_option_parser (): p.add_option ("-I", '--include', help=_ ("add DIR to include path"), metavar=_ ("DIR"), action='append', dest='include_path', - default=[os.path.abspath (os.getcwd ())]) + default=[]) p.add_option ('--info-images-dir', help=_ ("format Texinfo output so that Info will " @@ -609,6 +608,22 @@ def do_file (input_filename, included=False): progress (_ ("Removing `%s'") % output_filename) raise BookSnippet.CompileError +def inverse_relpath (path, relpath): + """Given two paths, the second relative to the first, + return the first path relative to the second.""" + if os.path.isabs (relpath): + return os.path.abspath (path) + relparts = [''] + parts = os.path.normpath (path).split (os.path.sep) + for part in os.path.normpath (relpath).split (os.path.sep): + if part == '..': + relparts.append (parts[-1]) + parts.pop () + else: + relparts.append ('..') + parts.append (part) + return os.path.sep.join (relparts[::-1]) + def do_options (): global global_options @@ -616,8 +631,15 @@ def do_options (): (global_options, args) = opt_parser.parse_args () global_options.information = {'program_version': ly.program_version, 'program_name': ly.program_name } + global_options.original_dir = original_dir + + if global_options.lily_output_dir: + global_options.lily_output_dir = os.path.expanduser (global_options.lily_output_dir) + global_options.include_path.insert (0, inverse_relpath (original_dir, global_options.lily_output_dir)) - global_options.include_path = map (os.path.abspath, global_options.include_path) + if global_options.output_dir: + global_options.output_dir = os.path.expanduser (global_options.output_dir) + global_options.include_path.insert (0, inverse_relpath (original_dir, global_options.output_dir)) # Load the python packages (containing e.g. custom formatter classes) # passed on the command line @@ -667,7 +689,7 @@ def main (): if global_options.lily_output_dir: # This must be first, so lilypond prefers to read .ly # files in the other lybookdb dir. - includes = [os.path.abspath(global_options.lily_output_dir)] + includes + includes = [global_options.lily_output_dir] + includes global_options.process_cmd += ' '.join ([' -I %s' % ly.mkarg (p) for p in includes]) @@ -713,7 +735,7 @@ def main (): base_file_name + global_options.formatter.default_extension) os.chdir (original_dir) - file (dep_file, 'w').write ('%s: %s' + file (dep_file, 'w').write ('%s: %s\n' % (final_output_file, ' '.join (inputs))) if __name__ == '__main__':