mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Fix an issue with "coroutine' object has no attribute 'addCallback'"
This commit is contained in:
@ -184,7 +184,7 @@ class ProjectRPC:
|
|||||||
)
|
)
|
||||||
return sorted(result, key=lambda data: data["platform"]["title"])
|
return sorted(result, key=lambda data: data["platform"]["title"])
|
||||||
|
|
||||||
def init(self, board, framework, project_dir):
|
async def init(self, board, framework, project_dir):
|
||||||
assert project_dir
|
assert project_dir
|
||||||
state = AppRPC.load_state()
|
state = AppRPC.load_state()
|
||||||
if not os.path.isdir(project_dir):
|
if not os.path.isdir(project_dir):
|
||||||
@ -197,14 +197,13 @@ class ProjectRPC:
|
|||||||
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
||||||
):
|
):
|
||||||
args.extend(["--ide", state["storage"]["coreCaller"]])
|
args.extend(["--ide", state["storage"]["coreCaller"]])
|
||||||
d = PIOCoreRPC.call(
|
await PIOCoreRPC.call(
|
||||||
args, options={"cwd": project_dir, "force_subprocess": True}
|
args, options={"cwd": project_dir, "force_subprocess": True}
|
||||||
)
|
)
|
||||||
d.addCallback(self._generate_project_main, project_dir, framework)
|
return self._generate_project_main(project_dir, framework)
|
||||||
return d
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate_project_main(_, project_dir, framework):
|
def _generate_project_main(project_dir, framework):
|
||||||
main_content = None
|
main_content = None
|
||||||
if framework == "arduino":
|
if framework == "arduino":
|
||||||
main_content = "\n".join(
|
main_content = "\n".join(
|
||||||
@ -251,7 +250,7 @@ class ProjectRPC:
|
|||||||
fp.write(main_content.strip())
|
fp.write(main_content.strip())
|
||||||
return project_dir
|
return project_dir
|
||||||
|
|
||||||
def import_arduino(self, board, use_arduino_libs, arduino_project_dir):
|
async def import_arduino(self, board, use_arduino_libs, arduino_project_dir):
|
||||||
board = str(board)
|
board = str(board)
|
||||||
# don't import PIO Project
|
# don't import PIO Project
|
||||||
if is_platformio_project(arduino_project_dir):
|
if is_platformio_project(arduino_project_dir):
|
||||||
@ -290,14 +289,9 @@ class ProjectRPC:
|
|||||||
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
||||||
):
|
):
|
||||||
args.extend(["--ide", state["storage"]["coreCaller"]])
|
args.extend(["--ide", state["storage"]["coreCaller"]])
|
||||||
d = PIOCoreRPC.call(
|
await PIOCoreRPC.call(
|
||||||
args, options={"cwd": project_dir, "force_subprocess": True}
|
args, options={"cwd": project_dir, "force_subprocess": True}
|
||||||
)
|
)
|
||||||
d.addCallback(self._finalize_arduino_import, project_dir, arduino_project_dir)
|
|
||||||
return d
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _finalize_arduino_import(_, project_dir, arduino_project_dir):
|
|
||||||
with fs.cd(project_dir):
|
with fs.cd(project_dir):
|
||||||
config = ProjectConfig()
|
config = ProjectConfig()
|
||||||
src_dir = config.get_optional_dir("src")
|
src_dir = config.get_optional_dir("src")
|
||||||
@ -307,7 +301,7 @@ class ProjectRPC:
|
|||||||
return project_dir
|
return project_dir
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def import_pio(project_dir):
|
async def import_pio(project_dir):
|
||||||
if not project_dir or not is_platformio_project(project_dir):
|
if not project_dir or not is_platformio_project(project_dir):
|
||||||
raise jsonrpc.exceptions.JSONRPCDispatchException(
|
raise jsonrpc.exceptions.JSONRPCDispatchException(
|
||||||
code=4001, message="Not an PlatformIO project: %s" % project_dir
|
code=4001, message="Not an PlatformIO project: %s" % project_dir
|
||||||
@ -325,8 +319,7 @@ class ProjectRPC:
|
|||||||
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
and state["storage"]["coreCaller"] in ProjectGenerator.get_supported_ides()
|
||||||
):
|
):
|
||||||
args.extend(["--ide", state["storage"]["coreCaller"]])
|
args.extend(["--ide", state["storage"]["coreCaller"]])
|
||||||
d = PIOCoreRPC.call(
|
await PIOCoreRPC.call(
|
||||||
args, options={"cwd": new_project_dir, "force_subprocess": True}
|
args, options={"cwd": new_project_dir, "force_subprocess": True}
|
||||||
)
|
)
|
||||||
d.addCallback(lambda _: new_project_dir)
|
return new_project_dir
|
||||||
return d
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -31,6 +30,7 @@ from platformio.commands.home.rpc.handlers.os import OSRPC
|
|||||||
from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC
|
from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC
|
||||||
from platformio.commands.home.rpc.handlers.project import ProjectRPC
|
from platformio.commands.home.rpc.handlers.project import ProjectRPC
|
||||||
from platformio.commands.home.rpc.server import WebSocketJSONRPCServerFactory
|
from platformio.commands.home.rpc.server import WebSocketJSONRPCServerFactory
|
||||||
|
from platformio.compat import get_running_loop
|
||||||
from platformio.exception import PlatformioException
|
from platformio.exception import PlatformioException
|
||||||
from platformio.package.manager.core import get_core_package_dir
|
from platformio.package.manager.core import get_core_package_dir
|
||||||
from platformio.proc import force_exit
|
from platformio.proc import force_exit
|
||||||
@ -47,7 +47,7 @@ class ShutdownMiddleware:
|
|||||||
|
|
||||||
|
|
||||||
async def shutdown_server(_=None):
|
async def shutdown_server(_=None):
|
||||||
asyncio.get_event_loop().call_later(0.5, force_exit)
|
get_running_loop().call_later(0.5, force_exit)
|
||||||
return PlainTextResponse("Server has been shutdown!")
|
return PlainTextResponse("Server has been shutdown!")
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user