2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
8 # - put all files and directories in docs into /usr/share/doc/${PF}/html
10 # - put foo.html into /usr/share/doc/${PF}/html
14 # dohtml <list-of-files>
15 # - will install the files in the list of files (space-separated list) into
16 # /usr/share/doc/${PF}/html, provided the file ends in .htm, .html, .css,
17 # .js, ,gif, .jpeg, .jpg, or .png.
18 # dohtml -r <list-of-files-and-directories>
19 # - will do as 'dohtml', but recurse into all directories, as long as the
20 # directory name is not CVS
21 # dohtml -A jpe,java [-r] <list-of-files[-and-directories]>
22 # - will do as 'dohtml' but add .jpe,.java (default filter list is
24 # dohtml -a png,gif,html,htm [-r] <list-of-files[-and-directories]>
25 # - will do as 'dohtml' but filter on .png,.gif,.html,.htm (default filter
27 # dohtml -x CVS,SCCS,RCS -r <list-of-files-and-directories>
28 # - will do as 'dohtml -r', but ignore directories named CVS, SCCS, RCS
31 from __future__ import print_function
37 os.spawnlp(os.P_WAIT, "install", "install", "-d", path)
40 os.spawnlp(os.P_WAIT, "install", "install", "-m0644", src, dst)
43 cmd = "source '%s/isolated-functions.sh' ; " % \
44 os.environ["PORTAGE_BIN_PATH"]
46 cmd += "eqawarn \"%s\" ; " % line
47 os.spawnlp(os.P_WAIT, "bash", "bash", "-c", cmd)
49 skipped_directories = []
51 def install(basename, dirname, options, prefix=""):
54 fullpath = prefix + "/" + fullpath
56 fullpath = dirname + "/" + fullpath
58 if options.DOCDESTTREE:
59 destdir = options.ED + "usr/share/doc/" + options.PF + "/" + options.DOCDESTTREE + "/" + options.doc_prefix + "/" + prefix
61 destdir = options.ED + "usr/share/doc/" + options.PF + "/html/" + options.doc_prefix + "/" + prefix
63 if not os.path.exists(fullpath):
64 sys.stderr.write("!!! dohtml: %s does not exist\n" % fullpath)
66 elif os.path.isfile(fullpath):
67 ext = os.path.splitext(basename)[1]
68 if (len(ext) and ext[1:] in options.allowed_exts) or basename in options.allowed_files:
70 dofile(fullpath, destdir + "/" + basename)
71 elif options.recurse and os.path.isdir(fullpath) and \
72 basename not in options.disallowed_dirs:
73 for i in os.listdir(fullpath):
75 if prefix: pfx = prefix + "/" + pfx
76 install(i, dirname, options, pfx)
77 elif not options.recurse and os.path.isdir(fullpath):
78 global skipped_directories
79 skipped_directories.append(fullpath)
92 if "PF" in os.environ:
93 self.PF = os.environ["PF"]
94 if os.environ.get("EAPI", "0") in ("0", "1", "2"):
95 self.ED = os.environ.get("D", "")
97 self.ED = os.environ.get("ED", "")
98 if "_E_DOCDESTTREE_" in os.environ:
99 self.DOCDESTTREE = os.environ["_E_DOCDESTTREE_"]
101 self.allowed_exts = [ 'htm', 'html', 'css', 'js',
102 'gif', 'jpeg', 'jpg', 'png' ]
103 self.allowed_files = []
104 self.disallowed_dirs = [ 'CVS' ]
110 opts = OptionsClass()
112 print("dohtml [-a .foo,.bar] [-A .foo,.bar] [-f foo,bar] [-x foo,bar]")
113 print(" [-r] [-V] <file> [file ...]")
115 print(" -a Set the list of allowed to those that are specified.")
116 print(" Default:", ",".join(opts.allowed_exts))
117 print(" -A Extend the list of allowed file types.")
118 print(" -f Set list of allowed extensionless file names.")
119 print(" -x Set directories to be excluded from recursion.")
120 print(" Default:", ",".join(opts.disallowed_dirs))
121 print(" -p Set a document prefix for installed files (empty by default).")
122 print(" -r Install files and directories recursively.")
123 print(" -V Be verbose.")
127 options = OptionsClass()
131 while x < len(sys.argv):
133 if arg in ["-h","-r","-V"]:
138 options.recurse = True
140 options.verbose = True
141 elif sys.argv[x] in ["-A","-a","-f","-x","-p"]:
143 if x == len(sys.argv):
147 options.doc_prefix = sys.argv[x]
149 values = sys.argv[x].split(",")
151 options.allowed_exts.extend(values)
153 options.allowed_exts = values
155 options.allowed_files = values
157 options.disallowed_dirs = values
159 args.append(sys.argv[x])
162 return (options, args)
166 (options, args) = parse_args()
169 print("Allowed extensions:", options.allowed_exts)
170 print("Document prefix : '" + options.doc_prefix + "'")
171 print("Allowed files :", options.allowed_files)
176 basename = os.path.basename(x)
177 dirname = os.path.dirname(x)
178 success |= install(basename, dirname, options)
180 global skipped_directories
181 for x in skipped_directories:
182 eqawarn(["QA Notice: dohtml on directory " + \
183 "'%s' without recursion option" % x])
192 if __name__ == "__main__":