]> git.donarmstrong.com Git - lilypond.git/blob - scripts/lilypond-pdfpc-helper.py
new file. Invoke different
[lilypond.git] / scripts / lilypond-pdfpc-helper.py
1 #!@PYTHON@
2 import re
3 import getopt
4 import sys
5 import os
6
7 version = '@TOPLEVEL_VERSION@'
8
9 localedir = '@localedir@'
10 try:
11         import gettext
12         gettext.bindtextdomain ('lilypond', localedir)
13         gettext.textdomain ('lilypond')
14         _ = gettext.gettext
15 except:
16         def _ (s):
17                 return s
18         
19 program_name = os.path.basename (sys.argv[0])
20 print os.getcwd()
21 def usage():
22         sys.stdout.write ('Usage: %s FILE:LINE:COLUMN' % program_name)
23         sys.stdout.write ('\n\n')
24         sys.stdout.write ('Call remote editor given Mozilla remote link command')
25         sys.stdout.write ('\n\n')
26         sys.stdout.write (_ ("Report bugs to %s.") % "bug-lilypond@gnu.org")
27         sys.stdout.write ('\n')
28
29 def print_version ():
30         sys.stdout.write (program_id ())
31         sys.stdout.write ('\n')
32         sys.stdout.write (_ ("""\
33 This program is free software.  It is covered by the GNU General Public
34 License and you are welcome to change it and/or distribute copies of it
35 under certain conditions.  Invoke as `%s --warranty' for more
36 information.
37 """) % "lilypond")
38
39 def program_id ():
40         return '%s (GNU LilyPond) %s' % (program_name, version)
41
42 ################################################################
43 (options, files) = getopt.getopt (sys.argv[1:], 'hv', ['help','version'])
44
45 for opt in options:
46         o = opt[0]
47         a = opt[1]
48         if o == '--help' or o == '-h':
49                 usage ()
50                 sys.exit (0)
51         if o == '--version' or o == '-v':
52                 print_version ()
53                 sys.exit (0)
54
55
56 if not files:
57         usage()
58         sys.exit (1)
59         
60
61 ################################################################
62
63 match = re.match ('([^:]+):([^:]+):(.*)', files[0])
64 if not match:
65         sys.stderr.write (_("Not in FILE:LINE:COL format: ")
66                           + files[0])
67         sys.exit (1)
68
69 (file, line, column) = tuple (match.groups())
70
71 editor = os.environ['EDITOR']
72 ly_pc_editor = None
73 try:
74         ly_pc_editor = os.environ['LYEDITOR']
75 except KeyError:
76         pass
77
78
79 if ly_pc_editor == None:
80         if  re.search ("emacs", editor):
81                 ly_pc_editor = 'emacsclient --no-wait +%(line)s:%(column)s %(file)s'
82         elif re.search ('gvim', editor):
83                 ly_pc_editor = 'gvim --remote +:%(line)s:norm%(column)s %(file)s'
84         elif re.search ('nedit', editor):
85                 ly_pc_editor = 'nc -noask +%(line)s %(file)s'
86
87 command = ly_pc_editor % vars()
88
89 status = os.system (command)
90 if status:
91         sys.stderr.write (_("Command failed: `%s' (status %d)") % (command, status) + '\n')
92
93
94