Skip to content

Commit

Permalink
remove empty directories with --clean-files
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Jul 24, 2015
1 parent 08fc9fa commit 063c709
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

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

Bugfixes
--------

Expand Down
14 changes: 14 additions & 0 deletions nikola/plugins/command/check.py
Expand Up @@ -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.