|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 | 3 | from __future__ import print_function
|
4 |
| -import fileinput |
5 | 4 | import glob
|
6 | 5 | import os
|
7 | 6 | import shutil
|
8 | 7 | import sys
|
9 | 8 | import re
|
10 | 9 |
|
11 |
| -### Begin compatibility block for pre-v2.6: ### |
12 |
| -# |
13 |
| -# ignore_patterns and copytree funtions are copies of what is included |
14 |
| -# in shutil.copytree of python v2.6 and later. |
15 |
| -# |
16 |
| -### When compatibility is no-longer needed, this block |
17 |
| -### can be replaced with: |
18 |
| -### |
19 |
| -### from shutil import ignore_patterns, copytree |
20 |
| -### |
21 |
| -### or the "shutil." qualifier can be prepended to the function |
22 |
| -### names where they are used. |
23 |
| - |
24 |
| -try: |
25 |
| - WindowsError |
26 |
| -except NameError: |
27 |
| - WindowsError = None |
28 |
| - |
29 |
| -def ignore_patterns(*patterns): |
30 |
| - """Function that can be used as copytree() ignore parameter. |
31 |
| -
|
32 |
| - Patterns is a sequence of glob-style patterns |
33 |
| - that are used to exclude files""" |
34 |
| - import fnmatch |
35 |
| - def _ignore_patterns(path, names): |
36 |
| - ignored_names = [] |
37 |
| - for pattern in patterns: |
38 |
| - ignored_names.extend(fnmatch.filter(names, pattern)) |
39 |
| - return set(ignored_names) |
40 |
| - return _ignore_patterns |
41 |
| - |
42 |
| -def copytree(src, dst, symlinks=False, ignore=None): |
43 |
| - """Recursively copy a directory tree using copy2(). |
44 |
| -
|
45 |
| - The destination directory must not already exist. |
46 |
| - If exception(s) occur, an Error is raised with a list of reasons. |
47 |
| -
|
48 |
| - If the optional symlinks flag is true, symbolic links in the |
49 |
| - source tree result in symbolic links in the destination tree; if |
50 |
| - it is false, the contents of the files pointed to by symbolic |
51 |
| - links are copied. |
52 |
| -
|
53 |
| - The optional ignore argument is a callable. If given, it |
54 |
| - is called with the `src` parameter, which is the directory |
55 |
| - being visited by copytree(), and `names` which is the list of |
56 |
| - `src` contents, as returned by os.listdir(): |
57 |
| -
|
58 |
| - callable(src, names) -> ignored_names |
59 |
| -
|
60 |
| - Since copytree() is called recursively, the callable will be |
61 |
| - called once for each directory that is copied. It returns a |
62 |
| - list of names relative to the `src` directory that should |
63 |
| - not be copied. |
64 |
| -
|
65 |
| - XXX Consider this example code rather than the ultimate tool. |
66 |
| -
|
67 |
| - """ |
68 |
| - from shutil import copy2, Error, copystat |
69 |
| - names = os.listdir(src) |
70 |
| - if ignore is not None: |
71 |
| - ignored_names = ignore(src, names) |
72 |
| - else: |
73 |
| - ignored_names = set() |
74 |
| - |
75 |
| - os.makedirs(dst) |
76 |
| - errors = [] |
77 |
| - for name in names: |
78 |
| - if name in ignored_names: |
79 |
| - continue |
80 |
| - srcname = os.path.join(src, name) |
81 |
| - dstname = os.path.join(dst, name) |
82 |
| - try: |
83 |
| - if symlinks and os.path.islink(srcname): |
84 |
| - linkto = os.readlink(srcname) |
85 |
| - os.symlink(linkto, dstname) |
86 |
| - elif os.path.isdir(srcname): |
87 |
| - copytree(srcname, dstname, symlinks, ignore) |
88 |
| - else: |
89 |
| - # Will raise a SpecialFileError for unsupported file types |
90 |
| - copy2(srcname, dstname) |
91 |
| - # catch the Error from the recursive copytree so that we can |
92 |
| - # continue with other files |
93 |
| - except Error as err: |
94 |
| - errors.extend(err.args[0]) |
95 |
| - except EnvironmentError as why: |
96 |
| - errors.append((srcname, dstname, str(why))) |
97 |
| - try: |
98 |
| - copystat(src, dst) |
99 |
| - except OSError as why: |
100 |
| - if WindowsError is not None and isinstance(why, WindowsError): |
101 |
| - # Copying file access times may fail on Windows |
102 |
| - pass |
103 |
| - else: |
104 |
| - errors.extend((src, dst, str(why))) |
105 |
| - if errors: |
106 |
| - raise Error(errors) |
107 |
| - |
108 |
| -### End compatibility block for pre-v2.6 ### |
109 |
| - |
110 | 10 |
|
111 | 11 | def copy_if_out_of_date(original, derived):
|
112 | 12 | if (not os.path.exists(derived) or
|
@@ -151,7 +51,7 @@ def html(buildername='html'):
|
151 | 51 | os.remove(filename)
|
152 | 52 |
|
153 | 53 | shutil.copy('../CHANGELOG', 'build/%s/_static/CHANGELOG' % buildername)
|
154 |
| - |
| 54 | + |
155 | 55 | def htmlhelp():
|
156 | 56 | html(buildername='htmlhelp')
|
157 | 57 | # remove scripts from index.html
|
|
0 commit comments