mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 10:37:13 +02:00
Use internal context to fetch IDE data
This commit is contained in:
@ -15,11 +15,14 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from cStringIO import StringIO
|
||||||
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
|
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
|
import click
|
||||||
|
|
||||||
from platformio import app, exception, util
|
from platformio import exception, util
|
||||||
|
from platformio.commands.run import cli as cmd_run
|
||||||
|
|
||||||
|
|
||||||
class ProjectGenerator(object):
|
class ProjectGenerator(object):
|
||||||
@ -61,18 +64,20 @@ class ProjectGenerator(object):
|
|||||||
envdata = self.get_project_env()
|
envdata = self.get_project_env()
|
||||||
if "env_name" not in envdata:
|
if "env_name" not in envdata:
|
||||||
return data
|
return data
|
||||||
cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"]
|
|
||||||
if app.get_session_var("caller_id"):
|
|
||||||
cmd.extend(["-c", app.get_session_var("caller_id")])
|
|
||||||
cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
|
|
||||||
cmd.extend(["-d", self.project_dir])
|
|
||||||
result = util.exec_command(cmd)
|
|
||||||
|
|
||||||
if result['returncode'] != 0 or '"includes":' not in result['out']:
|
out = StringIO()
|
||||||
raise exception.PlatformioException(
|
with util.capture_stdout(out):
|
||||||
"\n".join([result['out'], result['err']]))
|
click.get_current_context().invoke(
|
||||||
|
cmd_run,
|
||||||
|
project_dir=self.project_dir,
|
||||||
|
environment=[envdata['env_name']],
|
||||||
|
target=["idedata"])
|
||||||
|
result = out.getvalue()
|
||||||
|
|
||||||
for line in result['out'].split("\n"):
|
if '"includes":' not in result:
|
||||||
|
raise exception.PlatformioException(result)
|
||||||
|
|
||||||
|
for line in result.split("\n"):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('{"') and line.endswith("}"):
|
if line.startswith('{"') and line.endswith("}"):
|
||||||
data = json.loads(line)
|
data = json.loads(line)
|
||||||
|
@ -22,6 +22,7 @@ import socket
|
|||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
|
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
|
||||||
join, normpath, splitdrive)
|
join, normpath, splitdrive)
|
||||||
@ -160,6 +161,14 @@ def singleton(cls):
|
|||||||
return get_instance
|
return get_instance
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def capture_stdout(output):
|
||||||
|
stdout = sys.stdout
|
||||||
|
sys.stdout = output
|
||||||
|
yield
|
||||||
|
sys.stdout = stdout
|
||||||
|
|
||||||
|
|
||||||
def load_json(file_path):
|
def load_json(file_path):
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
|
Reference in New Issue
Block a user