Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/bin/generate_static_pages.py

Issue 29887585: Issue #5352 - generate_static_pages cannot deal with directories being turned into regular pages (Closed)
Patch Set: Created Sept. 21, 2018, 1:35 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cms/bin/generate_static_pages.py
diff --git a/cms/bin/generate_static_pages.py b/cms/bin/generate_static_pages.py
index 5eaeb1b9af236f2833bb27005a0ffe89a3e0b7d2..b02aaa3077147455a34594f2c0880c78c2b0daca 100644
--- a/cms/bin/generate_static_pages.py
+++ b/cms/bin/generate_static_pages.py
@@ -20,6 +20,7 @@ import codecs
import ConfigParser
import logging
from argparse import ArgumentParser
+import shutil
from cms.utils import get_page_params, process_page
from cms.sources import create_source
@@ -38,16 +39,25 @@ def generate_pages(repo, output_dir):
return
known_files.add(outfile)
- if os.path.exists(outfile):
+ if os.path.isfile(outfile):
Vasily Kuznetsov 2018/09/24 11:58:47 Are you sure if the two branches of this if statem
Tudor Avram 2018/09/24 14:04:51 Also, one more thing: do we want to raise an error
Vasily Kuznetsov 2018/09/24 14:42:23 I think if there's some kind of weird object in th
Tudor Avram 2018/09/24 16:10:00 Done.
with codecs.open(outfile, 'rb', encoding=encoding) as handle:
if handle.read() == contents:
return
+ elif os.path.isdir(outfile):
+ shutil.rmtree(outfile)
try:
Vasily Kuznetsov 2018/09/24 11:58:47 I think it would be good to extract this whole blo
Tudor Avram 2018/09/24 13:26:45 Yeah, I think it makes sense to put this into a di
Vasily Kuznetsov 2018/09/24 14:42:23 I don't expect many directories to be created when
Tudor Avram 2018/09/24 16:10:00 Done.
os.makedirs(os.path.dirname(outfile))
except OSError as e:
if e.errno != errno.EEXIST:
raise
+ path_so_far = output_dir
+ for part in path_parts[:-1]:
+ path_so_far = os.path.join(path_so_far, part)
+ if os.path.isfile(path_so_far):
+ os.remove(path_so_far)
+ os.makedirs(os.path.dirname(outfile))
+ break
with codecs.open(outfile, 'wb', encoding=encoding) as handle:
handle.write(contents)

Powered by Google App Engine
This is Rietveld