Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 209bef7

Browse files
authored
Update build_docs.py to remove build_dependencies directory
Merge pull request #60 from awsdocs/build_docs
2 parents 13a8a9e + 5421395 commit 209bef7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

build_docs.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Documentation build script for AWS Sphinx documentation on GitHub.
1818
# ------------------------------------------------------------------
1919

20-
import sys, os
20+
import sys, os, stat, errno
2121
import subprocess
2222
import shutil
2323

@@ -42,15 +42,29 @@
4242
SOURCE_DIR = 'doc_source'
4343

4444

45+
def handle_remove_readonly(func, path, excinfo):
46+
"""Handler for shutil.rmtree() failure
47+
48+
If the removal failed because of Access denied error due to a R/O file, change the file's
49+
permissions to R/W and retry the removal operation.
50+
"""
51+
52+
if excinfo[1].errno == errno.EACCES:
53+
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777
54+
func(path)
55+
else:
56+
raise excinfo[0]
57+
58+
4559
def check_and_remove_dir(dir_name):
4660
"""Check to see if the named directory exists. If it does, then remove it.
4761
Throw an exception if the directory can't be removed."""
4862

4963
if os.path.exists(dir_name):
5064
print("Removing directory: " + dir_name)
5165
try:
52-
shutil.rmtree(dir_name)
53-
except:
66+
shutil.rmtree(dir_name, onerror=handle_remove_readonly)
67+
except Exception as e:
5468
print("Couldn't remove " + dir_name)
5569
print("Remove this directory before building!")
5670
sys.exit(1)

0 commit comments

Comments
 (0)