31 lines
896 B
Python
31 lines
896 B
Python
import asyncio
|
|
from . import defaults, utils
|
|
|
|
#
|
|
# Base connector
|
|
#
|
|
def run_command(async_func, user_path:str=None):
|
|
async def runner():
|
|
# Connect to user socket
|
|
nonlocal user_path
|
|
if user_path is None:
|
|
user_path = defaults.USER_PATH
|
|
if user_path is None:
|
|
raise RuntimeError("User service socket path isn't set.")
|
|
sock = utils.Connection()
|
|
await sock.init(user_path)
|
|
|
|
# Run async function
|
|
await async_func(sock)
|
|
asyncio.run(runner())
|
|
|
|
|
|
#
|
|
# Remotes
|
|
#
|
|
def remote_add_gen(name:str, rtype:str, info):
|
|
async def remote_add(con:utils.Connection):
|
|
result = await con.call({"operation": "remote-add", "name": name, "type": rtype, "info": info})
|
|
if result["status"] != "success":
|
|
raise RuntimeError("Wasn't able to add remote.") # TODO: Show error
|
|
return remote_add |