]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefs2prefs_prefs.py
Remove the prefence default_papersize
[lyx.git] / lib / scripts / prefs2prefs_prefs.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
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.
7
8 # author Richard Heck
9
10 # Full author contact details are available in file CREDITS
11
12 # This file houses conversion information for the preferences file.
13
14 # The converter functions take a line as argument and return a list: 
15 #       (Bool, NewLine), 
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.
18
19 # Incremented to format 2, r39670 by jrioux
20 #   Support for multiple file extensions per format.
21 #   No conversion necessary.
22
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.
27
28 # Incremented to format 4, r40028 by vfr
29 #   Remove support for default paper size.
30
31 import re
32
33
34 ###########################################################
35 #
36 # Conversion chain
37
38 def simple_renaming(line, old, new):
39         if line.find(old) == -1:
40                 return no_match
41         line = line.replace(old, new)
42         return (True, line)
43
44 no_match = (False, [])
45
46 ########################
47 ### Format 1 conversions
48
49 def remove_obsolete(line):
50         tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
51                                 "\\plaintext_roff_command", "\\use_alt_language", 
52                                 "\\use_escape_chars", "\\use_input_encoding",
53                                 "\\use_personal_dictionary", "\\use_pspell",
54                                 "\\use_spell_lib")
55         line = line.lstrip()
56         for tag in tags:
57                 if line.startswith(tag):
58                         return (True, "")
59         return no_match
60
61 def language_use_babel(line):
62         if not line.startswith("\language_use_babel"):
63                 return no_match
64         re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)')
65         m = re_lub.match(line)
66         val = m.group(1)
67         newval = '0'
68         if val == 'false':
69                 newval = '3'
70         newline = "\\language_package_selection " + newval
71         return (True, newline)
72
73 def language_package(line):
74         return simple_renaming(line, "\\language_package", "\\language_custom_package")
75
76 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
77 def latex_flavor(line):
78         if not line.startswith("\\converter"):
79                 return no_match
80         m = lfre.match(line)
81         if not m:
82                 return no_match
83         conv = m.group(1)
84         fmat = m.group(2)
85         args = m.group(3)
86         conv2fl = {
87                    "luatex":   "lualatex",
88                    "pplatex":  "latex",
89                    "xetex":    "xelatex",
90                   }
91         if conv in conv2fl.keys():
92                 flavor = conv2fl[conv]
93         else:
94                 flavor = conv
95         if flavor == "latex":
96                 return no_match
97         return (True,
98                 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
99
100 emre = re.compile(r'^\\[Ff]ormat\s+(.*)\s+"(document[^"]*?)"')
101 def export_menu(line):
102         if not line.lower().startswith("\\format"):
103                 return no_match
104         m = emre.match(line)
105         if not m:
106                 return no_match
107         fmat = m.group(1)
108         opts = m.group(2)
109         return (True,
110                 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
111
112 zipre = re.compile(r'^\\[Ff]ormat\s+("?dia"?\s+.*)\s+"([^"]*?)"')
113 def zipped_native(line):
114         if not line.lower().startswith("\\format"):
115                 return no_match
116         m = zipre.match(line)
117         if not m:
118                 return no_match
119         fmat = m.group(1)
120         opts = m.group(2)
121         return (True,
122                 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
123
124 def remove_default_papersize(line):
125         if not line.startswith("\\default_papersize"):
126                 return no_match
127         return (True, "")
128
129
130 ########################
131
132
133 conversions = [
134         [  1, [ # this will be a long list of conversions to format 1
135                 export_menu,
136                 latex_flavor,
137                 remove_obsolete,
138                 language_use_babel,
139                 language_package
140         ]],
141         [  2, []],
142         [  3, [ zipped_native ]],
143         [  4, [ remove_default_papersize ]],
144 ]