2 # -*- coding: utf-8 -*-
4 # file prefs2prefs-prefs.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This file houses conversion information for the preferences file.
14 # The converter functions take a line as argument and return a list:
16 # where the Bool says if we've modified anything and the NewLine is
17 # the new line, if so, which will be used to replace the old line.
19 # Incremented to format 2, r39670 by jrioux
20 # Support for multiple file extensions per format.
21 # No conversion necessary.
23 # Incremented to format 3, r39705 by tommaso
24 # Support for file formats that are natively (g)zipped.
25 # We must add the flag zipped=native to formats that
26 # were previously hardcoded in the C++ source: dia.
28 # Incremented to format 4, r40028 by vfr
29 # Remove support for default paper size.
31 # Incremented to format 5, r40030 by vfr
32 # Add a default length unit.
33 # No conversion necessary.
35 # Incremented to format 6, r40515 by younes
36 # Add use_qimage option.
37 # No conversion necessary.
39 # Incremented to format 7, r40789 by gb
40 # Add mime type to file format
42 # Incremented to format 8, 288c1e0f by rgh
43 # Add "nice" flag for converters
44 # No conversion necessary.
46 # Incremented to format 9, by spitz
47 # Remove default_language rc.
51 ###########################################################
62 while i < len(line) and line[i] != '"':
63 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
68 entries.append(line[beg:end].replace('\\"', '"'))
71 elif not line[i].isspace():
73 while not line[i].isspace():
76 entries.append(line[beg:end])
81 def simple_renaming(line, old, new):
82 i = line.lower().find(old.lower())
85 line = line[:i] + new + line[i+len(old):]
88 no_match = (False, [])
90 ######################################
91 ### Format 1 conversions (for LyX 2.0)
93 def remove_obsolete(line):
94 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
95 "\\plaintext_roff_command", "\\use_alt_language",
96 "\\use_escape_chars", "\\use_input_encoding",
97 "\\use_personal_dictionary", "\\use_pspell",
99 line = line.lower().lstrip()
101 if line.lower().startswith(tag):
106 def language_use_babel(line):
107 if not line.lower().startswith("\language_use_babel"):
109 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
110 m = re_lub.match(line)
115 newline = "\\language_package_selection " + newval
116 return (True, newline)
119 def language_package(line):
120 return simple_renaming(line, "\\language_package", "\\language_custom_package")
123 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
124 def latex_flavor(line):
125 if not line.lower().startswith("\\converter"):
134 "luatex": "lualatex",
138 if conv in conv2fl.keys():
139 flavor = conv2fl[conv]
142 if flavor == "latex":
145 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
148 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
149 def export_menu(line):
150 if not line.lower().startswith("\\format"):
158 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
160 # End format 1 conversions (for LyX 2.0)
161 ########################################
163 #################################
164 # Conversions from LyX 2.0 to 2.1
165 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
166 def zipped_native(line):
167 if not line.lower().startswith("\\format"):
169 m = zipre.match(line)
175 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
177 def remove_default_papersize(line):
178 if not line.lower().startswith("\\default_papersize"):
182 def add_mime_types(line):
183 if not line.lower().startswith("\\format"):
185 entries = get_format(line)
189 converted = converted + ' ""'
191 formats = {'tgif':'application/x-tgif', \
192 'fig':'application/x-xfig', \
193 'dia':'application/x-dia-diagram', \
194 'odg':'application/vnd.oasis.opendocument.graphics', \
195 'svg':'image/svg+xml', \
196 'bmp':'image/x-bmp', \
198 'jpg':'image/jpeg', \
199 'pbm':'image/x-portable-bitmap', \
200 'pgm':'image/x-portable-graymap', \
201 'png':'image/x-png', \
202 'ppm':'image/x-portable-pixmap', \
203 'tiff':'image/tiff', \
204 'xbm':'image/x-xbitmap', \
205 'xpm':'image/x-xpixmap', \
206 'docbook-xml':'application/docbook+xml', \
207 'dot':'text/vnd.graphviz', \
208 'ly':'text/x-lilypond', \
209 'latex':'text/x-tex', \
210 'text':'text/plain', \
211 'gnumeric':'application/x-gnumeric', \
212 'excel':'application/vnd.ms-excel', \
213 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
214 'xhtml':'application/xhtml+xml', \
215 'bib':'text/x-bibtex', \
216 'eps':'image/x-eps', \
217 'ps':'application/postscript', \
218 'pdf':'application/pdf', \
219 'dvi':'application/x-dvi', \
220 'html':'text/html', \
221 'odt':'application/vnd.oasis.opendocument.text', \
222 'sxw':'application/vnd.sun.xml.writer', \
223 'rtf':'application/rtf', \
224 'doc':'application/msword', \
226 'lyx':'application/x-lyx', \
227 'wmf':'image/x-wmf', \
229 if entries[1] in formats.keys():
230 converted = converted + ' "' + formats[entries[1]] + '"'
232 converted = converted + ' ""'
233 return (True, converted)
235 def remove_default_language(line):
236 if not line.lower().startswith("\\default_language"):
241 # End conversions for LyX 2.0 to 2.1
242 ####################################
246 [ 1, [ # there were several conversions for format 1
254 [ 3, [ zipped_native ]],
255 [ 4, [ remove_default_papersize ]],
258 [ 7, [add_mime_types]],
260 [ 9, [ remove_default_language ]]