]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/texi2omf.py
* Documentation/user/music-glossary.tely: add @omf tags
[lilypond.git] / buildscripts / texi2omf.py
1 import time
2 import re
3 import sys
4 import getopt
5 import os
6
7 def usage ():
8         sys.stderr.write ('''
9 texi2omf [options] texifile
10
11 Options:
12
13 --format=FORM         format is FORM. Supported: HTML, PS, PDF
14 --location=FILE       path to file on disk.
15 --version=VERSION
16
17 Use the following commands (enclose in @ignore)
18
19 @omfsubject . .
20 @omfdescription . .
21 @omftype . . 
22
23 etc.
24
25
26 ''')
27         
28 (options, files) = getopt.getopt (sys.argv[1:], '',
29                                   ['format=', 'location=', 'version='])
30
31 license = 'FDL'
32 location = ''
33 version = ''
34 email = os.getenv ('MAILADDRESS')
35 name = os.getenv ('USERNAME')
36
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
46
47                 
48 if not files:
49         usage()
50         sys.exit (2)
51
52
53 formats = {
54         'html' : 'text/html',
55         'pdf' : 'application/pdf',
56         'ps.gz' : 'application/postscript',
57         'ps' : 'application/postscript',
58         }
59
60 if not formats.has_key (format):
61         sys.stderr.write ("Format `%s' unknown\n" % format)
62         sys.exit (1)
63
64
65 infile =files[0]
66
67 today = time.localtime()
68
69 texi = open (infile).read()
70
71 if not location:
72         location = 'file:%s' % re.sub (r'\.*', '.html', infile)
73         
74
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, 
81         }
82
83 for a in ['subject','creator', 'title', 'subtitle', 'version', 'category', 'type',
84           'description',  'license']:
85         
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] = ''
91                 
92 if not omf_vars['title']:
93         title = ''
94         m = re.search ('@title (.*)\n', texi)
95         if m:
96                 title = m.group (1)
97
98         subtitle = ''
99         m = re.search ('@subtitle (.*)\n', texi)
100         if m:
101                 subtitle = m.group (1)
102
103         if subtitle:
104                 title  = '%s -- %s' % (title, subtitle)
105
106         omf_vars['title'] = title
107         
108 if not omf_vars['creator']:
109         m = re.search ('@author (.*)\n', texi)
110         if m:
111                 omf_vars['creator'] = m.group (1)
112
113
114
115 print r'''
116 <?xml version="1.0" encoding="UTF-8"?>
117 <!DOCTYPE omf PUBLIC "-//OMF//DTD Scrollkeeper OMF Variant V1.0//EN" "http://scrollkeeper.sourceforge.net/dtds/scrollkeeper-omf-1.0/scrollkeeper-omf.dtd">
118 <omf>
119   <resource>
120     <creator>
121       %(creator)s
122     </creator>
123     <maintainer>
124       %(maintainer)s
125     </maintainer>
126     <title>
127       %(title)s
128     </title>
129     <date>
130       %(date)s
131     </date>
132     <version identifier="%(version)s" />
133     <subject category="%(category)s"/>
134     <description>
135     %(description)s
136     </description>
137     <type>
138     %(type)s
139     </type>
140     <format mime="%(mimeformat)s">
141     <identifier url="%(location)s"/>
142     <language code="C"/>
143     <rights type="%(license)s" />
144   </resource>
145 </omf>
146 ''' % omf_vars
147
148