mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #393 from tbunnyman/DeleteContentsNotDirectory
Change behavior of DELETE_OUTPUT_DIRECTORY to purge contents of the directory…
This commit is contained in:
commit
236dbb2842
4 changed files with 28 additions and 8 deletions
|
|
@ -238,5 +238,3 @@ Or run a simple web server using Python::
|
||||||
|
|
||||||
cd output && python -m SimpleHTTPServer
|
cd output && python -m SimpleHTTPServer
|
||||||
|
|
||||||
(Tip: If using the latter method in conjunction with the auto-reload feature,
|
|
||||||
ensure that ``DELETE_OUTPUT_DIRECTORY`` is set to ``False`` in your settings file.)
|
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ Setting name (default value) What doe
|
||||||
timestamp information (mtime) if it can't get
|
timestamp information (mtime) if it can't get
|
||||||
date information from the metadata.
|
date information from the metadata.
|
||||||
`JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use.
|
`JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use.
|
||||||
`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory as well as
|
`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the content of the output directory before
|
||||||
the generated files.
|
generating new files.
|
||||||
`LOCALE` (''[#]_) Change the locale. A list of locales can be provided
|
`LOCALE` (''[#]_) Change the locale. A list of locales can be provided
|
||||||
here or a single string representing one locale.
|
here or a single string representing one locale.
|
||||||
When providing a list, all the locales will be tried
|
When providing a list, all the locales will be tried
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,22 @@ def clean_output_dir(path):
|
||||||
"""Remove all the files from the output directory"""
|
"""Remove all the files from the output directory"""
|
||||||
|
|
||||||
# remove all the existing content from the output folder
|
# remove all the existing content from the output folder
|
||||||
try:
|
for filename in os.listdir(path):
|
||||||
shutil.rmtree(path)
|
file = os.path.join(path, filename)
|
||||||
except Exception:
|
if os.path.isdir(file):
|
||||||
pass
|
try:
|
||||||
|
shutil.rmtree(file)
|
||||||
|
logger.debug("Deleted directory %s" % file)
|
||||||
|
except Exception, e:
|
||||||
|
logger.error("Unable to delete directory %s; %e" % file, e)
|
||||||
|
elif os.path.isfile(file) or os.path.islink(file):
|
||||||
|
try:
|
||||||
|
os.remove(file)
|
||||||
|
logger.debug("Deleted file/link %s" % file)
|
||||||
|
except Exception, e:
|
||||||
|
logger.error("Unable to delete file %s; %e" % file, e)
|
||||||
|
else:
|
||||||
|
logger.error("Unable to delete %s, file type unknown" % file)
|
||||||
|
|
||||||
|
|
||||||
def get_relative_path(filename):
|
def get_relative_path(filename):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import shutil
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
|
@ -86,3 +87,12 @@ class TestUtils(unittest.TestCase):
|
||||||
changed = utils.files_changed(path, 'rst')
|
changed = utils.files_changed(path, 'rst')
|
||||||
self.assertEquals(changed, True)
|
self.assertEquals(changed, True)
|
||||||
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
||||||
|
|
||||||
|
def test_clean_output_dir(self):
|
||||||
|
test_directory = os.path.join(os.path.dirname(__file__), 'clean_output')
|
||||||
|
content = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
|
shutil.copytree(content, test_directory)
|
||||||
|
utils.clean_output_dir(test_directory)
|
||||||
|
self.assertTrue(os.path.isdir(test_directory))
|
||||||
|
self.assertListEqual([], os.listdir(test_directory))
|
||||||
|
shutil.rmtree(test_directory)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue