lyx_mirror/lib/scripts/prefs2prefs_lfuns.py
Richard Heck 851d01721f 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

64 lines
1.5 KiB
Python

#! /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 bind and ui files,
# i.e., for files where we are converting lfuns.
# 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.
import sys, re
current_format = 1
###########################################################
#
# Actual converter functions
#
# These accept a line as argument and should return a list:
# (bool, newline)
# where the bool indicates whether we changed anything. In
# that case, one normally returns: (False, []).
def simple_renaming(line, old, new):
if line.find(old) == -1:
return (False, [])
line = line.replace(old, new)
return (True, line)
def next_inset_modify(line):
return simple_renaming(line, "next-inset-modify", "inset-modify")
def next_inset_toggle(line):
return simple_renaming(line, "next-inset-toggle", "inset-toggle")
#
#
###########################################################
# Conversion chain
conversions = [
[ # this will be a long list of conversions for format 0
next_inset_toggle,
next_inset_modify
] # end conversions for format 0
]