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