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/CHANGELOG.md b/CHANGELOG.md index 3199341..c7a98dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,43 @@ +## Version - 1.1.0 - [2c8094f](https://github.com/k8thekat/AMPAPI_Python/commit/2c8094f) +#### Changelog.md +- Version info from `1.0.7` added. + +#### __init__.py +- Version bump to `1.1.0` + +#### __init__.py +- Version bump to `1.1.0` +- Version bump to `1.1.0` + +#### nodes +- Updated documentation for permission and setting nodes. +- Removed merge messages. + +#### 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. + ## Version - 1.0.7 - [8bb2fdc](https://github.com/k8thekat/AMPAPI_Python/commit/8bb2fdc) #### Changelog.md - Version info from `1.0.6` added. diff --git a/README.md b/README.md index d59e4f3..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 +___ -> Visit the package on [Pypi](https://pypi.org/project/cc-ampapi/) + ```bash -# Linux/macOS +# Linux/macOS/Windows pip install cc-ampapi -# Windows -pip install cc-ampapi ``` + ### Basic Usage ___ 1. First you need to fill out the APIParams class with the required fields (url, user and password). 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/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/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:`