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, a18af620 by spitz
47 # Remove default_language rc.
49 # Incremented to format 10, 4985015 by tommaso
50 # Add close_buffer_with_last_view in preferences.
51 # No conversion necessary.
55 ###########################################################
66 while i < len(line) and line[i] != '"':
67 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
72 entries.append(line[beg:end].replace('\\"', '"'))
75 elif not line[i].isspace():
77 while not line[i].isspace():
80 entries.append(line[beg:end])
85 def simple_renaming(line, old, new):
86 i = line.lower().find(old.lower())
89 line = line[:i] + new + line[i+len(old):]
92 no_match = (False, [])
94 ######################################
95 ### Format 1 conversions (for LyX 2.0)
97 def remove_obsolete(line):
98 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
99 "\\plaintext_roff_command", "\\use_alt_language",
100 "\\use_escape_chars", "\\use_input_encoding",
101 "\\use_personal_dictionary", "\\use_pspell",
103 line = line.lower().lstrip()
105 if line.lower().startswith(tag):
110 def language_use_babel(line):
111 if not line.lower().startswith("\language_use_babel"):
113 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
114 m = re_lub.match(line)
119 newline = "\\language_package_selection " + newval
120 return (True, newline)
123 def language_package(line):
124 return simple_renaming(line, "\\language_package", "\\language_custom_package")
127 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
128 def latex_flavor(line):
129 if not line.lower().startswith("\\converter"):
138 "luatex": "lualatex",
142 if conv in conv2fl.keys():
143 flavor = conv2fl[conv]
146 if flavor == "latex":
149 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
152 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
153 def export_menu(line):
154 if not line.lower().startswith("\\format"):
162 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
164 # End format 1 conversions (for LyX 2.0)
165 ########################################
167 #################################
168 # Conversions from LyX 2.0 to 2.1
169 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
170 def zipped_native(line):
171 if not line.lower().startswith("\\format"):
173 m = zipre.match(line)
179 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
181 def remove_default_papersize(line):
182 if not line.lower().startswith("\\default_papersize"):
186 def add_mime_types(line):
187 if not line.lower().startswith("\\format"):
189 entries = get_format(line)
193 converted = converted + ' ""'
195 formats = {'tgif':'application/x-tgif', \
196 'fig':'application/x-xfig', \
197 'dia':'application/x-dia-diagram', \
198 'odg':'application/vnd.oasis.opendocument.graphics', \
199 'svg':'image/svg+xml', \
200 'bmp':'image/x-bmp', \
202 'jpg':'image/jpeg', \
203 'pbm':'image/x-portable-bitmap', \
204 'pgm':'image/x-portable-graymap', \
205 'png':'image/x-png', \
206 'ppm':'image/x-portable-pixmap', \
207 'tiff':'image/tiff', \
208 'xbm':'image/x-xbitmap', \
209 'xpm':'image/x-xpixmap', \
210 'docbook-xml':'application/docbook+xml', \
211 'dot':'text/vnd.graphviz', \
212 'ly':'text/x-lilypond', \
213 'latex':'text/x-tex', \
214 'text':'text/plain', \
215 'gnumeric':'application/x-gnumeric', \
216 'excel':'application/vnd.ms-excel', \
217 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
218 'xhtml':'application/xhtml+xml', \
219 'bib':'text/x-bibtex', \
220 'eps':'image/x-eps', \
221 'ps':'application/postscript', \
222 'pdf':'application/pdf', \
223 'dvi':'application/x-dvi', \
224 'html':'text/html', \
225 'odt':'application/vnd.oasis.opendocument.text', \
226 'sxw':'application/vnd.sun.xml.writer', \
227 'rtf':'application/rtf', \
228 'doc':'application/msword', \
230 'lyx':'application/x-lyx', \
231 'wmf':'image/x-wmf', \
233 if entries[1] in formats.keys():
234 converted = converted + ' "' + formats[entries[1]] + '"'
236 converted = converted + ' ""'
237 return (True, converted)
239 def remove_default_language(line):
240 if not line.lower().startswith("\\default_language"):
245 # End conversions for LyX 2.0 to 2.1
246 ####################################
250 [ 1, [ # there were several conversions for format 1
258 [ 3, [ zipped_native ]],
259 [ 4, [ remove_default_papersize ]],
262 [ 7, [add_mime_types]],
264 [ 9, [ remove_default_language ]],