Skip to content
Browse files
Calling Nikola's main directly instead of using subprocess to execute…
… Nikola again.

Also avoiding unnecessary console output.
  • Loading branch information
felixfontein committed Jan 18, 2015
1 parent 2b34513 commit edfb302d4340dd198e1bcb64f349cfca8d5aab40
Showing 1 changed file with 20 additions and 12 deletions.
@@ -33,27 +33,35 @@
from urlparse import urlparse, urljoin, urldefrag
except ImportError:
from urllib.parse import unquote, urlparse, urljoin, urldefrag # NOQA
import subprocess

from io import TextIOWrapper, BytesIO

import lxml.html

from nikola.plugin_categories import Command
from nikola.utils import get_logger
from nikola import __main__

def _call_nikola_list(site, arguments):
command = ["nikola"]
command_args = []
if site.configuration_filename != '':
command.append('--conf=' + site.configuration_filename)
command.extend(["list", "--all"])
result = []
if == 'nt':
shell = True
command = ' '.join(command)
shell = False
for task in subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE).stdout.readlines():
command_args.append('--conf=' + site.configuration_filename)
command_args.extend(["list", "--all"])

with TextIOWrapper(BytesIO(), sys.stdout.encoding) as grabber, TextIOWrapper(BytesIO(), sys.stdout.encoding) as grabber2:
stdout_save = sys.stdout
stderr_save = sys.stderr
sys.stdout = grabber
sys.stderr = grabber2
sys.stdout = stdout_save
sys.stderr = stderr_save
result = grabber.readlines()
return result

0 comments on commit edfb302

Please sign in to comment.