]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefs2prefs_prefs.py
* de.po: spelling correction
[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 import re
20
21
22 ###########################################################
23 #
24 # Conversion chain
25
26 def simple_renaming(line, old, new):
27         if line.find(old) == -1:
28                 return no_match
29         line = line.replace(old, new)
30         return (True, line)
31
32 no_match = (False, [])
33
34 ########################
35 ### Format 1 conversions
36
37 def remove_obsolete(line):
38         tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
39                                 "\\plaintext_roff_command", "\\use_alt_language", 
40                                 "\\use_escape_chars", "\\use_input_encoding",
41                                 "\\use_personal_dictionary", "\\use_pspell",
42                                 "\\use_spell_lib")
43         line = line.lstrip()
44         for tag in tags:
45                 if line.startswith(tag):
46                         return (True, "")
47         return no_match
48
49 def language_use_babel(line):
50         if not line.startswith("\language_use_babel"):
51                 return no_match
52         re_lub = re.compile(r'^\\language_use_babel\s+(true|false)')
53         m = re_lub.match(line)
54         val = m.group(1)
55         newval = '0'
56         if val == 'false':
57                 newval = '3'
58         newline = "\\language_package_selection " + newval
59         return (True, newline)
60
61 def language_package(line):
62         return simple_renaming(line, "\\language_package", "\\language_custom_package")
63
64 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
65 def latex_flavor(line):
66         if not line.startswith("\\converter"):
67                 return no_match
68         m = lfre.match(line)
69         if not m:
70                 return no_match
71         conv = m.group(1)
72         fmat = m.group(2)
73         args = m.group(3)
74         flavor = "pdflatex"     
75         if conv in ("platex", "xetex", "luatex"):
76                 flavor = conv
77         return (True, 
78                 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
79
80
81 ########################
82
83
84 conversions = [
85         [ # this will be a long list of conversions for format 0
86                 latex_flavor,
87                 remove_obsolete,
88                 language_use_babel,
89                 language_package
90         ] # end conversions for format 0
91 ]