]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefs2prefs_prefs.py
Update prefs2prefs again. Thanks Vincent.
[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
20 ###########################################################
21 #
22 # Conversion chain
23
24 def simple_renaming(line, old, new):
25         if line.find(old) == -1:
26                 return no_match
27         line = line.replace(old, new)
28         return (True, line)
29
30 no_match = (False, [])
31
32 ########################
33 ### Format 1 conversions
34
35 def remove_obsolete(line):
36         tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
37                                 "\\plaintext_roff_command", "\\use_alt_language", 
38                                 "\\use_escape_chars", "\\use_input_encoding",
39                                 "\\use_personal_dictionary", "\\use_pspell",
40                                 "\\use_spell_lib")
41         line = line.lstrip()
42         for tag in tags:
43                 if line.startswith(tag):
44                         return (True, "")
45         return no_match
46
47 def language_use_babel(line):
48         if not line.startswith("\language_use_babel"):
49                 return no_match
50         re_lub = re.compile(r'^\\language_use_babel\s+(true|false)')
51         m = re_lub.match(line)
52         val = m.group(1)
53         newval = '0'
54         if val == 'false':
55                 newval = '3'
56         newline = "\\language_package_selection " + newval
57         return (True, newline)
58
59 def language_package(line):
60         return simple_renaming(line, "\\language_package", "\\language_custom_package")
61
62
63 ########################
64
65
66 conversions = [
67         [ # this will be a long list of conversions for format 0
68                 remove_obsolete,
69                 language_use_babel,
70                 language_package
71         ] # end conversions for format 0
72 ]