From: Richard Heck Date: Thu, 4 Nov 2010 13:42:19 +0000 (+0000) Subject: Clean up author id reversion routine. X-Git-Tag: 2.0.0~2065 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1bc5f3cb2b977f373ccfe2ca35ab060d020efa77;p=features.git Clean up author id reversion routine. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36050 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 4890baf476..c172a03143 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1112,9 +1112,7 @@ def convert_author_id(document): m = re_author.match(document.header[i]) if m: name = m.group(2) - email = '' - if m.lastindex == 3: - email = m.group(3) + email = m.group(3) document.header[i] = "\\author %i %s %s" % (anum, name, email) # FIXME Should this really be incremented if we didn't match? anum += 1 @@ -1137,40 +1135,37 @@ def convert_author_id(document): def revert_author_id(document): " Remove the author_id from the \\author definition " i = 0 - j = 0 + anum = 0 + rx = re.compile(r'(\\author)\s+(\d+)\s+(\".*\")\s*(.*)$') idmap = dict() + while True: i = find_token(document.header, "\\author", i) if i == -1: break - - r = re.compile(r'(\\author) (\d+) (\".*\")\s?(.*)$') - m = r.match(document.header[i]) - if m != None: + m = rx.match(document.header[i]) + if m: author_id = int(m.group(2)) - idmap[author_id] = j + idmap[author_id] = anum name = m.group(3) - - email = '' - if m.lastindex == 4: - email = m.group(4) + email = m.group(4) document.header[i] = "\\author %s %s" % (name, email) - i = i + 1 - j = j + 1 + i += 1 + # FIXME Should this be incremented if we didn't match? + anum += 1 - k = 0 + i = 0 while True: - k = find_token(document.body, "\\change_", k) - if k == -1: + i = find_token(document.body, "\\change_", i) + if i == -1: break - - change = document.body[k].split(' '); + change = document.body[i].split(' '); if len(change) == 3: type = change[0] author_id = int(change[1]) time = change[2] - document.body[k] = "%s %i %s" % (type, idmap[author_id], time) - k = k + 1 + document.body[i] = "%s %i %s" % (type, idmap[author_id], time) + i += 1 def revert_suppress_date(document):