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)
33 return re.sub ("(\s|[`'\"\\\\])", r'\\\1',x)
34 # return re.sub (r'''([^\\])([`'"\\\s])''', r'\1\\\2', x)
35 # help emacs'" broken python mode
39 if len (sys.argv) != 2 \
40 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
44 native_file = sys.argv[1]
46 file = read_pipe ('/usr/bin/cygpath -au %s' % escape_shell (native_file))
52 dir = os.path.dirname (file)
55 base = os.path.basename (file)
56 stem = strip_extension (base, '.ly')
59 native_base = '%(dir)s/%(stem)s' % vars ()
60 native_base = read_pipe ('/usr/bin/cygpath -aw %s' % escape_shell (native_base))
63 native_base = '%(dir)s/%(stem)s' % vars ()
65 pdfname = read_pipe ('/usr/bin/regtool get /root/.pdf/')
66 pdfopencommand = read_pipe ('/usr/bin/regtool get /root/%s/shell/open/command/' % escape_shell (pdfname))
69 native_view = re.sub ('"([^"]*).*"', '\\1', pdfopencommand)
71 native_view = 'acrobat'
74 pdfview = read_pipe ('/usr/bin/cygpath -au %s' % escape_shell (native_view))
77 sys.stderr.write ('no pdf viewer found\n')
81 if os.path.exists ('/usr/bin/ly2dvi'):
82 system ('/usr/bin/ly2dvi -p %s > %s.log 2>&1' % (escape_shell (base),
85 system ('/usr/bin/lilypond %s > %s.log 2>&1' % (escape_shell (base),
87 if not os.path.exists ('%(stem)s.pdf' % vars ()):
89 sys.stderr.write ('pdf output not found\n')
91 system ('%s %s.pdf' % (escape_shell (pdfview), escape_shell (native_base)))