forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
118 lines (93 loc) · 3.82 KB
/
utils.py
File metadata and controls
118 lines (93 loc) · 3.82 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
# Copyright The IETF Trust 2014-2020, All Rights Reserved
# -*- coding: utf-8 -*-
from textwrap import dedent
from ietf.ipr.mail import process_response_email
from ietf.ipr.models import IprDocRel
import debug # pyflakes:ignore
def get_genitive(name):
"""Return the genitive form of name"""
return name + "'" if name.endswith('s') else name + "'s"
def get_ipr_summary(disclosure):
"""Return IPR related document names as a formatted string"""
names = []
for doc in disclosure.docs.all():
if doc.name.startswith('rfc'):
names.append('RFC {}'.format(doc.name[3:]))
else:
names.append(doc.name)
if disclosure.other_designations:
names.append(disclosure.other_designations)
if not names:
summary = ''
elif len(names) == 1:
summary = names[0]
elif len(names) == 2:
summary = " and ".join(names)
elif len(names) > 2:
summary = ", ".join(names[:-1]) + ", and " + names[-1]
return summary if len(summary) <= 128 else summary[:125]+'...'
def iprs_from_docs(docs,**kwargs):
"""Returns a list of IPRs related to docs"""
iprdocrels = []
for document in docs:
if document.ipr(**kwargs):
iprdocrels += document.ipr(**kwargs)
return list(set([i.disclosure for i in iprdocrels]))
def related_docs(doc, relationship=('replaces', 'obs'), reverse_relationship=("became_rfc",)):
"""Returns list of related documents"""
results = [doc]
rels = doc.all_relations_that_doc(relationship)
for rel in rels:
rel.target.related = rel
rel.target.relation = rel.relationship.revname
results += [x.target for x in rels]
rev_rels = doc.all_relations_that(reverse_relationship)
for rel in rev_rels:
rel.source.related = rel
rel.source.relation = rel.relationship.name
results += [x.source for x in rev_rels]
return list(set(results))
def generate_draft_recursive_txt():
docipr = {}
for o in IprDocRel.objects.filter(disclosure__state='posted').select_related('document'):
doc = o.document
name = doc.name
related_set = set(doc) | set(doc.all_related_that_doc(('obs', 'replaces')))
for related in related_set:
name = related.name
if name.startswith("rfc"):
name = name.upper()
if not name in docipr:
docipr[name] = []
docipr[name].append(o.disclosure_id)
lines = [ "# Machine-readable list of IPR disclosures by Internet-Draft name" ]
for name, iprs in docipr.items():
lines.append(name + "\t" + "\t".join(str(ipr_id) for ipr_id in sorted(iprs)))
data = '\n'.join(lines)
filename = '/a/ietfdata/derived/ipr_draft_recursive.txt'
with open(filename, 'w') as f:
f.write(data)
def ingest_response_email(message: bytes):
from ietf.api.views import EmailIngestionError # avoid circular import
try:
result = process_response_email(message)
except Exception as err:
raise EmailIngestionError(
"Datatracker IPR email ingestion error",
email_body=dedent("""\
An error occurred while ingesting IPR email into the Datatracker. The original message is attached.
{error_summary}
"""),
email_original_message=message,
email_attach_traceback=True,
) from err
if result is None:
raise EmailIngestionError(
"Datatracker IPR email ingestion rejected",
email_body=dedent("""\
A message was rejected while ingesting IPR email into the Datatracker. The original message is attached.
{error_summary}
"""),
email_original_message=message,
email_attach_traceback=True,
)