2 # -*- coding: utf-8 -*-
4 # file prefs2prefs-lfuns.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.
31 ###########################################################
35 def simple_renaming(line, old, new):
36 if line.find(old) == -1:
38 line = line.replace(old, new)
41 no_match = (False, [])
43 ########################
44 ### Format 1 conversions
46 def remove_obsolete(line):
47 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
48 "\\plaintext_roff_command", "\\use_alt_language",
49 "\\use_escape_chars", "\\use_input_encoding",
50 "\\use_personal_dictionary", "\\use_pspell",
54 if line.startswith(tag):
58 def language_use_babel(line):
59 if not line.startswith("\language_use_babel"):
61 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)')
62 m = re_lub.match(line)
67 newline = "\\language_package_selection " + newval
68 return (True, newline)
70 def language_package(line):
71 return simple_renaming(line, "\\language_package", "\\language_custom_package")
73 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
74 def latex_flavor(line):
75 if not line.startswith("\\converter"):
88 if conv in conv2fl.keys():
89 flavor = conv2fl[conv]
95 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
97 emre = re.compile(r'^\\[Ff]ormat\s+(.*)\s+"(document[^"]*?)"')
98 def export_menu(line):
99 if not line.lower().startswith("\\format"):
107 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
109 zipre = re.compile(r'^\\[Ff]ormat\s+("?dia"?\s+.*)\s+"([^"]*?)"')
110 def zipped_native(line):
111 if not line.lower().startswith("\\format"):
113 m = zipre.match(line)
119 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
121 ########################
125 [ 1, [ # this will be a long list of conversions to format 1
133 [ 3, [ zipped_native ]],