A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
take a line as argument and return a list: (Bool, NewLine), where the Bool says if we've modified anything
and the NewLine is the new line, if so.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file prefs2prefs-lfuns.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Richard Heck
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
# This file houses conversion information for the preferences file.
|
|
|
|
|
|
|
|
# The converter functions take a line as argument and return a list:
|
|
|
|
# (Bool, NewLine),
|
|
|
|
# where the Bool says if we've modified anything and the NewLine is
|
|
|
|
# the new line, if so, which will be used to replace the old line.
|
|
|
|
|
2011-01-31 19:42:50 +00:00
|
|
|
import re
|
|
|
|
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
take a line as argument and return a list: (Bool, NewLine), where the Bool says if we've modified anything
and the NewLine is the new line, if so.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
#
|
|
|
|
# Conversion chain
|
|
|
|
|
2011-01-18 19:35:54 +00:00
|
|
|
def simple_renaming(line, old, new):
|
|
|
|
if line.find(old) == -1:
|
|
|
|
return no_match
|
|
|
|
line = line.replace(old, new)
|
|
|
|
return (True, line)
|
|
|
|
|
2011-01-16 03:59:43 +00:00
|
|
|
no_match = (False, [])
|
|
|
|
|
2011-01-18 19:35:54 +00:00
|
|
|
########################
|
|
|
|
### Format 1 conversions
|
|
|
|
|
2011-01-16 03:59:43 +00:00
|
|
|
def remove_obsolete(line):
|
2011-01-18 16:50:43 +00:00
|
|
|
tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
|
|
|
|
"\\plaintext_roff_command", "\\use_alt_language",
|
|
|
|
"\\use_escape_chars", "\\use_input_encoding",
|
|
|
|
"\\use_personal_dictionary", "\\use_pspell",
|
|
|
|
"\\use_spell_lib")
|
|
|
|
line = line.lstrip()
|
|
|
|
for tag in tags:
|
|
|
|
if line.startswith(tag):
|
|
|
|
return (True, "")
|
|
|
|
return no_match
|
|
|
|
|
|
|
|
def language_use_babel(line):
|
|
|
|
if not line.startswith("\language_use_babel"):
|
|
|
|
return no_match
|
|
|
|
re_lub = re.compile(r'^\\language_use_babel\s+(true|false)')
|
|
|
|
m = re_lub.match(line)
|
|
|
|
val = m.group(1)
|
|
|
|
newval = '0'
|
|
|
|
if val == 'false':
|
|
|
|
newval = '3'
|
|
|
|
newline = "\\language_package_selection " + newval
|
|
|
|
return (True, newline)
|
2011-01-16 03:59:43 +00:00
|
|
|
|
2011-01-18 19:35:54 +00:00
|
|
|
def language_package(line):
|
|
|
|
return simple_renaming(line, "\\language_package", "\\language_custom_package")
|
|
|
|
|
2011-01-31 19:42:50 +00:00
|
|
|
lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
|
|
|
|
def latex_flavor(line):
|
|
|
|
if not line.startswith("\\converter"):
|
|
|
|
return no_match
|
|
|
|
m = lfre.match(line)
|
|
|
|
if not m:
|
|
|
|
return no_match
|
|
|
|
conv = m.group(1)
|
|
|
|
fmat = m.group(2)
|
|
|
|
args = m.group(3)
|
|
|
|
flavor = "pdflatex"
|
|
|
|
if conv in ("platex", "xetex", "luatex"):
|
|
|
|
flavor = conv
|
|
|
|
return (True,
|
|
|
|
"\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
|
|
|
|
|
2011-01-18 19:35:54 +00:00
|
|
|
|
|
|
|
########################
|
|
|
|
|
|
|
|
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
take a line as argument and return a list: (Bool, NewLine), where the Bool says if we've modified anything
and the NewLine is the new line, if so.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
conversions = [
|
|
|
|
[ # this will be a long list of conversions for format 0
|
2011-01-31 19:42:50 +00:00
|
|
|
latex_flavor,
|
2011-01-18 16:50:43 +00:00
|
|
|
remove_obsolete,
|
2011-01-18 19:35:54 +00:00
|
|
|
language_use_babel,
|
|
|
|
language_package
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
take a line as argument and return a list: (Bool, NewLine), where the Bool says if we've modified anything
and the NewLine is the new line, if so.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
] # end conversions for format 0
|
|
|
|
]
|