forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-docs.py
More file actions
executable file
·1322 lines (1112 loc) · 57.6 KB
/
import-docs.py
File metadata and controls
executable file
·1322 lines (1112 loc) · 57.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import sys, os, re, datetime
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
sys.path = [ basedir ] + sys.path
from ietf import settings
settings.USE_DB_REDESIGN_PROXY_CLASSES = False
from django.core import management
management.setup_environ(settings)
from django.template.defaultfilters import pluralize
from ietf.doc.models import *
from ietf.doc.utils import get_tags_for_stream_id
from ietf.group.models import *
from ietf.name.models import *
from ietf.person.models import *
from ietf.person.name import name_parts
from redesign.importing.utils import old_person_to_person, person_name, dont_save_queries
from ietf.name.utils import name
from ietf.idtracker.models import InternetDraft, IDInternal, IESGLogin, DocumentComment, PersonOrOrgInfo, Rfc, IESGComment, IESGDiscuss, BallotInfo, Position, Area
from ietf.idrfc.models import RfcIndex, DraftVersions
from ietf.idrfc.mirror_rfc_index import get_std_level_mapping, get_stream_mapping
from ietf.ietfworkflows.models import StreamedID, AnnotationTag, ContentType, ObjectHistoryEntry, ObjectWorkflowHistoryEntry, ObjectAnnotationTagHistoryEntry, ObjectStreamHistoryEntry, StateObjectRelationMetadata
from ietf.wgchairs.models import ProtoWriteUp
from workflows.models import State as StateOld
import_docs_from = document_name_to_import = None
if len(sys.argv) > 1:
try:
import_docs_from = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d")
except:
document_name_to_import = sys.argv[1]
dont_save_queries()
# assumptions:
# - states have been imported
# - groups have been imported
# - IESG login emails/roles have been imported
# - IDAuthor emails/persons have been imported
# Regarding history, we currently don't try to create DocumentHistory
# objects, we just import the comments as events.
# imports drafts and RFCs, more specifically InternetDraft,
# IDInternal, BallotInfo, Position, IESGComment, IESGDiscuss,
# DocumentComment, IDAuthor, idrfc.RfcIndex, idrfc.DraftVersions,
# StreamedID
def alias_doc(name, doc):
DocAlias.objects.filter(name=name).exclude(document=doc).delete()
alias, _ = DocAlias.objects.get_or_create(name=name, document=doc)
return alias
type_draft = name(DocTypeName, "draft", "Draft")
stream_mapping = get_stream_mapping()
stream_mapping["ISE"] = stream_mapping["INDEPENDENT"]
relationship_replaces = name(DocRelationshipName, "replaces", "Replaces")
relationship_updates = name(DocRelationshipName, "updates", "Updates")
relationship_obsoletes = name(DocRelationshipName, "obs", "Obsoletes")
intended_std_level_mapping = {
"Proposed Standard": name(IntendedStdLevelName, "ps", name="Proposed Standard", order=1),
"Draft Standard": name(IntendedStdLevelName, "ds", name="Draft Standard", order=2),
"Standard": name(IntendedStdLevelName, "std", name="Standard", order=3),
"BCP": name(IntendedStdLevelName, "bcp", "Best Current Practice", order=4),
"Informational": name(IntendedStdLevelName, "inf", name="Informational", order=5),
"Experimental": name(IntendedStdLevelName, "exp", name="Experimental", order=6),
"Historic": name(IntendedStdLevelName, "hist", name="Historic", order=7),
"None": None,
"Request": None,
}
# add aliases from rfc_intend_status
intended_std_level_mapping["Proposed"] = intended_std_level_mapping["Proposed Standard"]
intended_std_level_mapping["Draft"] = intended_std_level_mapping["Draft Standard"]
std_level_mapping = get_std_level_mapping()
state_mapping = {
'Active': State.objects.get(type="draft", slug="active"),
'Expired': State.objects.get(type="draft", slug="expired"),
'RFC': State.objects.get(type="draft", slug="rfc"),
'Withdrawn by Submitter': State.objects.get(type="draft", slug="auth-rm"),
'Replaced': State.objects.get(type="draft", slug="repl"),
'Withdrawn by IETF': State.objects.get(type="draft", slug="ietf-rm"),
}
iesg_state_mapping = {
'RFC Published': State.objects.get(type="draft-iesg", slug="pub"),
'Dead': State.objects.get(type="draft-iesg", slug="dead"),
'Approved-announcement to be sent': State.objects.get(type="draft-iesg", slug="approved"),
'Approved-announcement sent': State.objects.get(type="draft-iesg", slug="ann"),
'AD is watching': State.objects.get(type="draft-iesg", slug="watching"),
'IESG Evaluation': State.objects.get(type="draft-iesg", slug="iesg-eva"),
'AD Evaluation': State.objects.get(type="draft-iesg", slug="ad-eval"),
'Last Call Requested': State.objects.get(type="draft-iesg", slug="lc-req"),
'In Last Call': State.objects.get(type="draft-iesg", slug="lc"),
'Publication Requested': State.objects.get(type="draft-iesg", slug="pub-req"),
'RFC Ed Queue': State.objects.get(type="draft-iesg", slug="rfcqueue"),
'IESG Evaluation - Defer': State.objects.get(type="draft-iesg", slug="defer"),
'Waiting for Writeup': State.objects.get(type="draft-iesg", slug="writeupw"),
'Waiting for AD Go-Ahead': State.objects.get(type="draft-iesg", slug="goaheadw"),
'Expert Review': State.objects.get(type="draft-iesg", slug="review-e"),
'DNP-waiting for AD note': State.objects.get(type="draft-iesg", slug="nopubadw"),
'DNP-announcement to be sent': State.objects.get(type="draft-iesg", slug="nopubanw"),
None: None, # FIXME: consider introducing the ID-exists state
}
ballot_position_mapping = {
'Yes': name(BallotPositionName, 'yes', 'Yes', order=1),
'No Objection': name(BallotPositionName, 'noobj', 'No Objection', order=2),
'Discuss': name(BallotPositionName, 'discuss', 'Discuss', order=3),
'Abstain': name(BallotPositionName, 'abstain', 'Abstain', order=4),
'Recuse': name(BallotPositionName, 'recuse', 'Recuse', order=5),
'No Record': name(BallotPositionName, 'norecord', 'No Record', order=6),
}
ballot_position_mapping["no"] = ballot_position_mapping['No Objection']
ballot_position_mapping["yes"] = ballot_position_mapping['Yes']
ballot_position_mapping["discuss"] = ballot_position_mapping['Discuss']
ballot_position_mapping["abstain"] = ballot_position_mapping['Abstain']
ballot_position_mapping["recuse"] = ballot_position_mapping['Recuse']
ballot_position_mapping[None] = ballot_position_mapping["No Record"]
ballot_position_mapping["Undefined"] = ballot_position_mapping["No Record"]
# tags
substate_mapping = {
"External Party": name(DocTagName, 'extpty', "External Party", 'The document is awaiting review or input from an external party (i.e, someone other than the shepherding AD, the authors, or the WG). See the "note" field for more details on who has the action.', 3),
"Revised ID Needed": name(DocTagName, 'need-rev', "Revised ID Needed", 'An updated ID is needed to address the issues that have been raised.', 5),
"AD Followup": name(DocTagName, 'ad-f-up', "AD Followup", """A generic substate indicating that the shepherding AD has the action item to determine appropriate next steps. In particular, the appropriate steps (and the corresponding next state or substate) depend entirely on the nature of the issues that were raised and can only be decided with active involvement of the shepherding AD. Examples include:
- if another AD raises an issue, the shepherding AD may first iterate with the other AD to get a better understanding of the exact issue. Or, the shepherding AD may attempt to argue that the issue is not serious enough to bring to the attention of the authors/WG.
- if a documented issue is forwarded to a WG, some further iteration may be needed before it can be determined whether a new revision is needed or whether the WG response to an issue clarifies the issue sufficiently.
- when a new revision appears, the shepherding AD will first look at the changes to determine whether they believe all outstanding issues have been raised satisfactorily, prior to asking the ADs who raised the original issues to verify the changes.""", 2),
"Point Raised - writeup needed": name(DocTagName, 'point', "Point Raised - writeup needed", 'IESG discussions on the document have raised some issues that need to be brought to the attention of the authors/WG, but those issues have not been written down yet. (It is common for discussions during a telechat to result in such situations. An AD may raise a possible issue during a telechat and only decide as a result of that discussion whether the issue is worth formally writing up and bringing to the attention of the authors/WG). A document stays in the "Point Raised - Writeup Needed" state until *ALL* IESG comments that have been raised have been documented.', 1)
}
tag_review_by_rfc_editor = name(DocTagName, 'rfc-rev', "Review by RFC Editor")
tag_via_rfc_editor = name(DocTagName, 'via-rfc', "Via RFC Editor")
tag_approved_in_minute = name(DocTagName, 'app-min', "Approved in minute")
tag_has_errata = name(DocTagName, 'errata', "Has errata")
name(DocTagName, "w-expert", "Awaiting Expert Review/Resolution of Issues Raised", order=1)
name(DocTagName, "w-extern", "Awaiting External Review/Resolution of Issues Raised", order=2)
name(DocTagName, "w-merge", "Awaiting Merge with Other Document", order=3)
name(DocTagName, "need-aut", "Author or Editor Needed", order=4)
name(DocTagName, "w-refdoc", "Waiting for Referenced Document", order=5)
name(DocTagName, "w-refing", "Waiting for Referencing Document", order=6)
name(DocTagName, "rev-wglc", "Revised I-D Needed - Issue raised by WGLC", order=7)
name(DocTagName, "rev-ad", "Revised I-D Needed - Issue raised by AD", order=8)
name(DocTagName, "rev-iesg", "Revised I-D Needed - Issue raised by IESG", order=9)
name(DocTagName, "sheph-u", "Doc Shepherd Follow-up Underway", order=10)
name(DocTagName, "other", "Other - see Comment Log", order=11)
name(DocTagName, "need-ed", "Editor Needed", order=1)
name(DocTagName, "w-part", "Waiting for Partner Feedback", order=2)
name(DocTagName, "w-review", "Awaiting Reviews", order=3)
name(DocTagName, "sh-f-up", "Document Shepherd Followup", order=4)
name(DocTagName, "need-sh", "Shepherd Needed")
name(DocTagName, "w-dep", "Waiting for Dependency on Other Document")
name(DocTagName, "iesg-com", "IESG Review Completed")
stream_state_reminder_type = name(DocReminderTypeName, "stream-s", "Stream state should change")
#tag_mapping = dict((t.name, t) for t in DocTagName.objects.all())
# helpers
def extract_authors_from_dump():
authors_re = re.compile(r"docauthors='([^']*);....-..-..'")
name_email_re = re.compile(r"(.*) <([^>]+)>")
email_brackets_re = re.compile(r" <[^>]*>")
comma_re = re.compile(r".*,")
colon_re = re.compile(r".*:")
email_mapping = {
}
res = {}
if not os.path.exists(ALL_IDS_STATE):
print "WARNING: proceeding without author information in all_ids.state"
return res
with open(ALL_IDS_STATE, "r") as author_source:
for line in author_source:
if line.startswith("#"):
continue
draft_name = line.split(" ")[1]
m = authors_re.search(line)
if not m:
continue
l = []
reliable = True
for a in m.group(1).replace("\\x27", "'").replace("\\'", "'").decode("latin-1").split(", "):
n = name_email_re.match(a)
if n:
name = n.group(1)
email = n.group(2)
else:
name = a
email = ""
if "@" not in email or not email:
reliable = False
name = email_brackets_re.sub("", name)
name = comma_re.sub("", name)
name = colon_re.sub("", name)
name = name.strip()
if "VCARD" in name or len(name.split()) > 5:
reliable = False
if not reliable:
break
email = email_mapping.get(email, email)
l.append((name, email))
if reliable:
res[draft_name] = l
return res
author_dump = extract_authors_from_dump()
def save_docevent(doc, event, comment):
event.time = comment.datetime()
event.by = iesg_login_to_person(comment.created_by)
event.doc = doc
if not event.desc:
event.desc = comment.comment_text # FIXME: consider unquoting here
event.save()
def sync_tag(d, include, tag):
if include:
d.tags.add(tag)
else:
d.tags.remove(tag)
buggy_iesg_logins_cache = {}
system = Person.objects.get(name="(System)")
def iesg_login_to_person(l):
if not l:
return system
else:
# there's a bunch of old weird comments made by "IESG
# Member", transform these into "System" instead
if l.id == 2:
return system
# fix logins without the right person
if not l.person:
if l.id not in buggy_iesg_logins_cache:
logins = IESGLogin.objects.filter(first_name=l.first_name, last_name=l.last_name).exclude(id=l.id)
if logins:
buggy_iesg_logins_cache[l.id] = logins[0]
else:
persons = PersonOrOrgInfo.objects.filter(first_name=l.first_name, last_name=l.last_name)
if persons:
l.person = persons[0]
buggy_iesg_logins_cache[l.id] = l
else:
buggy_iesg_logins_cache[l.id] = None
l = buggy_iesg_logins_cache[l.id]
if not l:
return system
try:
return old_person_to_person(l.person)
except Person.DoesNotExist:
print "MISSING IESG LOGIN", l.person, l.person.email()
return None
def iesg_login_is_secretary(l):
# Amy has two users, for some reason, we sometimes get the wrong one
return l.user_level == IESGLogin.SECRETARIAT_LEVEL or (l.first_name == "Amy" and l.last_name == "Vezza")
old_internetdraft_content_type_id = ContentType.objects.using("legacy").get(app_label="idtracker", model="internetdraft").pk
# regexps for parsing document comments
date_re_str = "(?P<year>[0-9][0-9][0-9][0-9])-(?P<month>[0-9][0-9]?)-(?P<day>[0-9][0-9]?)"
def date_in_match(match):
y = int(match.group('year'))
m = int(match.group('month'))
d = int(match.group('day'))
if d == 35: # borked status date
d = 25
return datetime.date(y, m, d)
re_telechat_agenda = re.compile(r"(Placed on|Removed from) agenda for telechat( - %s|)" % date_re_str)
re_telechat_changed = re.compile(r"Telechat date (was|has been) changed to (<b>)?%s(</b>)? from" % date_re_str)
re_ballot_position = re.compile(r"\[Ballot Position Update\] (New position, (?P<position>.*), has been recorded( for (?P<for>\w+ \w+) |)|Position (|for (?P<for2>.*) )has been changed to (?P<position2>.*) from .*)(by (?P<by>.*)|)")
re_ballot_issued = re.compile(r"Ballot has been issued")
re_state_changed = re.compile(r"(State (has been changed|changed|Changes) to <b>(?P<to>.*)</b> from (<b>|)(?P<from>.*)(</b> by|)|Sub state has been changed to (?P<tosub>.*) from (?P<fromsub>.*))")
re_note_changed = re.compile(r"(\[Note\]: .*'.*'|Note field has been cleared)", re.DOTALL)
re_draft_added = re.compile(r"Draft [Aa]dded (by .*)?( in state (?P<state>.*))?")
re_last_call_requested = re.compile(r"Last Call was requested")
re_document_approved = re.compile(r"IESG has approved and state has been changed to")
re_document_disapproved = re.compile(r"(Do Not Publish|DNP) note has been sent to RFC Editor and state has been changed to")
re_resurrection_requested = re.compile(r"(I-D |)Resurrection was requested")
re_completed_resurrect = re.compile(r"(This document has been resurrected|This document has been resurrected per RFC Editor's request|Resurrection was completed)")
re_status_date_changed = re.compile(r"Status [dD]ate has been changed to (<b>)?" + date_re_str)
re_responsible_ad_changed = re.compile(r"(Responsible AD|Shepherding AD|responsible) has been changed to (<b>)?")
re_intended_status_changed = re.compile(r"Intended [sS]tatus has been changed to (<b>)?")
re_state_change_notice = re.compile(r"State Change Notice email list (have been change|has been changed) (<b>)?")
re_area_acronym_changed = re.compile(r"Area acronymn? has been changed to \w+ from \w+(<b>)?")
re_comment_discuss_by_tag = re.compile(r" by [\w-]+ [\w-]+$")
def import_from_idinternal(d, idinternal):
d.time = idinternal.event_date
d.ad = iesg_login_to_person(idinternal.job_owner)
d.notify = idinternal.state_change_notice_to or ""
d.note = (idinternal.note or "").replace('<br>', '\n').strip().replace('\n', '<br>')
try:
if idinternal.area_acronym and d.group.type_id == "individ":
d.group = Group.objects.get(acronym=idinternal.area_acronym.area_acronym.acronym)
except (Area.DoesNotExist, AttributeError):
pass
d.save()
d.set_state(iesg_state_mapping[idinternal.cur_state.state])
# extract events
last_note_change_text = ""
started_iesg_process = ""
document_comments = DocumentComment.objects.filter(document=idinternal.draft_id).order_by('date', 'time', 'id')
for c in document_comments:
handled = False
# telechat agenda schedulings
match = re_telechat_agenda.search(c.comment_text) or re_telechat_changed.search(c.comment_text)
if match:
e = TelechatDocEvent()
e.type = "scheduled_for_telechat"
e.telechat_date = date_in_match(match) if "Placed on" in c.comment_text else None
# can't extract this from history so we just take the latest value
e.returning_item = bool(idinternal.returning_item)
save_docevent(d, e, c)
handled = True
# ballot issued
match = re_ballot_issued.search(c.comment_text)
if match:
e = DocEvent()
e.type = "sent_ballot_announcement"
save_docevent(d, e, c)
handled = True
ad = iesg_login_to_person(c.created_by)
last_pos = d.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=ad)
if not last_pos and not iesg_login_is_secretary(c.created_by):
# when you issue a ballot, you also vote yes; add that vote
e = BallotPositionDocEvent()
e.type = "changed_ballot_position"
e.ad = ad
e.desc = u"[Ballot Position Update] New position, Yes, has been recorded for %s" % e.ad.plain_name()
e.pos = ballot_position_mapping["Yes"]
e.discuss = last_pos.discuss if last_pos else ""
e.discuss_time = last_pos.discuss_time if last_pos else None
e.comment = last_pos.comment if last_pos else ""
e.comment_time = last_pos.comment_time if last_pos else None
save_docevent(d, e, c)
# ballot positions
match = re_ballot_position.search(c.comment_text)
if match:
position = ballot_position_mapping[match.group('position') or match.group('position2')]
# some of the old positions don't specify who it's for, in
# that case assume it's "by", the person who entered the
# position
ad_name = match.group('for') or match.group('for2') or match.group('by') or (u"%s %s" % (c.created_by.first_name, c.created_by.last_name) if c.created_by else "")
ad_first, ad_last = ad_name.split(' ')
login = IESGLogin.objects.filter(first_name=ad_first, last_name=ad_last).order_by('user_level')[0]
if iesg_login_is_secretary(login):
# now we're in trouble, a secretariat person isn't an
# AD, instead try to find a position object that
# matches and that we haven't taken yet
positions = Position.objects.filter(ballot=idinternal.ballot)
if position.slug == "noobj":
positions = positions.filter(noobj=1)
elif position.slug == "yes":
positions = positions.filter(yes=1)
elif position.slug == "abstain":
positions = positions.filter(models.Q(abstain=1)|models.Q(abstain=2))
elif position.slug == "recuse":
positions = positions.filter(recuse=1)
elif position.slug == "discuss":
positions = positions.filter(models.Q(discuss=1)|models.Q(discuss=2))
assert position.slug != "norecord"
found = False
for p in positions:
if not BallotPositionDocEvent.objects.filter(doc=d, type="changed_ballot_position", pos=position, ad=iesg_login_to_person(p.ad)):
login = p.ad
found = True
break
if not found:
# in even more trouble, we can try and see if it
# belongs to a nearby discuss
if position.slug == "discuss":
index_c = list(document_comments).index(c)
start = c.datetime()
end = c.datetime() + datetime.timedelta(seconds=30 * 60)
for i, x in enumerate(document_comments):
if (x.ballot == DocumentComment.BALLOT_DISCUSS
and (c.datetime() <= x.datetime() <= end
or abs(index_c - i) <= 2)
and not iesg_login_is_secretary(x.created_by)):
login = x.created_by
found = True
if not found:
print "BALLOT BY SECRETARIAT", login
e = BallotPositionDocEvent()
e.type = "changed_ballot_position"
e.ad = iesg_login_to_person(login)
last_pos = d.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=e.ad)
e.pos = position
e.discuss = last_pos.discuss if last_pos else ""
e.discuss_time = last_pos.discuss_time if last_pos else None
if e.pos_id == "discuss" and not e.discuss_time:
# in a few cases, we don't have the discuss
# text/time, fudge the time so it's not null
e.discuss_time = c.datetime()
e.comment = last_pos.comment if last_pos else ""
e.comment_time = last_pos.comment_time if last_pos else None
save_docevent(d, e, c)
handled = True
# ballot discusses/comments
if c.ballot in (DocumentComment.BALLOT_DISCUSS, DocumentComment.BALLOT_COMMENT):
skip = False
e = BallotPositionDocEvent()
e.type = "changed_ballot_position"
e.ad = iesg_login_to_person(c.created_by)
last_pos = d.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=e.ad)
e.pos = last_pos.pos if last_pos else ballot_position_mapping[None]
c.comment_text = re_comment_discuss_by_tag.sub("", c.comment_text).strip()
if c.ballot == DocumentComment.BALLOT_DISCUSS:
e.discuss = c.comment_text
if not e.discuss and (not last_pos or not last_pos.discuss):
skip = True # skip some bogus empty entries
e.discuss_time = c.datetime()
e.comment = last_pos.comment if last_pos else ""
e.comment_time = last_pos.comment_time if last_pos else None
# put header into description
c.comment_text = "[Ballot discuss]\n" + c.comment_text
else:
e.discuss = last_pos.discuss if last_pos else ""
e.discuss_time = last_pos.discuss_time if last_pos else None
if e.pos_id == "discuss" and not e.discuss_time:
# in a few cases, we don't have the discuss
# text/time, fudge the time so it's not null
e.discuss_time = c.datetime()
e.comment = c.comment_text
if not e.comment and (not last_pos or not last_pos.comment):
skip = True # skip some bogus empty entries
e.comment_time = c.datetime()
# put header into description
c.comment_text = "[Ballot comment]\n" + c.comment_text
# there are some bogus copies where a secretary has the
# same discuss comment as an AD
if iesg_login_is_secretary(c.created_by) and DocumentComment.objects.filter(ballot=c.ballot, document=c.document).exclude(created_by=c.created_by):
skip = True
if not skip:
save_docevent(d, e, c)
handled = True
# last call requested
match = re_last_call_requested.search(c.comment_text)
if match:
e = DocEvent(type="requested_last_call")
save_docevent(d, e, c)
handled = True
# state changes
match = re_state_changed.search(c.comment_text)
if match:
e = DocEvent(type="changed_document")
save_docevent(d, e, c)
handled = True
# note changed
match = re_note_changed.search(c.comment_text)
if match:
# watch out for duplicates of which the old data's got many
if c.comment_text != last_note_change_text:
last_note_change_text = c.comment_text
e = DocEvent(type="changed_document")
save_docevent(d, e, c)
handled = True
# draft added
match = re_draft_added.search(c.comment_text)
if match:
# watch out for extraneous starts, the old data contains
# some phony ones
if not started_iesg_process:
started_iesg_process = c.comment_text
e = DocEvent(type="started_iesg_process")
save_docevent(d, e, c)
handled = True
# new version
if c.comment_text == "New version available":
e = NewRevisionDocEvent(type="new_revision", rev=c.version)
c.comment_text = "Added new revision"
save_docevent(d, e, c)
handled = True
# resurrect requested
match = re_resurrection_requested.search(c.comment_text)
if match:
e = DocEvent(type="requested_resurrect")
save_docevent(d, e, c)
handled = True
# completed resurrect
match = re_completed_resurrect.search(c.comment_text)
if match:
e = DocEvent(type="completed_resurrect")
save_docevent(d, e, c)
handled = True
# document expiration
if c.comment_text == "Document is expired by system":
e = DocEvent(type="expired_document")
c.comment_text = "Document has expired"
save_docevent(d, e, c)
handled = True
# approved document
match = re_document_approved.search(c.comment_text)
if match:
e = DocEvent(type="iesg_approved")
save_docevent(d, e, c)
handled = True
# disapproved document
match = re_document_disapproved.search(c.comment_text)
if match:
e = DocEvent(type="iesg_disapproved")
save_docevent(d, e, c)
handled = True
# some changes can be bundled - this is not entirely
# convenient, especially since it makes it hard to give
# each a type, so unbundle them
if not handled:
unhandled_lines = []
for line in c.comment_text.split("<br>"):
line = line.replace(" ", " ")
# status date changed
match = re_status_date_changed.search(line)
if match:
e = DocEvent(type="added_comment")
e.desc = line
save_docevent(d, e, c)
handled = True
# AD/job owner changed
match = re_responsible_ad_changed.search(line)
if match:
e = DocEvent(type="changed_document")
e.desc = line
save_docevent(d, e, c)
handled = True
# intended standard level changed
match = re_intended_status_changed.search(line)
if match:
e = DocEvent(type="changed_document")
e.desc = line
save_docevent(d, e, c)
handled = True
# state change notice
match = re_state_change_notice.search(line)
if match:
e = DocEvent(type="changed_document")
e.desc = line
save_docevent(d, e, c)
handled = True
# area acronym
match = re_area_acronym_changed.search(line)
if match:
e = DocEvent(type="changed_document")
e.desc = line
save_docevent(d, e, c)
handled = True
# multiline change bundles end with a single "by xyz" that we skip
if not handled and not line.startswith("by <b>"):
unhandled_lines.append(line)
if handled:
c.comment_text = "<br>".join(unhandled_lines)
if c.comment_text:
if "Due date has been changed" not in c.comment_text:
print "DID NOT HANDLE multi-line comment %s '%s'" % (c.id, c.comment_text.replace("\n", " ").replace("\r", "")[0:80])
# all others are added as comments
if not handled:
e = DocEvent(type="added_comment")
save_docevent(d, e, c)
# stop typical comments from being output
typical_comments = [
"Document Shepherd Write-up for %s" % d.name,
"Who is the Document Shepherd for this document",
"We understand that this document doesn't require any IANA actions",
"IANA questions",
"IANA has questions",
"IANA comments",
"IANA Comments",
"IANA Evaluation Comment",
"IANA Last Call Comments",
"ublished as RFC",
"A new comment added",
"Due date has been changed",
"Due date has been changed",
"by <b>",
"AD-review comments",
"IANA Last Call",
"Subject:",
"Merged with",
]
for t in typical_comments:
if t in c.comment_text:
handled = True
break
if not handled:
print (u"DID NOT HANDLE comment %s '%s' by %s" % (c.id, c.comment_text.replace("\n", " ").replace("\r", "")[0:80], c.created_by)).encode("utf-8")
e = d.latest_event()
if e:
made_up_date = e.time
else:
made_up_date = d.time
made_up_date += datetime.timedelta(seconds=1)
e = d.latest_event(TelechatDocEvent, type="scheduled_for_telechat")
telechat_date = e.telechat_date if e else None
if not idinternal.agenda:
idinternal.telechat_date = None # normalize
if idinternal.telechat_date != telechat_date:
e = TelechatDocEvent(type="scheduled_for_telechat",
telechat_date=idinternal.telechat_date,
returning_item=bool(idinternal.returning_item))
# a common case is that it has been removed from the
# agenda automatically by a script without a notice in the
# comments, in that case the time is simply the day after
# the telechat
e.time = telechat_date + datetime.timedelta(days=1) if telechat_date and not idinternal.telechat_date else made_up_date
e.by = system
args = ("Placed on", idinternal.telechat_date) if idinternal.telechat_date else ("Removed from", telechat_date)
e.doc = d
e.desc = "%s agenda for telechat - %s" % args
e.save()
try:
# sad fact: some ballots haven't been generated yet
ballot = idinternal.ballot
except BallotInfo.DoesNotExist:
ballot = None
if ballot:
e = d.docevent_set.filter(type__in=("changed_ballot_position", "sent_ballot_announcement", "requested_last_call")).order_by('-time')[:1]
if e:
position_date = e[0].time + datetime.timedelta(seconds=1)
else:
position_date = made_up_date
# make sure we got all the positions
existing = BallotPositionDocEvent.objects.filter(doc=d, type="changed_ballot_position").order_by("-time", '-id')
for p in Position.objects.filter(ballot=ballot):
# there are some bogus ones
if iesg_login_is_secretary(p.ad):
continue
ad = iesg_login_to_person(p.ad)
if p.noobj > 0:
pos = ballot_position_mapping["No Objection"]
elif p.yes > 0:
pos = ballot_position_mapping["Yes"]
elif p.abstain > 0:
pos = ballot_position_mapping["Abstain"]
elif p.recuse > 0:
pos = ballot_position_mapping["Recuse"]
elif p.discuss > 0:
pos = ballot_position_mapping["Discuss"]
else:
pos = ballot_position_mapping[None]
found = False
for x in existing:
if x.ad == ad and x.pos == pos:
found = True
break
if not found:
e = BallotPositionDocEvent()
e.type = "changed_ballot_position"
e.doc = d
e.time = position_date
e.by = system
e.ad = ad
last_pos = d.latest_event(BallotPositionDocEvent, type="changed_ballot_position", ad=e.ad)
e.pos = pos
e.discuss = last_pos.discuss if last_pos else ""
e.discuss_time = last_pos.discuss_time if last_pos else None
if e.pos_id == "discuss" and not e.discuss_time:
# in a few cases, we don't have the discuss
# text/time, fudge the time so it's not null
e.discuss_time = e.time
e.comment = last_pos.comment if last_pos else ""
e.comment_time = last_pos.comment_time if last_pos else None
if last_pos:
e.desc = u"[Ballot Position Update] Position for %s has been changed to %s from %s" % (ad.plain_name(), pos.name, last_pos.pos.name)
else:
e.desc = u"[Ballot Position Update] New position, %s, has been recorded for %s" % (pos.name, ad.plain_name())
e.save()
# make sure we got the ballot issued event
if ballot.ballot_issued and not d.docevent_set.filter(type="sent_ballot_announcement"):
position = d.docevent_set.filter(type=("changed_ballot_position")).order_by('time', 'id')[:1]
if position:
sent_date = position[0].time
else:
sent_date = made_up_date
e = DocEvent()
e.type = "sent_ballot_announcement"
e.doc = d
e.time = sent_date
e.by = system
e.desc = "Ballot has been issued"
e.save()
# make sure the comments and discusses are updated
positions = list(BallotPositionDocEvent.objects.filter(doc=d).order_by("-time", '-id'))
for c in IESGComment.objects.filter(ballot=ballot):
ad = iesg_login_to_person(c.ad)
for p in positions:
if p.ad == ad:
if p.comment != c.text:
p.comment = c.text
p.comment_time = c.date if p.time.date() != c.date else p.time
p.save()
break
for c in IESGDiscuss.objects.filter(ballot=ballot):
ad = iesg_login_to_person(c.ad)
for p in positions:
if p.ad == ad:
if p.discuss != c.text:
p.discuss = c.text
p.discuss_time = c.date if p.time.date() != c.date else p.time
p.save()
break
# if any of these events have happened, they're closer to
# the real time
e = d.docevent_set.filter(type__in=("requested_last_call", "sent_last_call", "sent_ballot_announcement", "iesg_approved", "iesg_disapproved")).order_by('time')[:1]
if e:
text_date = e[0].time - datetime.timedelta(seconds=1)
else:
text_date = made_up_date
if idinternal.ballot.approval_text:
e, _ = WriteupDocEvent.objects.get_or_create(type="changed_ballot_approval_text", doc=d,
defaults=dict(by=system))
e.text = idinternal.ballot.approval_text
e.time = text_date
e.desc = "Ballot approval text was added"
e.save()
if idinternal.ballot.last_call_text:
e, _ = WriteupDocEvent.objects.get_or_create(type="changed_last_call_text", doc=d,
defaults=dict(by=system))
e.text = idinternal.ballot.last_call_text
e.time = text_date
e.desc = "Last call text was added"
e.save()
if idinternal.ballot.ballot_writeup:
e, _ = WriteupDocEvent.objects.get_or_create(type="changed_ballot_writeup_text", doc=d,
defaults=dict(by=system))
e.text = idinternal.ballot.ballot_writeup
e.time = text_date
e.desc = "Ballot writeup text was added"
e.save()
ballot_set = idinternal.ballot_set()
if len(ballot_set) > 1:
others = sorted(b.draft.filename for b in ballot_set if b != idinternal)
desc = u"This was part of a ballot set with: %s" % ",".join(others)
DocEvent.objects.get_or_create(type="added_comment", doc=d, desc=desc,
defaults=dict(time=made_up_date,
by=system))
# fix tags
sync_tag(d, idinternal.via_rfc_editor, tag_via_rfc_editor)
n = idinternal.cur_sub_state and idinternal.cur_sub_state.sub_state
for k, v in substate_mapping.iteritems():
sync_tag(d, k == n, v)
# currently we ignore prev_sub_state
sync_tag(d, idinternal.approved_in_minute, tag_approved_in_minute)
all_drafts = InternetDraft.objects.all().order_by('pk').select_related()
if import_docs_from:
all_drafts = all_drafts.filter(last_modified_date__gte=import_docs_from) | all_drafts.filter(idinternal__event_date__gte=import_docs_from)
if document_name_to_import:
if document_name_to_import.startswith("rfc"):
all_drafts = all_drafts.filter(rfc_number=document_name_to_import[3:])
else:
all_drafts = all_drafts.filter(filename=document_name_to_import)
for index, o in enumerate(all_drafts.iterator()):
print "importing", o.id_document_tag, o.filename, index, "ballot %s" % o.idinternal.ballot_id if o.idinternal and o.idinternal.ballot_id else ""
try:
d = Document.objects.get(name=o.filename)
except Document.DoesNotExist:
d = Document(name=o.filename)
d.time = o.revision_date
d.type = type_draft
d.title = o.title
d.group = Group.objects.get(acronym=o.group.acronym)
d.states = []
d.set_state(state_mapping[o.status.status])
# try guess stream to have a default for old submissions
d.stream = None
if o.filename.startswith("draft-iab-"):
d.stream = stream_mapping["IAB"]
elif o.filename.startswith("draft-irtf-"):
d.stream = stream_mapping["IRTF"]
elif o.idinternal and o.idinternal.via_rfc_editor:
d.stream = stream_mapping["INDEPENDENT"]
elif d.name.startswith("draft-ietf-") and (d.group.type_id != "individ" or state_mapping[o.status.status].slug == "rfc" or o.idinternal):
d.stream = stream_mapping["IETF"]
sid = StreamedID.objects.filter(draft=o)
if sid and sid[0].stream:
d.stream = stream_mapping[sid[0].stream.name]
try:
s = StateOld.objects.get(stateobjectrelation__content_type=old_internetdraft_content_type_id,
stateobjectrelation__content_id=o.pk)
except StateOld.DoesNotExist:
s = None
if s:
try:
# there may be a mismatch between the stream type and the
# state because of a bug in the ietfworkflows code so try
# first without type constraint
new_s = State.objects.get(name=s.name)
except State.MultipleObjectsReturned:
new_s = State.objects.get(type="draft-stream-%s" % d.stream_id, name=s.name)
# fix some bugs in the old data
skip = False
if s.name == "WG Document" and d.group.type_id == "individ":
skip = True
if d.name.startswith("draft-ietf"):
if d.name not in ("draft-ietf-proto-wgchair-tracker-ext", "draft-ietf-proto-iab-irtf-tracker-ext", "draft-ietf-sipping-nat-scenarios", "draft-ietf-sipping-sip-offeranswer"):
skip = False
group_acronym = d.name.split("-")[2]
if group_acronym == "pppext":
group_acronym = "trill"
d.group = Group.objects.get(acronym=group_acronym)
if not skip:
d.set_state(new_s)
# there was a bug in ietfworkflows so the group wasn't set on adopted documents
if s.name in ("Call for Adoption by WG Issued", "Adopted by a WG") and d.group.type_id == "individ" and o.replaced_by and o.replaced_by.group:
d.group = Group.objects.get(acronym=o.replaced_by.group.acronym)
d.rev = o.revision_display()
d.abstract = o.abstract
d.pages = o.txt_page_count
d.intended_std_level = intended_std_level_mapping[o.intended_status.intended_status]
d.ad = None
d.shepherd = old_person_to_person(o.shepherd) if o.shepherd else None
d.notify = ""
d.external_url = ""
d.note = ""
d.internal_comments = o.comments or ""
d.save()
# make sure our alias is updated
d_alias = alias_doc(d.name, d)
# RFC alias
if o.rfc_number:
alias_doc("rfc%s" % o.rfc_number, d)
# authors
d.authors.clear()
authors_from_dump = author_dump.get(d.name)
if authors_from_dump:
for i, a in enumerate(authors_from_dump):
name, email = a
try:
e = Email.objects.get(address__iexact=email)
except Email.DoesNotExist:
e = Email(address=email)
ps = Person.objects.filter(alias__name=name)
if ps:
p = ps[0]
else:
_, first, _, last, _ = name_parts(name)
first = first.replace(".", "")
ps = Person.objects.filter(name__regex=u".*%s.*%s.*" % (first, last))
if len(ps) == 1:
p = ps[0]
else:
from ietf.utils import unaccent
p = Person.objects.create(name=name, ascii=unaccent.asciify(name))
Alias.objects.create(name=p.name, person=p)
if p.ascii != p.name:
Alias.objects.create(name=p.ascii, person=p)
e.person = p