mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 03:18:25 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43556a0470 | ||
|
|
e244d3bb44 | ||
|
|
d6e6efc633 | ||
|
|
a114c9721c |
@@ -12,6 +12,7 @@ class Platform(Enum):
|
|||||||
Battlenet = "battlenet"
|
Battlenet = "battlenet"
|
||||||
|
|
||||||
class Feature(Enum):
|
class Feature(Enum):
|
||||||
|
Unknown = "Unknown"
|
||||||
ImportInstalledGames = "ImportInstalledGames"
|
ImportInstalledGames = "ImportInstalledGames"
|
||||||
ImportOwnedGames = "ImportOwnedGames"
|
ImportOwnedGames = "ImportOwnedGames"
|
||||||
LaunchGame = "LaunchGame"
|
LaunchGame = "LaunchGame"
|
||||||
@@ -24,16 +25,18 @@ class Feature(Enum):
|
|||||||
VerifyGame = "VerifyGame"
|
VerifyGame = "VerifyGame"
|
||||||
|
|
||||||
class LicenseType(Enum):
|
class LicenseType(Enum):
|
||||||
SinglePurchase = "SinglePurchase"
|
Unknown = "Unknown"
|
||||||
FreeToPlay = "FreeToPlay"
|
SinglePurchase = "SinglePurchase"
|
||||||
OtherUserLicense = "OtherUserLicense"
|
FreeToPlay = "FreeToPlay"
|
||||||
Unknown = "Unknown"
|
OtherUserLicense = "OtherUserLicense"
|
||||||
|
|
||||||
class LocalGameState(Enum):
|
class LocalGameState(Enum):
|
||||||
|
None_ = "None"
|
||||||
Installed = "Installed"
|
Installed = "Installed"
|
||||||
Running = "Running"
|
Running = "Running"
|
||||||
|
|
||||||
class PresenceState(Enum):
|
class PresenceState(Enum):
|
||||||
|
Unknown = "Unknown"
|
||||||
Online = "online"
|
Online = "online"
|
||||||
Offline = "offline"
|
Offline = "offline"
|
||||||
Away = "away"
|
Away = "away"
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ class BackendError(ApplicationError):
|
|||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
super().__init__(4, "Backend error", data)
|
super().__init__(4, "Backend error", data)
|
||||||
|
|
||||||
|
class UnknownBackendResponse(ApplicationError):
|
||||||
|
def __init__(self, data=None):
|
||||||
|
super().__init__(4, "Backend responded in uknown way", data)
|
||||||
|
|
||||||
class InvalidCredentials(ApplicationError):
|
class InvalidCredentials(ApplicationError):
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
super().__init__(100, "Invalid credentials", data)
|
super().__init__(100, "Invalid credentials", data)
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ class Server():
|
|||||||
self._send_error(request.id, MethodNotFound())
|
self._send_error(request.id, MethodNotFound())
|
||||||
except JsonRpcError as error:
|
except JsonRpcError as error:
|
||||||
self._send_error(request.id, error)
|
self._send_error(request.id, error)
|
||||||
except Exception as error: #pylint: disable=broad-except
|
except Exception: #pylint: disable=broad-except
|
||||||
logging.error("Unexpected exception raised in plugin handler: %s", repr(error))
|
logging.exception("Unexpected exception raised in plugin handler")
|
||||||
|
|
||||||
asyncio.create_task(handle())
|
asyncio.create_task(handle())
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
import sys
|
||||||
|
|
||||||
from galaxy.api.jsonrpc import Server, NotificationClient
|
from galaxy.api.jsonrpc import Server, NotificationClient
|
||||||
from galaxy.api.consts import Feature
|
from galaxy.api.consts import Feature
|
||||||
@@ -21,6 +23,7 @@ class JSONEncoder(json.JSONEncoder):
|
|||||||
|
|
||||||
class Plugin():
|
class Plugin():
|
||||||
def __init__(self, platform, reader, writer, handshake_token):
|
def __init__(self, platform, reader, writer, handshake_token):
|
||||||
|
logging.info("Creating plugin for platform %s", platform.value)
|
||||||
self._platform = platform
|
self._platform = platform
|
||||||
|
|
||||||
self._feature_methods = OrderedDict()
|
self._feature_methods = OrderedDict()
|
||||||
@@ -167,7 +170,10 @@ class Plugin():
|
|||||||
async def pass_control():
|
async def pass_control():
|
||||||
while self._active:
|
while self._active:
|
||||||
logging.debug("Passing control to plugin")
|
logging.debug("Passing control to plugin")
|
||||||
self.tick()
|
try:
|
||||||
|
self.tick()
|
||||||
|
except Exception:
|
||||||
|
logging.exception("Unexpected exception raised in plugin tick")
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
await asyncio.gather(pass_control(), self._server.run())
|
await asyncio.gather(pass_control(), self._server.run())
|
||||||
@@ -309,22 +315,40 @@ class Plugin():
|
|||||||
async def get_game_times(self):
|
async def get_game_times(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
def create_and_run_plugin(plugin_class, argv):
|
def create_and_run_plugin(plugin_class, argv):
|
||||||
if not issubclass(plugin_class, Plugin):
|
root = logging.getLogger()
|
||||||
raise TypeError("plugin_class must be subclass of Plugin")
|
root.setLevel(logging.DEBUG)
|
||||||
|
if len(argv) >= 4:
|
||||||
|
handler = logging.handlers.RotatingFileHandler(argv[3], "a", 10000000, 10)
|
||||||
|
root.addHandler(handler)
|
||||||
|
|
||||||
if len(argv) < 3:
|
if len(argv) < 3:
|
||||||
raise ValueError("Not enough parameters, required: token, port")
|
logging.critical("Not enough parameters, required: token, port")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
token = argv[1]
|
token = argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
port = int(argv[2])
|
port = int(argv[2])
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
raise ValueError("Failed to parse port value, {}".format(e))
|
logging.critical("Failed to parse port value: %s", argv[2])
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
if not (1 <= port <= 65535):
|
if not (1 <= port <= 65535):
|
||||||
raise ValueError("Port value out of range (1, 65535)")
|
logging.critical("Port value out of range (1, 65535)")
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
if not issubclass(plugin_class, Plugin):
|
||||||
|
logging.critical("plugin_class must be subclass of Plugin")
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
async def coroutine():
|
async def coroutine():
|
||||||
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
||||||
plugin = plugin_class(reader, writer, token)
|
plugin = plugin_class(reader, writer, token)
|
||||||
await plugin.run()
|
await plugin.run()
|
||||||
asyncio.run(coroutine())
|
|
||||||
|
try:
|
||||||
|
asyncio.run(coroutine())
|
||||||
|
except Exception:
|
||||||
|
logging.exception("Error while running plugin")
|
||||||
|
sys.exit(5)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="galaxy.plugin.api",
|
name="galaxy.plugin.api",
|
||||||
version="0.7",
|
version="0.11",
|
||||||
description="Galaxy python plugin API",
|
description="Galaxy python plugin API",
|
||||||
author='Galaxy team',
|
author='Galaxy team',
|
||||||
author_email='galaxy@gog.com',
|
author_email='galaxy@gog.com',
|
||||||
|
|||||||
Reference in New Issue
Block a user