]> git.donarmstrong.com Git - lilypond.git/blob - cygwin/lily-wins.py
(web-install): Bugfix: set out prefix Similar to
[lilypond.git] / cygwin / lily-wins.py
1 #!@PYTHON@
2 # lily-wins.py -- LilyPond command for .ly on Windows
3
4 import os
5 import re
6 import sys
7
8 def usage ():
9         print 'Usage [-h,--help] lily-wins LY-FILE'
10
11 # print debugging stuff for now
12 def debug (s):
13         print s
14
15 def read_pipe (command):
16         debug ('command:' + command)
17         s = os.popen (command).read ()
18         if s and s[-1] == '\n':
19                 return s[:-1]
20         return s 
21
22 def system (command):
23         debug ('command:' + command)
24         os.system (command)
25
26 def strip_extension (f, ext):
27         (p, e) = os.path.splitext (f)
28         if e == ext:
29                 e = ''
30         return p + e
31
32 debug (`sys.argv`)
33
34 if len (sys.argv) != 2 \
35    or sys.argv[1] == '-h' or sys.argv[1] == '--help':
36         usage ()
37         sys.exit (0)
38         
39 native_file = sys.argv[1]
40         
41 file = read_pipe ("/usr/bin/cygpath -au '%(native_file)s'" % vars ())
42 if not file:
43         file = native_file
44
45 cwd = os.getcwd ()
46
47 dir = os.path.dirname (file)
48 if not dir:
49         dir = '.'
50 base = os.path.basename (file)
51 stem = strip_extension (base, '.ly')
52 print `vars ()`
53
54 native_base = read_pipe ('/usr/bin/cygpath -aw %(dir)s/%(stem)s' % vars ())
55 if not native_base:
56         native_base = '%(dir)s/%(stem)s' % vars ()
57
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 ())
60
61 # hmm
62 native_view = re.sub ('"([^"]*).*"', '\\1', pdfopencommand)
63 if not native_view:
64         native_view = 'acrobat'
65         
66 if native_view:
67         pdfview = read_pipe ("/usr/bin/cygpath -au '%(native_view)s'" % vars ())
68 if not pdfview:
69         # message box?
70         sys.stderr.write ('no pdf viewer found\n')
71         pdfview = 'xpdf'
72
73 os.chdir (dir)
74 system ("/usr/bin/lilypond '%(base)s' > '%(stem)s.log' 2>&1" % vars ())
75 if not os.path.exists ('%(stem)s.pdf' % vars ()):
76         # message box?
77         sys.stderr.write ('pdf output not found\n')
78
79 system ("'%(pdfview)s' '%(native_base)s.pdf'" % vars ())