Skip to content
Permalink
Browse files

Merge pull request #1908 from getnikola/fix-1873

remove empty directories with --clean-files
  • Loading branch information
Kwpolska committed Jul 24, 2015
2 parents 8151c2d + 7c205be commit 77a8d380b7daf535cd8287cf3c1e8d3d8ff64a04
Showing with 16 additions and 0 deletions.
  1. +2 −0 CHANGES.txt
  2. +14 −0 nikola/plugins/command/check.py
@@ -4,6 +4,8 @@ New in master
Features
--------

* Remove empty directories with nikola check --clean-files (Issue #1873)

Bugfixes
--------

@@ -313,5 +313,19 @@ def scan_files(self):
def clean_files(self):
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
self.logger.info('removed: {0}'.format(f))
os.unlink(f)

# Find empty directories and remove them
output_folder = self.site.config['OUTPUT_FOLDER']
all_dirs = []
for root, dirs, files in os.walk(output_folder, followlinks=True):
all_dirs.append(root)
all_dirs.sort(key=len, reverse=True)
for d in all_dirs:
try:
os.rmdir(d)
self.logger.info('removed: {0}/'.format(d))
except OSError:
pass
return True

0 comments on commit 77a8d38

Please sign in to comment.
You can’t perform that action at this time.