diff options
author | Guido van Rossum <guido@python.org> | 1999-01-03 13:06:00 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-03 13:06:00 (GMT) |
commit | 909bc181885185a6ee96f34a2fb3ad5ffb92954e (patch) | |
tree | dd8bbcd9c4f99ad0a3962fbdde7779d6e6ca5aba /Tools/webchecker/websucker.py | |
parent | 0a6363d7e1d3061211faa2323752819e371e0ad2 (diff) | |
download | cpython-909bc181885185a6ee96f34a2fb3ad5ffb92954e.zip cpython-909bc181885185a6ee96f34a2fb3ad5ffb92954e.tar.gz cpython-909bc181885185a6ee96f34a2fb3ad5ffb92954e.tar.bz2 |
Recover from failed saves; when a file turns out to be a directory,
create a directory and moer the original file to the index.html.
Diffstat (limited to 'Tools/webchecker/websucker.py')
-rwxr-xr-x | Tools/webchecker/websucker.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Tools/webchecker/websucker.py b/Tools/webchecker/websucker.py index 59da51b..67e493d 100755 --- a/Tools/webchecker/websucker.py +++ b/Tools/webchecker/websucker.py @@ -73,10 +73,13 @@ class Sucker(webchecker.Checker): def savefile(self, text, path): dir, base = os.path.split(path) makedirs(dir) - f = open(path, "wb") - f.write(text) - f.close() - self.message("saved %s", path) + try: + f = open(path, "wb") + f.write(text) + f.close() + self.message("saved %s", path) + except IOError, msg: + self.message("didn't save %s: %s", path, str(msg)) def savefilename(self, url): type, rest = urllib.splittype(url) @@ -93,7 +96,16 @@ class Sucker(webchecker.Checker): return path def makedirs(dir): - if not dir or os.path.exists(dir): + if not dir: + return + if os.path.exists(dir): + if not os.path.isdir(dir): + try: + os.rename(dir, dir + ".bak") + os.mkdir(dir) + os.rename(dir + ".bak", os.path.join(dir, "index.html")) + except os.error: + pass return head, tail = os.path.split(dir) if not tail: |