Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions ampapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions ampapi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.

Expand All @@ -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()
Expand Down
59 changes: 52 additions & 7 deletions ampapi/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1794,27 +1795,71 @@ 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
-----------
uuid: :class:`str`
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
Expand Down
9 changes: 5 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -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`_.

Expand All @@ -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*

Expand All @@ -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



Expand All @@ -42,6 +42,7 @@ Basic Usage

.. _Quick Example: ../samples/sample.py


.. toctree::
:maxdepth: 3
:caption: API Classes:
Expand Down
30 changes: 7 additions & 23 deletions docs/nodes/permission_nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########################
Expand Down Expand Up @@ -233,7 +238,6 @@ ADS Nodes
- ADS.AutoReactivate
- ADS.AutostartInstances
- ADS.ConfigurationRepositories
- ADS.DownloadMirror
- ADS.InstanceStartDelay
- ADS.Mode
- ADS.ShowDeprecated
Expand All @@ -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
^^^^^^^^^^^^^
Expand Down Expand Up @@ -316,26 +318,6 @@ AMP Nodes
- AMP.ShowHelpOnStatus
- AMP.Theme

Branding Nodes
^^^^^^^^^^^^^^^
:raw-html:`<hr>`

- Branding.*
- Branding.BackgroundURL
- Branding.BrandingMessage
- Branding.CompanyName
- Branding.DisplayBranding
- Branding.ForgotPasswordURL
- Branding.LogoURL
- Branding.PageTitle
- Branding.ShortBrandingMessage
- Branding.SplashFrameURL
- Branding.SubmitTicketURL
- Branding.SupportText
- Branding.SupportURL
- Branding.URL
- Branding.WelcomeMessage

Login Nodes
^^^^^^^^^^^^
:raw-html:`<hr>`
Expand Down Expand Up @@ -382,6 +364,7 @@ Security Nodes
- Security.IncludeExceptionDataInAPI
- Security.RateLimitLogins
- Security.RequireSessionIPStickiness
- Security.RequireTokenIPStickiness
- Security.TwoFactorMode

Webserver Nodes
Expand Down Expand Up @@ -495,6 +478,7 @@ SteamUpdateSettings Nodes
- SteamUpdateSettings.KeepSteamCMDScripts
- SteamUpdateSettings.ShowDownloadSpeedInBits
- SteamUpdateSettings.SteamCMDBetaPassword
- SteamUpdateSettings.SteamCMDValidateDownloads
- SteamUpdateSettings.ThrottleDownloadSpeed
- SteamUpdateSettings.UpdateCheckMethod

Expand Down
Loading
Loading