mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 11:28:12 -05:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43556a0470 | ||
|
|
e244d3bb44 | ||
|
|
d6e6efc633 | ||
|
|
a114c9721c | ||
|
|
6c0389834b | ||
|
|
bc7d1c2914 | ||
|
|
d69e1aaa08 | ||
|
|
c2a0534162 | ||
|
|
1614fd6eb2 | ||
|
|
48e54a8460 |
@@ -20,5 +20,7 @@ deploy_package:
|
||||
- curl -X POST --silent --show-error --fail
|
||||
"https://gitlab.gog.com/api/v4/projects/${CI_PROJECT_ID}/repository/tags?tag_name=${VERSION}&ref=${CI_COMMIT_REF_NAME}&private_token=${PACKAGE_DEPLOYER_API_TOKEN}"
|
||||
when: manual
|
||||
only:
|
||||
- master
|
||||
except:
|
||||
- tags
|
||||
0
galaxy/__init__.py
Normal file
0
galaxy/__init__.py
Normal file
@@ -12,6 +12,7 @@ class Platform(Enum):
|
||||
Battlenet = "battlenet"
|
||||
|
||||
class Feature(Enum):
|
||||
Unknown = "Unknown"
|
||||
ImportInstalledGames = "ImportInstalledGames"
|
||||
ImportOwnedGames = "ImportOwnedGames"
|
||||
LaunchGame = "LaunchGame"
|
||||
@@ -23,11 +24,19 @@ class Feature(Enum):
|
||||
ImportUsers = "ImportUsers"
|
||||
VerifyGame = "VerifyGame"
|
||||
|
||||
class LicenseType(Enum):
|
||||
Unknown = "Unknown"
|
||||
SinglePurchase = "SinglePurchase"
|
||||
FreeToPlay = "FreeToPlay"
|
||||
OtherUserLicense = "OtherUserLicense"
|
||||
|
||||
class LocalGameState(Enum):
|
||||
None_ = "None"
|
||||
Installed = "Installed"
|
||||
Running = "Running"
|
||||
|
||||
class PresenceState(Enum):
|
||||
Unknown = "Unknown"
|
||||
Online = "online"
|
||||
Offline = "offline"
|
||||
Away = "away"
|
||||
|
||||
@@ -20,6 +20,10 @@ class BackendError(ApplicationError):
|
||||
def __init__(self, data=None):
|
||||
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):
|
||||
def __init__(self, data=None):
|
||||
super().__init__(100, "Invalid credentials", data)
|
||||
|
||||
@@ -64,10 +64,12 @@ class Server():
|
||||
|
||||
async def run(self):
|
||||
while self._active:
|
||||
data = await self._reader.readline()
|
||||
if not data:
|
||||
# on windows rederecting a pipe to stdin result on continues
|
||||
# not-blocking return of empty line on EOF
|
||||
try:
|
||||
data = await self._reader.readline()
|
||||
if not data:
|
||||
self._eof()
|
||||
continue
|
||||
except:
|
||||
self._eof()
|
||||
continue
|
||||
data = data.strip()
|
||||
@@ -141,8 +143,8 @@ class Server():
|
||||
self._send_error(request.id, MethodNotFound())
|
||||
except JsonRpcError as error:
|
||||
self._send_error(request.id, error)
|
||||
except Exception as error: #pylint: disable=broad-except
|
||||
logging.error("Unexpected exception raised in plugin handler: %s", repr(error))
|
||||
except Exception: #pylint: disable=broad-except
|
||||
logging.exception("Unexpected exception raised in plugin handler")
|
||||
|
||||
asyncio.create_task(handle())
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import logging.handlers
|
||||
import dataclasses
|
||||
from enum import Enum
|
||||
from collections import OrderedDict
|
||||
import sys
|
||||
|
||||
from galaxy.api.jsonrpc import Server, NotificationClient
|
||||
from galaxy.api.consts import Feature
|
||||
@@ -21,6 +23,7 @@ class JSONEncoder(json.JSONEncoder):
|
||||
|
||||
class Plugin():
|
||||
def __init__(self, platform, reader, writer, handshake_token):
|
||||
logging.info("Creating plugin for platform %s", platform.value)
|
||||
self._platform = platform
|
||||
|
||||
self._feature_methods = OrderedDict()
|
||||
@@ -167,7 +170,10 @@ class Plugin():
|
||||
async def pass_control():
|
||||
while self._active:
|
||||
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.gather(pass_control(), self._server.run())
|
||||
@@ -309,22 +315,40 @@ class Plugin():
|
||||
async def get_game_times(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def create_and_run_plugin(plugin_class, argv):
|
||||
if not issubclass(plugin_class, Plugin):
|
||||
raise TypeError("plugin_class must be subclass of Plugin")
|
||||
root = logging.getLogger()
|
||||
root.setLevel(logging.DEBUG)
|
||||
if len(argv) >= 4:
|
||||
handler = logging.handlers.RotatingFileHandler(argv[3], "a", 10000000, 10)
|
||||
root.addHandler(handler)
|
||||
|
||||
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]
|
||||
|
||||
try:
|
||||
port = int(argv[2])
|
||||
except ValueError as e:
|
||||
raise ValueError("Failed to parse port value, {}".format(e))
|
||||
except ValueError:
|
||||
logging.critical("Failed to parse port value: %s", argv[2])
|
||||
sys.exit(2)
|
||||
|
||||
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():
|
||||
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
||||
plugin = plugin_class(reader, writer, token)
|
||||
await plugin.run()
|
||||
asyncio.run(coroutine())
|
||||
|
||||
try:
|
||||
asyncio.run(coroutine())
|
||||
except Exception:
|
||||
logging.exception("Error while running plugin")
|
||||
sys.exit(5)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from galaxy.api.consts import LocalGameState, PresenceState
|
||||
from galaxy.api.consts import LicenseType, LocalGameState, PresenceState
|
||||
|
||||
@dataclass
|
||||
class Authentication():
|
||||
@@ -10,8 +10,8 @@ class Authentication():
|
||||
|
||||
@dataclass
|
||||
class LicenseInfo():
|
||||
license_type: str
|
||||
owner: str = None
|
||||
license_type: LicenseType
|
||||
owner: Optional[str] = None
|
||||
|
||||
@dataclass
|
||||
class Dlc():
|
||||
@@ -39,8 +39,8 @@ class LocalGame():
|
||||
@dataclass
|
||||
class Presence():
|
||||
presence_state: PresenceState
|
||||
game_id: str = None
|
||||
presence_status: str = None
|
||||
game_id: Optional[str] = None
|
||||
presence_status: Optional[str] = None
|
||||
|
||||
@dataclass
|
||||
class UserInfo():
|
||||
|
||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="galaxy.plugin.api",
|
||||
version="0.4",
|
||||
version="0.11",
|
||||
description="Galaxy python plugin API",
|
||||
author='Galaxy team',
|
||||
author_email='galaxy@gog.com',
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import json
|
||||
|
||||
from galaxy.api.types import Game, Dlc, LicenseInfo
|
||||
from galaxy.api.consts import LicenseType
|
||||
from galaxy.api.errors import UnknownError
|
||||
|
||||
def test_success(plugin, readline, write):
|
||||
@@ -13,15 +14,15 @@ def test_success(plugin, readline, write):
|
||||
|
||||
readline.side_effect = [json.dumps(request), ""]
|
||||
plugin.get_owned_games.return_value = [
|
||||
Game("3", "Doom", None, LicenseInfo("SinglePurchase", None)),
|
||||
Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None)),
|
||||
Game(
|
||||
"5",
|
||||
"Witcher 3",
|
||||
[
|
||||
Dlc("7", "Hearts of Stone", LicenseInfo("SinglePurchase", None)),
|
||||
Dlc("8", "Temerian Armor Set", LicenseInfo("FreeToPlay", None)),
|
||||
Dlc("7", "Hearts of Stone", LicenseInfo(LicenseType.SinglePurchase, None)),
|
||||
Dlc("8", "Temerian Armor Set", LicenseInfo(LicenseType.FreeToPlay, None)),
|
||||
],
|
||||
LicenseInfo("SinglePurchase", None))
|
||||
LicenseInfo(LicenseType.SinglePurchase, None))
|
||||
]
|
||||
asyncio.run(plugin.run())
|
||||
plugin.get_owned_games.assert_called_with()
|
||||
@@ -89,7 +90,7 @@ def test_failure(plugin, readline, write):
|
||||
}
|
||||
|
||||
def test_add_game(plugin, write):
|
||||
game = Game("3", "Doom", None, LicenseInfo("SinglePurchase", None))
|
||||
game = Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None))
|
||||
|
||||
async def couritine():
|
||||
plugin.add_game(game)
|
||||
@@ -127,7 +128,7 @@ def test_remove_game(plugin, write):
|
||||
}
|
||||
|
||||
def test_update_game(plugin, write):
|
||||
game = Game("3", "Doom", None, LicenseInfo("SinglePurchase", None))
|
||||
game = Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None))
|
||||
|
||||
async def couritine():
|
||||
plugin.update_game(game)
|
||||
|
||||
Reference in New Issue
Block a user