forked from apache/attic-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retire.py
executable file
·168 lines (148 loc) · 5.62 KB
/
retire.py
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
#!/usr/bin/env python3
"""
Script to create retirement files for a project.
Input:
- https://whimsy.apache.org/public/committee-retired.json
- https://lists.apache.org/api/preferences.lua
- xdocs/projects/_template.xml
- _template.jira
Output:
- xdocs/flagged/<pid> (created)
- xdocs/projects/<pid>.xml (created)
- xdocs/stylesheets/project.xml (updated)
- cwiki_retired/<wiki_id>.txt (created)
- <pid>.jira.tmp (created) - this is for pasting into an Attic JIRA issue
N.B. The generated pid.xml file may need tweaking
"""
import sys
import os.path
from os.path import dirname, abspath, join
from inspect import getsourcefile
from string import Template
import os
import re
from collections import defaultdict
from urlutils import loadyaml, loadjson
if len(sys.argv) == 1:
print("Please provide a list of project ids")
sys.exit(1)
CWIKI='https://cwiki.apache.org/confluence/display/'
CWIKI_INFO='https://cwiki.apache.org/confluence/rest/api/space/?type=global&limit=1000'
WIKI_KEYS = defaultdict(list) # key = project name, value = list of possible spaces
for entry in loadjson(CWIKI_INFO)['results']:
WIKI_KEYS[entry['name'].lower().replace('apache ', '')].append(entry['key'])
JIRA='https://issues.apache.org/jira/rest/api/2/project'
MYHOME = dirname(abspath(getsourcefile(lambda:0)))
PROJECTS = join((MYHOME), 'xdocs', 'projects')
SYLESHEETS = join((MYHOME), 'xdocs', 'stylesheets')
FLAGGED = join((MYHOME), 'xdocs', 'flagged')
CWIKI_RETIRED = join((MYHOME), 'cwiki_retired')
# get details of the retired projects
RETIREES = loadyaml('https://whimsy.apache.org/public/committee-retired.json')['retired']
lists = {}
for host,names in loadyaml('https://lists.apache.org/api/preferences.lua')['lists'].items():
proj = host.replace('.apache.org','')
if proj in RETIREES:
lists[proj] = list(names.keys())
def list_jira(pid):
jira = loadjson(JIRA)
jiras = []
for project in jira:
key = project['key']
catname = ''
if 'projectCategory' in project:
catname = project['projectCategory']['name']
if pid.upper() == key:
jiras.append(key)
elif catname.lower() == pid:
jiras.append(key)
return jiras
# updates xdocs/stylesheets/project.xml
# <li><a href="/projects/abdera.html">Abdera</a></li>
def update_stylesheet(pid):
xmlfile = join(SYLESHEETS,'project.xml')
xmlfilet = join(SYLESHEETS,'project.xml.t')
print("Updating %s" % xmlfile)
found = False
with open(xmlfile,'r', encoding='utf-8') as r, open(xmlfilet,'w', encoding='utf-8') as w:
for l in r:
if not found:
m = re.search(r'^(\s+<li><a href="/projects/)([^.]+)(.html">)[^<]+(</a></li>)', l)
if m:
stem = m.group(2)
if stem == pid:
print("Already present in projects.xml")
print(l)
w.close()
os.remove(xmlfilet)
return
if stem > pid: # Found insertion point
found = True
name = RETIREES[pid]['display_name']
w.write("%s%s%s%s%s\n" % (m.group(1), pid, m.group(3), name, m.group(4)))
w.write(l) # write the original line
if found:
print("Successfully added %s to %s" % (pid, xmlfile))
os.system("diff %s %s" % (xmlfile, xmlfilet))
os.rename(xmlfilet, xmlfile)
else:
print("Could not find where to add %s" % pid)
# create JIRA template
def create_jira_template(pid):
outfile = join(MYHOME, "%s.jira.tmp" % pid)
print("Creating %s" % outfile)
with open(join(MYHOME, '_template.jira'), 'r', encoding='utf-8') as t:
template = Template(t.read())
out = template.substitute(tlpid = pid)
with open(outfile, 'w', encoding='utf-8') as o:
o.write(out)
# create the project.xml file from the template
def create_project(pid):
outfile = join(PROJECTS, "%s.xml" % pid)
print("Creating %s" % outfile)
with open(join(PROJECTS, '_template.xml'), 'r', encoding='utf-8') as t:
template = Template(t.read())
meta = RETIREES[pid]
mnames = lists[pid]
mnames.remove('dev')
jiras = list_jira(pid)
out = template.substitute(tlpid = pid,
FullName = meta['display_name'],
Month_Year = meta['retired'],
mail_names = ",".join(sorted(mnames)),
jira_names = ",".join(sorted(jiras)),
description = meta.get('description', 'TBA'))
with open(outfile, 'w', encoding='utf-8') as o:
o.write(out)
os.system("svn add %s" % outfile)
print("Check XML file for customisations such as JIRA and mailing lists")
def find_wiki(pid):
found = []
for k, v in WIKI_KEYS.items():
if k == pid or (k.startswith(pid)): # and not k == valid project name
found += v
return found
def check_wiki(pid):
for wiki in find_wiki(pid):
flagname = wiki.lower()
flagfile = join(CWIKI_RETIRED, f"{flagname}.txt")
with open(flagfile, 'w', encoding='utf-8') as w:
if not flagname == pid:
w.write(pid)
w.write("\n")
os.system("svn add %s" % flagfile)
for arg in sys.argv[1:]:
print("Processing "+arg)
if not arg in RETIREES:
print("%s does not appear to be a retired project" % arg)
continue
flagdir = join(FLAGGED, arg)
if os.path.exists(flagdir):
print("flagged/%s already exists" % arg)
continue
create_jira_template(arg)
os.mkdir(flagdir)
os.system("svn add %s" % flagdir)
create_project(arg)
update_stylesheet(arg)
check_wiki(arg)