-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcreate-sitemap.py
48 lines (41 loc) · 1.43 KB
/
create-sitemap.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
import os
BASE_URL = 'http://docs.buildbot.net/'
def find(dir, exclude=[]):
for (dirpath, dirnames, filenames) in os.walk(dir):
for excl in exclude:
if excl in dirnames:
del dirnames[dirnames.index(excl)]
for fn in filenames:
yield os.path.join(dirpath, fn)
def process(baseurl, dir, f):
if dir.endswith('/current'):
priority = 1.0
elif dir.endswith('/latest'):
priority = 0.7
else:
priority = 0.5
for filename in find(dir, exclude='reference _static _sources'.split()):
ignored = False
for ignore in 'search.html .buildinfo objects.inv searchindex.js full.html'.split():
if ignore in filename:
ignored = True
break
if not ignored:
url = BASE_URL + filename[5:]
f.write("<url><loc>%s</loc><priority>%s</priority></url>\n" % (url, priority))
dirs = [ 'docs/%s' % x for x in os.listdir('docs') ]
dirs = [ x for x in dirs if os.path.isdir(x) and not os.path.islink(x) ]
dirs += [ 'docs/current', 'docs/latest' ]
f = open('docs/sitemap.xml', 'w')
f.write("""\
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
""")
for dir in dirs:
process(BASE_URL, dir, f)
f.write("""\
</urlset>
""")
f.close()
if os.stat('docs/sitemap.xml').st_size > 10*1024*1024:
print("docs/sitemap.xml is too bug (greater than 10MB)")