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
|
#!/usr/bin/python3
import os, pwd, re, sys
from subprocess import call, check_call
def extract_tar(tarfile,rootdir):
"""Extract files from a tar archive.
Arguments:
tarfile -- file name of tar archive
rootdir -- directory into which the archive is extracted
"""
cmd = ["tar","--extract"]
if tarfile.endswith(".gz"):
cmd.append("--gzip")
elif tarfile.endswith(".bz2"):
cmd.append("--bzip")
cmd.append("--file")
cmd.append(os.path.abspath(tarfile))
check_call(cmd, cwd=rootdir, universal_newlines=True)
def wget_localhost_files(serverbase,tempdir):
"""Use wget to obtain files from localhost server.
server -- root of file tree on http://localhost
tempdir -- directory into which the files are placed
"""
cmd = ["wget", "--quiet",
"--recursive", "--no-parent",
"--domains=localhost",
"http://localhost/" + serverbase]
retcode = call(cmd, cwd=tempdir, universal_newlines=True)
if retcode not in [0, 8]:
raise RuntimeError("wget failed")
def find_file_root(dirname,filename):
"""Recursively search the dir for a file."""
while 1:
#print "Considering " + dirname
if not os.path.isdir(dirname): return None
files = os.listdir(dirname)
if len(files) == 1:
dirname = os.path.abspath(os.path.join(dirname,files[0]))
else:
if filename in files:
return dirname
return None
def list_doc_files(rootdir,src_rootdir):
"""List files comprising the Boost documentation tree.
Returns list of filenames, relative to given rootdir, that
make up the Boost documentation. This is all files that:
(a) are not in subdir $rootdir/boost AND
(b) endswith .html or .htm OR
is a file in $src_rootdir
"""
doc_files = []
for dirpath, dirs, files in os.walk(rootdir):
if dirpath == rootdir:
dirs.remove("boost")
for filename in files:
#print "Considering: ", filename
filepath = os.path.abspath(os.path.join(dirpath,filename))
filepath = filepath.replace(rootdir,"",1)
if filepath.startswith("/"):
filepath = filepath[1:]
keep = filename.endswith(".html") or \
filename.endswith(".htm") or \
os.path.exists(os.path.join(src_rootdir,filename))
if keep:
doc_files.append(filepath)
#print filepath
return doc_files
def main():
if (len(sys.argv) != 3):
print("Usage: %s tarfile boost_x_y_z" % sys.argv[0])
return 1
tarfile, path = sys.argv[1:3]
tar_extract_root = os.path.expanduser("~/public_html")
url_root = "~" + pwd.getpwuid(os.getuid()).pw_name + "/" + path + "/index.html"
extract_tar(tarfile, tar_extract_root)
check_call(["chmod", "-R", "+x", tar_extract_root+'/'+path])
wget_localhost_files(url_root, "/tmp")
boost_dir = find_file_root("/tmp/localhost", "boost")
files = list_doc_files(boost_dir,
os.path.join(tar_extract_root,path))
files.sort()
for f in files:
print(f)
main()
|