Markup command indexing: don't use internal function names.
[lilypond.git] / buildscripts / texi2omf.py
blobcc2603f5e03e172b7fb9d130636ea12d461d318d
1 #!@PYTHON@
3 import getopt
4 import os
5 import re
6 import sys
7 import time
9 def usage ():
10 sys.stderr.write ('''
11 texi2omf [options] FILE.texi > FILE.omf
13 Options:
15 --format=FORM set format FORM (HTML, PS, PDF, [XML]).
16 --location=FILE file name as installed on disk.
17 --version=VERSION
19 Use the following commands (enclose in @ignore)
21 @omfsubject . .
22 @omfdescription . .
23 @omftype . .
25 etc.
28 ''')
30 (options, files) = getopt.getopt (sys.argv[1:], '',
31 ['format=', 'location=', 'version='])
33 license = 'FDL'
34 location = ''
35 version = ''
36 email = os.getenv ('MAILADDRESS')
37 name = os.getenv ('USERNAME')
38 format = 'xml'
40 for (o, a) in options:
41 if o == '--format':
42 format = a
43 elif o == '--location':
44 location = 'file:%s' % a
45 elif o == '--version':
46 version = a
47 else:
48 assert 0
51 if not files:
52 usage ()
53 sys.exit (2)
56 formats = {
57 'html' : 'text/html',
58 'pdf' : 'application/pdf',
59 'ps.gz' : 'application/postscript',
60 'ps' : 'application/postscript',
61 'xml' : 'text/xml',
64 if not formats.has_key (format):
65 sys.stderr.write ("Format `%s' unknown\n" % format)
66 sys.exit (1)
69 infile = files[0]
71 today = time.localtime ()
73 texi = open (infile).read ()
75 if not location:
76 location = 'file:/%s' % re.sub (r'\..*', '.' + format, infile)
78 omf_vars = {
79 'date': '%d-%d-%d' % today[:3],
80 'mimeformat': formats[format],
81 'maintainer': "%s (%s)" % (name, email),
82 'version' : version,
83 'location' : location,
84 'language' : 'C',
87 omf_caterories = ['subject', 'creator', 'maintainer', 'contributor',
88 'title', 'subtitle', 'version', 'category', 'type',
89 'description', 'license', 'language',]
91 for a in omf_caterories:
92 m = re.search ('@omf%s (.*)\n'% a, texi)
93 if m:
94 omf_vars[a] = m.group (1)
95 elif not omf_vars.has_key (a):
96 omf_vars[a] = ''
98 if not omf_vars['title']:
99 title = ''
100 m = re.search ('@title (.*)\n', texi)
101 if m:
102 title = m.group (1)
104 subtitle = ''
105 m = re.search ('@subtitle (.*)\n', texi)
106 if m:
107 subtitle = m.group (1)
109 if subtitle:
110 title = '%s -- %s' % (title, subtitle)
112 omf_vars['title'] = title
114 if not omf_vars['creator']:
115 m = re.search ('@author (.*)\n', texi)
116 if m:
117 omf_vars['creator'] = m.group (1)
121 print r'''<?xml version="1.0" encoding="UTF-8"?>
122 <!DOCTYPE omf PUBLIC "-//OMF//DTD Scrollkeeper OMF Variant V1.0//EN" "http://scrollkeeper.sourceforge.net/dtds/scrollkeeper-omf-1.0/scrollkeeper-omf.dtd">
123 <omf>
124 <resource>
125 <creator>
126 %(creator)s
127 </creator>
128 <maintainer>
129 %(maintainer)s
130 </maintainer>
131 <title>
132 %(title)s
133 </title>
134 <date>
135 %(date)s
136 </date>
137 <version identifier="%(version)s" date="%(date)s" />
138 <subject category="%(category)s"/>
139 <description>
140 %(description)s
141 </description>
142 <type>
143 %(type)s
144 </type>
145 <format mime="%(mimeformat)s" />
146 <identifier url="%(location)s"/>
147 <language code="%(language)s"/>
148 <rights type="%(license)s" />
149 </resource>
150 </omf>
152 ''' % omf_vars