2 # lily-wins.py -- LilyPond command for .ly on Windows
9 print 'Usage [-h,--help] lily-wins LY-FILE'
11 # print debugging stuff for now
15 def read_pipe (command):
16 debug ('command:' + command)
17 s = os.popen (command).read ()
18 if s and s[-1] == '\n':
23 debug ('command:' + command)
26 def strip_extension (f, ext):
27 (p, e) = os.path.splitext (f)
34 if len (sys.argv) != 2 \
35 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
39 native_file = sys.argv[1]
41 file = read_pipe ("/usr/bin/cygpath -au '%(native_file)s'" % vars ())
47 dir = os.path.dirname (file)
50 base = os.path.basename (file)
51 stem = strip_extension (base, '.ly')
54 native_base = read_pipe ('/usr/bin/cygpath -aw %(dir)s/%(stem)s' % vars ())
56 native_base = '%(dir)s/%(stem)s' % vars ()
58 pdfname = read_pipe ('/usr/bin/regtool get /root/.pdf/')
59 pdfopencommand = read_pipe ("/usr/bin/regtool get '/root/%(pdfname)s/shell/open/command/'" % vars ())
62 native_view = re.sub ('"([^"]*).*"', '\\1', pdfopencommand)
64 native_view = 'acrobat'
67 pdfview = read_pipe ("/usr/bin/cygpath -au '%(native_view)s'" % vars ())
70 sys.stderr.write ('no pdf viewer found\n')
74 system ("/usr/bin/lilypond '%(base)s' > '%(stem)s.log' 2>&1" % vars ())
75 if not os.path.exists ('%(stem)s.pdf' % vars ()):
77 sys.stderr.write ('pdf output not found\n')
79 system ("'%(pdfview)s' '%(native_base)s.pdf'" % vars ())