Skip to content
Permalink
Browse files

remove empty directories with --clean-files

  • Loading branch information
ralsina committed Jul 24, 2015
1 parent 08fc9fa commit 063c7095a18f861bd6a5234c8b9b820d19ff7cf3
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: %s' % 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: %s/' % d)
except OSError:
pass
return True

0 comments on commit 063c709

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