]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/texi2omf.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / build / texi2omf.py
1 #!@PYTHON@
2
3 import getopt
4 import os
5 import re
6 import sys
7 import time
8
9 def usage ():
10     sys.stderr.write ('''
11 texi2omf [options] FILE.texi > FILE.omf
12
13 Options:
14
15 --format=FORM         set format FORM  (HTML, PS, PDF, [XML]).
16 --location=FILE       file name as installed on disk.
17 --version=VERSION
18
19 Use the following commands (enclose in @ignore)
20
21 @omfsubject . .
22 @omfdescription . .
23 @omftype . . 
24
25 etc.
26
27
28 ''')
29     
30 (options, files) = getopt.getopt (sys.argv[1:], '',
31                  ['format=', 'location=', 'version='])
32
33 license = 'FDL'
34 location = ''
35 version = ''
36 email = os.getenv ('MAILADDRESS')
37 name = os.getenv ('USERNAME')
38 format = 'xml'
39
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
49
50         
51 if not files:
52     usage ()
53     sys.exit (2)
54
55
56 formats = {
57     'html' : 'text/html',
58     'pdf' : 'application/pdf',
59     'ps.gz' : 'application/postscript',
60     'ps' : 'application/postscript',
61     'xml' : 'text/xml',
62     }
63
64 if not formats.has_key (format):
65     sys.stderr.write ("Format `%s' unknown\n" % format)
66     sys.exit (1)
67
68
69 infile = files[0]
70
71 today = time.localtime ()
72
73 texi = open (infile).read ()
74
75 if not location:
76     location = 'file:/%s' % re.sub (r'\..*', '.' + format, infile)
77
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',
85     }
86
87 omf_caterories = ['subject', 'creator', 'maintainer', 'contributor',
88          'title', 'subtitle', 'version', 'category', 'type',
89          'description', 'license', 'language',]
90     
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] = ''
97         
98 if not omf_vars['title']:
99     title = ''
100     m = re.search ('@title (.*)\n', texi)
101     if m:
102         title = m.group (1)
103
104     subtitle = ''
105     m = re.search ('@subtitle (.*)\n', texi)
106     if m:
107         subtitle = m.group (1)
108
109     if subtitle:
110         title  = '%s -- %s' % (title, subtitle)
111
112     omf_vars['title'] = title
113     
114 if not omf_vars['creator']:
115     m = re.search ('@author (.*)\n', texi)
116     if m:
117         omf_vars['creator'] = m.group (1)
118
119
120
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>
151
152 ''' % omf_vars
153
154