summaryrefslogtreecommitdiff
blob: 5e728583f3cd4e71e0848404a987f4de411a9aa8 (plain)
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
#!/usr/bin/python2.2

# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# Author Karl Trygve Kalleberg <karltk@gentoo.org>
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/bin/dohtml,v 1.9 2003/02/22 16:59:08 carpaski Exp $
#
# Typical usage:
# dohtml -r docs/*
#  - put all files and directories in docs into /usr/share/doc/${PF}/html
# dohtml foo.html
#  - put foo.html into /usr/share/doc/${PF}/html
#
#
# Detailed usage:
# dohtml <list-of-files> 
#  - will install the files in the list of files (space-separated list) into 
#    /usr/share/doc/${PF}/html, provided the file ends in .html, .png, .jpg 
#     or .css
# dohtml -r <list-of-files-and-directories>
#  - will do as 'dohtml', but recurse into all directories, as long as the 
#    directory name is not CVS
# dohtml -A jpe,java [-r] <list-of-files[-and-directories]>
#  - will do as 'dohtml' but add .jpe,.java (default filter list is
#    added to your list)
# dohtml -a png,gif,html,htm [-r] <list-of-files[-and-directories]>
#  - will do as 'dohtml' but filter on .png,.gif,.html,.htm (default filter 
#    list is ignored)
# dohtml -x CVS,SCCS,RCS -r <list-of-files-and-directories>
#  - will do as 'dohtml -r', but ignore directories named CVS, SCCS, RCS
#

import os
import sys
import string
import os.path

def dodir(path):
	os.system("install -d " + path)

def dofile(src,dst):

	os.system("install -m0644 " + src + " " + dst)
		
def install(basename, dirname, recurse=0, prefix=""):

	fullpath = basename
	if prefix: fullpath = prefix + "/" + fullpath
	if dirname: fullpath = dirname + "/" + fullpath
		
	if DOCDESTTREE:
		destdir = D + "usr/share/doc/" + PF + "/" + DOCDESTTREE + "/" + prefix
	else:
		destdir = D + "usr/share/doc/" + PF + "/html/" + prefix

#	print fullpath, destdir
	
	if os.path.isfile(fullpath):
		ext = os.path.splitext(basename)[1]
		if len(ext) and ext[1:] in allowed_exts:
			dodir(destdir)
			dofile(fullpath, destdir + "/" + basename)
	elif recurse and os.path.isdir(fullpath) and \
	     basename not in disallowed_dirs:
		for i in os.listdir(fullpath):
			pfx = basename
			if prefix: pfx = prefix + "/" + pfx
			install(i, dirname, recurse, pfx)

skip = 0
files = []
D=os.environ["D"]
PF=os.environ["PF"]
DOCDESTTREE=os.environ["DOCDESTTREE"]
allowed_exts = [ 'png', 'gif', 'html', 'htm', 'jpg', 'css', 'js' ]
disallowed_dirs = [ 'CVS' ]
recurse = 0

for i in xrange(1,len(sys.argv)):
	if skip:
		skip = skip - 1
		continue
		
	if sys.argv[i]	== "-A":
		allowed_exts = allowed_exts+string.split(sys.argv[i + 1], ',')
		skip = 1
		continue
	elif sys.argv[i]	== "-a":
		allowed_exts = string.split(sys.argv[i + 1], ',')
		skip = 1
		continue
	elif sys.argv[i] == "-x":
		disallowed_dirs = string.split(sys.argv[i + 1], ',')
		skip = 1
		continue
	elif sys.argv[i] == "-r":
		recurse = 1
		continue
	files.append(sys.argv[i])

for i in files:
	basename = os.path.basename(i)
	dirname  = os.path.dirname(i)
	install(basename, dirname, recurse)