release commit
[lilypond.git] / buildscripts / texi2omf.py
blobf87fea162370d05ff527edaf18c91f9088573adf
1 import time
2 import re
3 import sys
4 import getopt
5 import os
7 def usage ():
8 sys.stderr.write ('''
9 texi2omf [options] texifile
11 Options:
13 --format=FORM format is FORM. Supported: HTML, PS, PDF
14 --location=FILE path to file on disk.
15 --version=VERSION
17 Use the following commands (enclose in @ignore)
19 @omfsubject . .
20 @omfdescription . .
21 @omftype . .
23 etc.
26 ''')
28 (options, files) = getopt.getopt (sys.argv[1:], '',
29 ['format=', 'location=', 'version='])
31 license = 'FDL'
32 location = ''
33 version = ''
34 email = os.getenv ('MAILADDRESS')
35 name = os.getenv ('USERNAME')
37 for (o,a) in options:
38 if o == '--format':
39 format = a
40 elif o == '--location':
41 location = 'file:%s' % a
42 elif o == '--version':
43 version = a
44 else:
45 assert 0
48 if not files:
49 usage()
50 sys.exit (2)
53 formats = {
54 'html' : 'text/html',
55 'pdf' : 'application/pdf',
56 'ps.gz' : 'application/postscript',
57 'ps' : 'application/postscript',
60 if not formats.has_key (format):
61 sys.stderr.write ("Format `%s' unknown\n" % format)
62 sys.exit (1)
65 infile =files[0]
67 today = time.localtime()
69 texi = open (infile).read()
71 if not location:
72 location = 'file:%s' % re.sub (r'\.*', '.html', infile)
75 omf_vars = {
76 'date': '%d-%d-%d' % today[:3],
77 'mimeformat': formats[format],
78 'maintainer': "%s (%s)" % (name, email),
79 'version' : version,
80 'location' : location,
83 for a in ['subject','creator', 'title', 'subtitle', 'version', 'category', 'type',
84 'description', 'license']:
86 m = re.search ('@omf%s (.*)\n'% a, texi)
87 if m:
88 omf_vars[a] = m.group (1)
89 elif not omf_vars.has_key (a):
90 omf_vars[a] = ''
92 if not omf_vars['title']:
93 title = ''
94 m = re.search ('@title (.*)\n', texi)
95 if m:
96 title = m.group (1)
98 subtitle = ''
99 m = re.search ('@subtitle (.*)\n', texi)
100 if m:
101 subtitle = m.group (1)
103 if subtitle:
104 title = '%s -- %s' % (title, subtitle)
106 omf_vars['title'] = title
108 if not omf_vars['creator']:
109 m = re.search ('@author (.*)\n', texi)
110 if m:
111 omf_vars['creator'] = m.group (1)
115 print r'''<?xml version="1.0" encoding="UTF-8"?>
116 <!DOCTYPE omf PUBLIC "-//OMF//DTD Scrollkeeper OMF Variant V1.0//EN" "http://scrollkeeper.sourceforge.net/dtds/scrollkeeper-omf-1.0/scrollkeeper-omf.dtd">
117 <omf>
118 <resource>
119 <creator>
120 %(creator)s
121 </creator>
122 <maintainer>
123 %(maintainer)s
124 </maintainer>
125 <title>
126 %(title)s
127 </title>
128 <date>
129 %(date)s
130 </date>
131 <version identifier="%(version)s" date="%(date)s" />
132 <subject category="%(category)s"/>
133 <description>
134 %(description)s
135 </description>
136 <type>
137 %(type)s
138 </type>
139 <format mime="%(mimeformat)s" />
140 <identifier url="%(location)s"/>
141 <language code="C"/>
142 <rights type="%(license)s" />
143 </resource>
144 </omf>
146 ''' % omf_vars