Skip to content

Commit edfb302

Browse files
committedJan 18, 2015
Calling Nikola's main directly instead of using subprocess to execute Nikola again.
Also avoiding unnecessary console output.
1 parent 2b34513 commit edfb302

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed
 

‎nikola/plugins/command/check.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,35 @@
3333
from urlparse import urlparse, urljoin, urldefrag
3434
except ImportError:
3535
from urllib.parse import unquote, urlparse, urljoin, urldefrag # NOQA
36-
import subprocess
36+
37+
from io import TextIOWrapper, BytesIO
3738

3839
import lxml.html
3940

4041
from nikola.plugin_categories import Command
4142
from nikola.utils import get_logger
43+
from nikola import __main__
4244

4345

4446
def _call_nikola_list(site, arguments):
45-
command = ["nikola"]
47+
command_args = []
4648
if site.configuration_filename != 'conf.py':
47-
command.append('--conf=' + site.configuration_filename)
48-
command.extend(["list", "--all"])
49-
result = []
50-
if os.name == 'nt':
51-
shell = True
52-
command = ' '.join(command)
53-
else:
54-
shell = False
55-
for task in subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE).stdout.readlines():
56-
result.append(task.decode('utf-8'))
49+
command_args.append('--conf=' + site.configuration_filename)
50+
command_args.extend(["list", "--all"])
51+
52+
with TextIOWrapper(BytesIO(), sys.stdout.encoding) as grabber, TextIOWrapper(BytesIO(), sys.stdout.encoding) as grabber2:
53+
stdout_save = sys.stdout
54+
stderr_save = sys.stderr
55+
try:
56+
sys.stdout = grabber
57+
sys.stderr = grabber2
58+
__main__.main(command_args)
59+
finally:
60+
sys.stdout = stdout_save
61+
sys.stderr = stderr_save
62+
63+
grabber.seek(0)
64+
result = grabber.readlines()
5765
return result
5866

5967

0 commit comments

Comments
 (0)
Please sign in to comment.