From 580fa7ee3bdfe1191e2d6b9ea884afae5f97a323 Mon Sep 17 00:00:00 2001 From: Julien Rioux Date: Wed, 15 Jun 2011 22:24:30 +0000 Subject: [PATCH] configure.py : Remove more code duplication. No change in output, at least none intended. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39077 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/configure.py | 63 +++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/lib/configure.py b/lib/configure.py index 15a6095f1b..c97af47d66 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -261,6 +261,10 @@ def checkProgAlternatives(description, progs, rc_entry = [], alt_rc_entry = [], def addAlternatives(rcs, alt_type): + ''' + Returns a \\prog_alternatives string to be used as an alternative + rc entry. + ''' r = re.compile(r'\\Format (\S+).*$') m = None alt = '' @@ -279,8 +283,11 @@ def addAlternatives(rcs, alt_type): return alt -def checkViewer(description, progs, rc_entry = [], path = []): - ''' The same as checkProgAlternatives, but for viewers ''' +def listAlternatives(progs, alt_type, rc_entry = []): + ''' + Returns a list of \\prog_alternatives strings to be used as alternative + rc entries. + ''' if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1: logger.error("rc entry should have one item or item for each prog and not_found.") sys.exit(2) @@ -288,67 +295,37 @@ def checkViewer(description, progs, rc_entry = [], path = []): for idx in range(len(progs)): if len(rc_entry) == 1: rcs = rc_entry[0].split('\n') - alt = addAlternatives(rcs, 'viewer') + alt = addAlternatives(rcs, alt_type) alt_rc_entry.insert(0, alt) elif len(rc_entry) > 1: rcs = rc_entry[idx].split('\n') - alt = addAlternatives(rcs, 'viewer') + alt = addAlternatives(rcs, alt_type) alt_rc_entry.insert(idx, alt) + return alt_rc_entry + + +def checkViewer(description, progs, rc_entry = [], path = []): + ''' The same as checkProgAlternatives, but for viewers ''' + alt_rc_entry = listAlternatives(progs, 'viewer', rc_entry) return checkProgAlternatives(description, progs, rc_entry, alt_rc_entry, path, not_found = 'auto') def checkEditor(description, progs, rc_entry = [], path = []): ''' The same as checkProgAlternatives, but for editors ''' - if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1: - logger.error("rc entry should have one item or item for each prog and not_found.") - sys.exit(2) - alt_rc_entry = [] - for idx in range(len(progs)): - if len(rc_entry) == 1: - rcs = rc_entry[0].split('\n') - alt = addAlternatives(rcs, 'editor') - alt_rc_entry.insert(0, alt) - elif len(rc_entry) > 1: - rcs = rc_entry[idx].split('\n') - alt = addAlternatives(rcs, 'editor') - alt_rc_entry.insert(idx, alt) + alt_rc_entry = listAlternatives(progs, 'editor', rc_entry) return checkProgAlternatives(description, progs, rc_entry, alt_rc_entry, path, not_found = 'auto') def checkViewerNoRC(description, progs, rc_entry = [], path = []): ''' The same as checkViewer, but do not add rc entry ''' - if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1: - logger.error("rc entry should have one item or item for each prog and not_found.") - sys.exit(2) - alt_rc_entry = [] - for idx in range(len(progs)): - if len(rc_entry) == 1: - rcs = rc_entry[0].split('\n') - alt = addAlternatives(rcs, 'viewer') - alt_rc_entry.insert(0, alt) - elif len(rc_entry) > 1: - rcs = rc_entry[idx].split('\n') - alt = addAlternatives(rcs, 'viewer') - alt_rc_entry.insert(idx, alt) + alt_rc_entry = listAlternatives(progs, 'viewer', rc_entry) rc_entry = [] return checkProgAlternatives(description, progs, rc_entry, alt_rc_entry, path, not_found = 'auto') def checkEditorNoRC(description, progs, rc_entry = [], path = []): ''' The same as checkViewer, but do not add rc entry ''' - if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1: - logger.error("rc entry should have one item or item for each prog and not_found.") - sys.exit(2) - alt_rc_entry = [] - for idx in range(len(progs)): - if len(rc_entry) == 1: - rcs = rc_entry[0].split('\n') - alt = addAlternatives(rcs, 'editor') - alt_rc_entry.insert(0, alt) - elif len(rc_entry) > 1: - rcs = rc_entry[idx].split('\n') - alt = addAlternatives(rcs, 'editor') - alt_rc_entry.insert(idx, alt) + alt_rc_entry = listAlternatives(progs, 'editor', rc_entry) rc_entry = [] return checkProgAlternatives(description, progs, rc_entry, alt_rc_entry, path, not_found = 'auto') -- 2.39.2