|
33 | 33 | from urlparse import urlparse, urljoin, urldefrag
|
34 | 34 | except ImportError:
|
35 | 35 | from urllib.parse import unquote, urlparse, urljoin, urldefrag # NOQA
|
36 |
| -import subprocess |
| 36 | + |
| 37 | +from io import TextIOWrapper, BytesIO |
37 | 38 |
|
38 | 39 | import lxml.html
|
39 | 40 |
|
40 | 41 | from nikola.plugin_categories import Command
|
41 | 42 | from nikola.utils import get_logger
|
| 43 | +from nikola import __main__ |
42 | 44 |
|
43 | 45 |
|
44 | 46 | def _call_nikola_list(site, arguments):
|
45 |
| - command = ["nikola"] |
| 47 | + command_args = [] |
46 | 48 | 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() |
57 | 65 | return result
|
58 | 66 |
|
59 | 67 |
|
|
0 commit comments