diff options
| author | 2014-02-28 08:49:38 -0300 | |
|---|---|---|
| committer | 2014-02-28 08:49:38 -0300 | |
| commit | 2828399ba5cbb14502b023d4de1ba02f13dd5055 (patch) | |
| tree | 38012b6bacaa508ca56fb6f4ba87b912bb54b8c9 /nikola/plugins/command/check.py | |
| parent | ca94afc07df55cb7fc6fe3b4f3011877b7881195 (diff) | |
Imported Upstream version 6.3.0upstream/6.3.0
Diffstat (limited to 'nikola/plugins/command/check.py')
| -rw-r--r-- | nikola/plugins/command/check.py | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/nikola/plugins/command/check.py b/nikola/plugins/command/check.py index 5c7e49a..a7e8c13 100644 --- a/nikola/plugins/command/check.py +++ b/nikola/plugins/command/check.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -40,6 +40,29 @@ from nikola.plugin_categories import Command from nikola.utils import get_logger +def real_scan_files(site): + task_fnames = set([]) + real_fnames = set([]) + output_folder = site.config['OUTPUT_FOLDER'] + # First check that all targets are generated in the right places + for task in os.popen('nikola list --all', 'r').readlines(): + task = task.strip() + if output_folder in task and ':' in task: + fname = task.split(':', 1)[-1] + task_fnames.add(fname) + # And now check that there are no non-target files + for root, dirs, files in os.walk(output_folder): + for src_name in files: + fname = os.path.join(root, src_name) + real_fnames.add(fname) + + only_on_output = list(real_fnames - task_fnames) + + only_on_input = list(task_fnames - real_fnames) + + return (only_on_output, only_on_input) + + class CommandCheck(Command): """Check the generated site.""" @@ -63,7 +86,7 @@ class CommandCheck(Command): 'long': 'check-files', 'type': bool, 'default': False, - 'help': 'Check for unknown files', + 'help': 'Check for unknown (orphaned and not generated) files', }, { 'name': 'clean', @@ -154,7 +177,7 @@ class CommandCheck(Command): failure = False self.logger.notice("Checking Files:") self.logger.notice("===============\n") - only_on_output, only_on_input = self.real_scan_files() + only_on_output, only_on_input = real_scan_files(self.site) # Ignore folders only_on_output = [p for p in only_on_output if not os.path.isdir(p)] @@ -162,7 +185,7 @@ class CommandCheck(Command): if only_on_output: only_on_output.sort() - self.logger.warn("Files from unknown origins:") + self.logger.warn("Files from unknown origins (orphans):") for f in only_on_output: self.logger.warn(f) failure = True @@ -180,25 +203,3 @@ class CommandCheck(Command): for f in only_on_output: os.unlink(f) return True - - def real_scan_files(self): - task_fnames = set([]) - real_fnames = set([]) - output_folder = self.site.config['OUTPUT_FOLDER'] - # First check that all targets are generated in the right places - for task in os.popen('nikola list --all', 'r').readlines(): - task = task.strip() - if output_folder in task and ':' in task: - fname = task.split(':', 1)[-1] - task_fnames.add(fname) - # And now check that there are no non-target files - for root, dirs, files in os.walk(output_folder): - for src_name in files: - fname = os.path.join(root, src_name) - real_fnames.add(fname) - - only_on_output = list(real_fnames - task_fnames) - - only_on_input = list(task_fnames - real_fnames) - - return (only_on_output, only_on_input) |
