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.
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.
39 ###########################################################
43 def simple_renaming(line, old, new):
44 if line.find(old) == -1:
46 line = line.replace(old, new)
49 no_match = (False, [])
51 ########################
52 ### Format 1 conversions
54 def remove_obsolete(line):
55 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
56 "\\plaintext_roff_command", "\\use_alt_language",
57 "\\use_escape_chars", "\\use_input_encoding",
58 "\\use_personal_dictionary", "\\use_pspell",
62 if line.startswith(tag):
66 def language_use_babel(line):
67 if not line.startswith("\language_use_babel"):
69 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)')
70 m = re_lub.match(line)
75 newline = "\\language_package_selection " + newval
76 return (True, newline)
78 def language_package(line):
79 return simple_renaming(line, "\\language_package", "\\language_custom_package")
81 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
82 def latex_flavor(line):
83 if not line.startswith("\\converter"):
96 if conv in conv2fl.keys():
97 flavor = conv2fl[conv]
100 if flavor == "latex":
103 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
105 emre = re.compile(r'^\\[Ff]ormat\s+(.*)\s+"(document[^"]*?)"')
106 def export_menu(line):
107 if not line.lower().startswith("\\format"):
115 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
117 zipre = re.compile(r'^\\[Ff]ormat\s+("?dia"?\s+.*)\s+"([^"]*?)"')
118 def zipped_native(line):
119 if not line.lower().startswith("\\format"):
121 m = zipre.match(line)
127 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
129 def remove_default_papersize(line):
130 if not line.startswith("\\default_papersize"):
135 ########################
139 [ 1, [ # this will be a long list of conversions to format 1
147 [ 3, [ zipped_native ]],
148 [ 4, [ remove_default_papersize ]],