Skip to content

Commit 224e3f6

Browse files
committed
Import document state changes, spit out missing comments
- Legacy-Id: 2712
1 parent df9dba6 commit 224e3f6

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

redesign/doc/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ class SendQueue(models.Model):
145145

146146

147147
EVENT_TYPES = [
148-
# misc document events
148+
# core events
149149
("new_revision", "Added new revision"),
150-
("document_changed", "Changed document"),
151-
("tombstone_added", "Added tombstone"),
150+
("changed_document", "Changed document metadata"),
151+
152+
# misc document events
153+
("added_tombstone", "Added tombstone"),
152154
("requested_resurrect", "Requested resurrect"),
153155

154156
# IESG events

redesign/import-document-state.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# assumptions:
2020
# - groups have been imported
21-
# - iesglogin emails have been imported
21+
# - roles have been imported
2222

2323
# FIXME: what about RFCs
2424

@@ -94,6 +94,7 @@ def date_in_match(match):
9494
re_telechat_agenda = re.compile(r"(Placed on|Removed from) agenda for telechat - %s by" % date_re_str)
9595
re_ballot_position = re.compile(r"\[Ballot Position Update\] (New position, (?P<position>.*), has been recorded (|for (?P<for>.*) )|Position (|for (?P<for2>.*) )has been changed to (?P<position2>.*) from .*)by (?P<by>.*)")
9696
re_ballot_issued = re.compile(r"Ballot has been issued by")
97+
re_state_changed = re.compile(r"(State (changed|Changes) to <b>(?P<to>.*)</b> from <b>(?P<from>.*)</b> by|Sub state has been changed to (?P<tosub>.*) from (?P<fromsub>.*))")
9798

9899
# helpers for events
99100

@@ -104,16 +105,30 @@ def save_event(doc, event, comment):
104105
event.desc = comment.comment_text # FIXME: consider unquoting here
105106
event.save()
106107

108+
iesg_login_cache = {}
109+
110+
# make sure system email exists
111+
system_email, _ = Email.objects.get_or_create(address="(System)")
112+
107113
def iesg_login_to_email(l):
108114
if not l:
109-
return None
115+
return system_email
110116
else:
117+
# fix logins without the right person
118+
if not l.person:
119+
if l.id not in iesg_login_cache:
120+
logins = IESGLogin.objects.filter(first_name=l.first_name, last_name=l.last_name).exclude(id=l.id)
121+
if logins:
122+
iesg_login_cache[l.id] = logins[0]
123+
else:
124+
iesg_login_cache[l.id] = None
125+
l = iesg_login_cache[l.id]
126+
111127
try:
112128
return Email.objects.get(address=l.person.email()[1])
113129
except Email.DoesNotExist:
114130
print "MISSING IESG LOGIN", l.person.email()
115131
return None
116-
117132

118133

119134
all_drafts = InternetDraft.objects.all().select_related()
@@ -158,6 +173,8 @@ def iesg_login_to_email(l):
158173

159174
# extract events
160175
for c in o.idinternal.documentcomment_set.order_by('date', 'time', 'id'):
176+
handled = False
177+
161178
# telechat agenda schedulings
162179
match = re_telechat_agenda.search(c.comment_text)
163180
if match:
@@ -167,6 +184,7 @@ def iesg_login_to_email(l):
167184
# can't extract this from history so we just take the latest value
168185
e.returning_item = bool(o.idinternal.returning_item)
169186
save_event(d, e, c)
187+
handled = True
170188

171189

172190
# ballot issued
@@ -187,6 +205,7 @@ def iesg_login_to_email(l):
187205
e.comment = last_pos.ballotposition.comment if last_pos else ""
188206
e.comment_time = last_pos.ballotposition.comment_time if last_pos else None
189207
save_event(d, e, c)
208+
handled = True
190209

191210

192211
# ballot positions
@@ -206,6 +225,7 @@ def iesg_login_to_email(l):
206225
e.comment = last_pos.ballotposition.comment if last_pos else ""
207226
e.comment_time = last_pos.ballotposition.comment_time if last_pos else None
208227
save_event(d, e, c)
228+
handled = True
209229

210230

211231
# ballot discusses/comments
@@ -230,6 +250,19 @@ def iesg_login_to_email(l):
230250
# put header into description
231251
c.comment_text = "[Ballot comment]\n" + c.comment_text
232252
save_event(d, e, c)
253+
handled = True
254+
255+
# state changes
256+
match = re_state_changed.search(c.comment_text)
257+
if match:
258+
# we currently don't recreate DocumentHistory
259+
e = Event(type="changed_document")
260+
save_event(d, e, c)
261+
handled = True
262+
263+
264+
if not handled:
265+
print "couldn't handle %s '%s'" % (c.id, c.comment_text.replace("\n", "").replace("\r", ""))
233266

234267

235268
print "imported", d.name, "state", d.iesg_state
@@ -317,4 +350,4 @@ class CheckListBallotInfo(models.Model):
317350
approval_text = models.TextField(blank=True)
318351
last_call_text = models.TextField(blank=True)
319352
ballot_writeup = models.TextField(blank=True)
320-
ballot_issued = models.IntegerField(null=True, blank=True)
353+
# ballot_issued = models.IntegerField(null=True, blank=True)

0 commit comments

Comments
 (0)