Skip to content

Commit 63e1c5e

Browse files
committedMay 27, 2015
this makes check -f work
1 parent 4911008 commit 63e1c5e

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Features
1414
Bugfixes
1515
--------
1616

17+
* Extract ``nikola check`` target list from actual task list instead of parsing (Issue #1758)
1718
* Treat special-purpose “draft” tag case-insensitive
1819
* Avoid some rebuild loops (Issue #1747)
1920
* Better error if two posts/pages output conflict (Issue #1749)

‎nikola/plugins/command/check.py

+16-27
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
except ImportError:
3535
from urllib.parse import unquote, urlparse, urljoin, urldefrag # NOQA
3636

37+
from doit.loader import generate_tasks
3738
import lxml.html
3839
try:
3940
import requests
@@ -44,33 +45,22 @@
4445
from nikola.utils import get_logger, req_missing
4546

4647

47-
def _call_nikola_list(l, site, arguments):
48-
class NotReallyAStream(object):
49-
"""A massive hack."""
50-
out = []
48+
def _call_nikola_list(site):
49+
files = []
50+
for task in generate_tasks('render_site', site.gen_tasks('render_site', "Task", '')):
51+
files.extend(task.targets)
52+
for task in generate_tasks('post_render', site.gen_tasks('render_site', "LateTask", '')):
53+
files.extend(task.targets)
54+
return files
5155

52-
def write(self, t):
53-
self.out.append(t)
54-
55-
oldstream = l.outstream
56-
newstream = NotReallyAStream()
57-
try:
58-
l.outstream = newstream
59-
l.parse_execute(arguments)
60-
return newstream.out
61-
finally:
62-
l.outstream = oldstream
63-
64-
65-
def real_scan_files(l, site):
56+
def real_scan_files(site):
6657
task_fnames = set([])
6758
real_fnames = set([])
6859
output_folder = site.config['OUTPUT_FOLDER']
6960
# First check that all targets are generated in the right places
70-
for task in _call_nikola_list(l, site, ["--all"]):
71-
task = task.strip()
72-
if output_folder in task and ':' in task:
73-
fname = task.split(':', 1)[-1]
61+
for fname in _call_nikola_list(site):
62+
fname = fname.strip()
63+
if output_folder in fname:
7464
task_fnames.add(fname)
7565
# And now check that there are no non-target files
7666
for root, dirs, files in os.walk(output_folder, followlinks=True):
@@ -154,7 +144,6 @@ class CommandCheck(Command):
154144
def _execute(self, options, args):
155145
"""Check the generated site."""
156146
self.logger = get_logger('check', self.site.loghandlers)
157-
self.l = self._doitargs['cmds'].get_plugin('list')(config=self.config, **self._doitargs)
158147

159148
if not options['links'] and not options['files'] and not options['clean']:
160149
print(self.help())
@@ -262,7 +251,7 @@ def analyze(self, task, find_sources=False, check_remote=False):
262251
self.logger.warn("Broken link in {0}: {1}".format(filename, target))
263252
if find_sources:
264253
self.logger.warn("Possible sources:")
265-
self.logger.warn("\n".join(_call_nikola_list(self.l, self.site, ["--deps", task])))
254+
self.logger.warn("\n".join(_call_nikola_list(self.site)))
266255
self.logger.warn("===============================\n")
267256
except Exception as exc:
268257
self.logger.error("Error with: {0} {1}".format(filename, exc))
@@ -273,7 +262,7 @@ def scan_links(self, find_sources=False, check_remote=False):
273262
self.logger.info("===============\n")
274263
self.logger.notice("{0} mode".format(self.site.config['URL_TYPE']))
275264
failure = False
276-
for task in _call_nikola_list(self.l, self.site, ["--all"]):
265+
for task in _call_nikola_list(self.site):
277266
task = task.strip()
278267
if task.split(':')[0] in (
279268
'render_tags', 'render_archive',
@@ -290,7 +279,7 @@ def scan_files(self):
290279
failure = False
291280
self.logger.info("Checking Files:")
292281
self.logger.info("===============\n")
293-
only_on_output, only_on_input = real_scan_files(self.l, self.site)
282+
only_on_output, only_on_input = real_scan_files(self.site)
294283

295284
# Ignore folders
296285
only_on_output = [p for p in only_on_output if not os.path.isdir(p)]
@@ -312,7 +301,7 @@ def scan_files(self):
312301
return failure
313302

314303
def clean_files(self):
315-
only_on_output, _ = real_scan_files(self.l, self.site)
304+
only_on_output, _ = real_scan_files(self.site)
316305
for f in only_on_output:
317306
os.unlink(f)
318307
return True

0 commit comments

Comments
 (0)
Please sign in to comment.