From cdd1361ef8f6487b154f327b71680b1f2f45ba80 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <68672235+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:32:53 -0800 Subject: [PATCH 1/3] # CHANGELOG.md - Removed merge messages. # __init__.py - Version bump to `1.1.0` # pyproject.toml - Changed the readme property's file extension and content-type. - Removed comment. # build.yml - Removed comment. # core.py - Fixed issue mentioned in #13 -- All connected players are represented in a `Players` dataclass. You can access the list via the `sorted` attribute. - Fixed typo on LN1459. # dataclass.py - New `Players` Dataclass and a `Player` NamedTuple to house the data. -- `Players.get_player(name_or_uuid: str)` now exists to allow for searching of players by name or uuid. # index.rst - Fixed incorrect information throughout. # types.rst - Added API Modules. # README.md - Fixed incorrect information throughout. --- .github/workflows/build.yml | 2 +- README.md | 11 +++---- ampapi/core.py | 12 ++++---- ampapi/dataclass.py | 59 ++++++++++++++++++++++++++++++++----- docs/index.rst | 9 +++--- docs/types.rst | 20 ++++++++++++- pyproject.toml | 4 +-- 7 files changed, 91 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 945113a..e78c70d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: with: name: artifact-source-dist path: "./**/dist/*.tar.gz" -# TODO - Need to finish implementing this. + upload_pypi: # This only fires when we generate a release. if: ${{github.event.release}} diff --git a/README.md b/README.md index 03cd85e..2e441ed 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,15 @@ ___ To install run the below command to install the required pip packages from [Requirements](./requirements.txt) ### PyPi --> https://pypi.org/project/cubecoders-amp-api-wrapper/ +___ +-> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/) + ```bash -# Linux/macOS -pip install cubecoders-amp-api-wrapper +# Linux/macOS/Windows +pip install cc-ampapi -# Windows -pip install cubecoders-amp-api-wrapper ``` + ### Basic Usage ___ 1. First you need to fill out the APIParams class with the required fields (url, user and password). diff --git a/ampapi/core.py b/ampapi/core.py index 1d76597..641423b 100644 --- a/ampapi/core.py +++ b/ampapi/core.py @@ -1456,8 +1456,8 @@ async def get_user_info(self, user_id: str, format_data: Union[bool, None] = Non Returns -------- - :class:`UserAPplicationData` - On success returns a :class:`UserAPplicationData` class. + :class:`UserApplicationData` + On success returns a :class:`UserApplicationData` class. """ await self._connect() @@ -1467,8 +1467,8 @@ async def get_user_info(self, user_id: str, format_data: Union[bool, None] = Non ) return result - async def get_user_list(self, format_data: Union[bool, None] = None) -> list[Players]: - """|coro| + async def get_user_list(self, format_data: Union[bool, None] = None) -> Players: + """|coro|Players Returns the list of the connected users to the Application. @@ -1479,8 +1479,8 @@ async def get_user_list(self, format_data: Union[bool, None] = None) -> list[Pla Returns -------- - list[:class:`Players`] - On success returns a list of :class:`Player` dataclasses. + :class:`Players` + On success returns a :class:`Players` dataclasses. """ await self._connect() diff --git a/ampapi/dataclass.py b/ampapi/dataclass.py index c41f604..bd43e87 100644 --- a/ampapi/dataclass.py +++ b/ampapi/dataclass.py @@ -5,8 +5,9 @@ from dataclasses import dataclass, field, fields from datetime import datetime from logging import Logger +from operator import attrgetter from pprint import pformat -from typing import TYPE_CHECKING, Any, ClassVar, Union +from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Union from dataclass_wizard.errors import MissingFields from typing_extensions import Self @@ -1794,10 +1795,9 @@ class PlatformInfo: installed_glibc_version: str = field(default="") # "AMPVersionInfo" -@dataclass(init=False) -class Players: +class Player(NamedTuple): """ - Represents the JSON response data from :meth:`~Core.get_user_list`. + Represents a single player connected to a server. Attributes ----------- @@ -1805,16 +1805,61 @@ class Players: The UUID of the player. name: :class:`str` The name of the player. - """ uuid: str = "" name: str = "" + def __eq__(self, other: object) -> bool: + return isinstance(other, self.__class__) and self.name == other.name + + def __lt__(self, other: object) -> bool: + return isinstance(other, self.__class__) and self.name < other.name + + +@dataclass(init=False) +class Players: + """ + Represents the JSON response data from :meth:`~Core.get_user_list`. + + + .. note:: + The print out of this dataclass can be long depending on the number of players connected due to separation by newline. + + + Attributes + ----------- + sorted: list[:class:`Player`] + A sorted list of :class:`Player` objects by name. + + """ + + # {'781a2971-c14b-42c2-8742-d1e2b029d00a': 'k8_thekat', '50686fad-4027-4bdb-a4a5-2533f8a1e51f': 'WolfDevilAngel'} + sorted: list[Player] + def __init__(self, data: dict[str, str]) -> None: for uuid, name in data.items(): - setattr(self, "id", uuid) - setattr(self, "name", name) + self.sorted.append(Player(uuid=uuid, name=name)) + self.sorted.sort(key=attrgetter("name")) + + def __repr__(self) -> str: + return "\n".join([p.name for p in self.sorted]) + + def get_player(self, name_or_uuid: str) -> list[Player]: + """ + Search for a player by their name or UUID. + + Parameters + ----------- + name_or_uuid: :class:`str` + The players name or UUID. + + Returns + -------- + :class:`list[Player]` + A list of :class:`Player` objects matching the search string. + """ + return [p for p in self.sorted if name_or_uuid in (p.name, p.uuid)] @dataclass diff --git a/docs/index.rst b/docs/index.rst index ec1409d..418dd56 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ AMP API Python ============== -.. _PyPi: https://pypi.org/project/cubecoders-amp-api-wrapper/ +.. _PyPi: https://pypi.org/project/cc-ampapi/ The project can be found on `PyPi`_. @@ -11,13 +11,13 @@ Key Features - Pythonic API wrapper using `async` and `await`. - Data is in dataclasses for easier management and interaction. - Optional parameter per function or global to disable formatting of data. -- Parent classes `AMPADSInstance`, `AMPInstance`, `AMPMinecraftInstance` to group endpoints together and make handling of multiple Instances easier. +- Parent classes `ADSInstance` and `AMPInstance` to group endpoints together and make handling of multiple Instances easier. - This will also limit Instance specific API endpoints (eg. Minecraft) to that Instance type only. - - Built in functions to start, stop, restart and update AMPInstances that are NOT an ADS/Controller. Installing ========== + .. note:: *Python 3.10 or higher is required* @@ -28,7 +28,7 @@ To install run the below command in a Terminal. :linenos: # Linux/macOS/Windows - pip install cubecoders-amp-api-wrapper + pip install cc-ampapi @@ -42,6 +42,7 @@ Basic Usage .. _Quick Example: ../samples/sample.py + .. toctree:: :maxdepth: 3 :caption: API Classes: diff --git a/docs/types.rst b/docs/types.rst index 0abf02a..ed166f0 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -98,4 +98,22 @@ Dataclasses ~~~~~~~~~~~~ .. automodule:: ampapi.dataclass - :members: \ No newline at end of file + :members: + + +.. currentmodule:: ampapi.modules + +Data Modules +~~~~~~~~~~~~~ + +.. autoclass:: DeploymentTemplate + :members: + +.. autoclass:: UserApplicationData + :members: + +.. autoclass:: TriggerID + :members: + + +.. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 55f4cfd..2ebca9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,12 +3,12 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] -name = "cc-ampapi" # cc-ampapi +name = "cc-ampapi" dynamic = ["version"] authors = [ { name = "k8thekat", email = "Cadwalladerkatelynn+AMPAPI@gmail.com" }, ] -readme = { file = "README.txt", content-type = "text/markdown" } +readme = { file = "README.md", content-type = "text/markdown" } description = "A Python wrapper for the AMP API by CubeCoders" requires-python = ">=3.10.0" license = { file = "LICENSE" } From 2c8094f4ffc3c14490740849c670649904c1240b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <68672235+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:42:39 -0800 Subject: [PATCH 2/3] # __init__.py - Version bump to `1.1.0` # nodes - Updated documentation for permission and setting nodes. --- ampapi/__init__.py | 4 +- docs/nodes/permission_nodes.rst | 30 +++--------- docs/nodes/setting_nodes.rst | 84 ++++----------------------------- 3 files changed, 19 insertions(+), 99 deletions(-) diff --git a/ampapi/__init__.py b/ampapi/__init__.py index 81eb0ae..5c0873e 100644 --- a/ampapi/__init__.py +++ b/ampapi/__init__.py @@ -25,7 +25,7 @@ __title__ = "CubeCoders AMP API" __author__ = "k8thekat" __license__ = "GNU" -__version__ = "1.0.7" +__version__ = "1.1.0" __credits__ = "AMP by CubeCoders and associates." from typing import Literal, NamedTuple @@ -55,6 +55,6 @@ class VersionInfo(NamedTuple): releaseLevel: Literal["alpha", "beta", "pre-release", "release", "development"] -version_info: VersionInfo = VersionInfo(Major=1, Minor=0, Revision=6, releaseLevel="release") +version_info: VersionInfo = VersionInfo(Major=1, Minor=1, Revision=0, releaseLevel="release") del NamedTuple, Literal, VersionInfo diff --git a/docs/nodes/permission_nodes.rst b/docs/nodes/permission_nodes.rst index c0c6103..1f93fe9 100644 --- a/docs/nodes/permission_nodes.rst +++ b/docs/nodes/permission_nodes.rst @@ -202,6 +202,11 @@ Instances Permission Nodes - Instances.`instance-id`.Start - Instances.`instance-id`.Stop - Instances.`instance-id`.Update +- Instances.`instance-id`.Manage +- Instances.`instance-id`.Restart +- Instances.`instance-id`.Start +- Instances.`instance-id`.Stop +- Instances.`instance-id`.Update Settings Permission Nodes ########################## @@ -233,7 +238,6 @@ ADS Nodes - ADS.AutoReactivate - ADS.AutostartInstances - ADS.ConfigurationRepositories -- ADS.DownloadMirror - ADS.InstanceStartDelay - ADS.Mode - ADS.ShowDeprecated @@ -260,12 +264,10 @@ Defaults Nodes - Defaults.DefaultReleaseStream - Defaults.DefaultSettings - Defaults.ExcludeFromFirewall -- Defaults.MatchVersion - Defaults.NewInstanceKey - Defaults.PropagateAuthServer - Defaults.PropogateRepos - Defaults.UseDocker -- Defaults.UseOverlays Limits Nodes ^^^^^^^^^^^^^ @@ -316,26 +318,6 @@ AMP Nodes - AMP.ShowHelpOnStatus - AMP.Theme -Branding Nodes -^^^^^^^^^^^^^^^ -:raw-html:`