-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-master-index.py
executable file
·53 lines (39 loc) · 1.48 KB
/
make-master-index.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
#!/usr/bin/env python3
"""
This constructs the Master-Index file (the plain text one, not the XML).
It works by walking the directory tree, extracting all the Index files,
and concatenating them together. It adds a # directory header at the top
of each Index file, and increases the # header depth (of files, etc) by
one.
Usage: make-master-index.py [ htdocs ]
The argument is optional, and defaults to /var/ifarchive/htdocs.
(This used to read the ls-lR file, but not any more.)
In normal Archive operation:
/var/ifarchive/bin/make-master-index.py > if-archive/Master-Index
"""
import sys
import os, os.path
import re
rootdir = '/var/ifarchive/htdocs'
if len(sys.argv) >= 2:
rootdir = sys.argv[1]
rootarchdir = os.path.join(rootdir, 'if-archive')
dirre = re.compile('^if-archive.*:$')
for (dirpath, dirnames, filenames) in os.walk(rootarchdir):
if 'Index' in filenames:
currentdir = os.path.relpath(dirpath, start=rootdir)
basename = (currentdir + ':')
print()
print('# ' + basename)
filename = (rootdir + '/' + currentdir + '/Index')
fl = open(filename, 'r', encoding='utf-8')
for subln in fl.readlines():
if subln.startswith('#'):
subln = '#'+subln
print(subln, end='')
fl.close()
str = None
print()
print('------------------------------------------------------')
# Ensure that we visit in Unicode sort order (not case-folded).
dirnames.sort()