diff --git a/Cargo.toml b/Cargo.toml index d7705ac..e5ca674 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,16 +8,12 @@ members = [ "members/libpt-bin", "members/libpt-log", "members/libpt-net", - "members/libpt-py", "members/libpt-hedu", ] default-members = [ ".", "members/libpt-bin", "members/libpt-core", - "members/libpt-py", - "members/libpt-log", - "members/libpt-math", ] [workspace.package] publish = true @@ -29,11 +25,10 @@ description = "Personal multitool" readme = "README.md" homepage = "https://git.cscherr.de/PlexSheep/libpt" repository = "https://git.cscherr.de/PlexSheep/libpt" -keywords = ["cli", "python", "scriptable", "pyo3", "library"] +keywords = ["cli", "library"] categories = ["command-line-utilities", "development-tools", "development-tools::ffi"] [workspace.dependencies] -pyo3 = "0.19" anyhow = "1.0.79" thiserror = "1.0.56" diff --git a/members/libpt-py/.github/workflows/CI.yml b/members/libpt-py/.github/workflows/CI.yml deleted file mode 100644 index 8268eaf..0000000 --- a/members/libpt-py/.github/workflows/CI.yml +++ /dev/null @@ -1,120 +0,0 @@ -# This file is autogenerated by maturin v1.1.0 -# To update, run -# -# maturin generate-ci github -# -name: CI - -on: - push: - branches: - - main - - master - tags: - - '*' - pull_request: - workflow_dispatch: - -permissions: - contents: read - -jobs: - linux: - runs-on: ubuntu-latest - strategy: - matrix: - target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter - sccache: 'true' - manylinux: auto - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - windows: - runs-on: windows-latest - strategy: - matrix: - target: [x64, x86] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - architecture: ${{ matrix.target }} - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter - sccache: 'true' - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - macos: - runs-on: macos-latest - strategy: - matrix: - target: [x86_64, aarch64] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Build wheels - uses: PyO3/maturin-action@v1 - with: - target: ${{ matrix.target }} - args: --release --out dist --find-interpreter - sccache: 'true' - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - sdist: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Build sdist - uses: PyO3/maturin-action@v1 - with: - command: sdist - args: --out dist - - name: Upload sdist - uses: actions/upload-artifact@v3 - with: - name: wheels - path: dist - - release: - name: Release - runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" - needs: [linux, windows, macos, sdist] - steps: - - uses: actions/download-artifact@v3 - with: - name: wheels - - name: Publish to PyPI - uses: PyO3/maturin-action@v1 - env: - MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} - with: - command: upload - args: --skip-existing * diff --git a/members/libpt-py/.gitignore b/members/libpt-py/.gitignore deleted file mode 100644 index af3ca5e..0000000 --- a/members/libpt-py/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -/target - -# Byte-compiled / optimized / DLL files -__pycache__/ -.pytest_cache/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -.venv/ -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -include/ -man/ -venv/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -.DS_Store - -# Sphinx documentation -docs/_build/ - -# PyCharm -.idea/ - -# VSCode -.vscode/ - -# Pyenv -.python-version \ No newline at end of file diff --git a/members/libpt-py/Cargo.toml b/members/libpt-py/Cargo.toml deleted file mode 100644 index e8efa77..0000000 --- a/members/libpt-py/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "libpt-py" -publish.workspace = true -version.workspace = true -edition.workspace = true -authors.workspace = true -license.workspace = true -description.workspace = true -readme.workspace = true -homepage.workspace = true -repository.workspace = true -keywords.workspace = true -categories.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -name = "libpt_py" -crate-type = ["cdylib"] - -[dependencies] -libpt = { version = "0.1.7", path = "../..", features = ["all"] } -pyo3 = { workspace = true } diff --git a/members/libpt-py/LICENSE b/members/libpt-py/LICENSE deleted file mode 100644 index 1709dc6..0000000 --- a/members/libpt-py/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 Christoph Johannes Scherr - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/members/libpt-py/README.md b/members/libpt-py/README.md deleted file mode 100644 index d1c15d3..0000000 --- a/members/libpt-py/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# pt / libpt - -![pt-logo](data/media/pt-logo.svg) - -`pt` stands for either one of "personal tool", "plex tool", "pete" or something among those lines. -It is a collection of tools that i might or might not use. The intended purpose of this repo is that -I program whatever i feel is worth having in a personal thing into it, then use it as either a lib, -crate, python module or executable. - -Let's see if I make it a bloated mess or stop committing after 30 hello worlds. - -#### But the name `pt` / `libpt` already exists! - -So what? I don't care. Besides, there is not enough names to name everything unique. - -## Dependencies - -- See `cargo.toml` -- [openssl bindings for rust](https://docs.rs/openssl/latest/openssl/) -- [Python](https://www.python.org/) -- [`maturin`](https://maturin.rs) - `pip install maturin` - -## Compiling & Installing from source - -If you only want the rust library, you can simply build it with `cargo build`. Add it to your -project like any other local dependency. - -If you want to use the python variant too, you need to compile with maturing. - -- Install in `venv`: `maturin develop --release` -- Install in system: `maturin build --release && pip install target/wheels/libpt-x.x.x-*` - -## Installing from [pypi](https://pypi.org) - -`libpt` has been packaged for [pypi.org](https://pypi.org/project/libpt/). - -You can install it with `pip install libpt` - -## Installing from [crates.io](https://crates.io) - -`libpt` has been packaged for [crates.io](https://crates.io/crates/libpt). - -You can add the library to your project with `cargo add libpt`. - -## Installing from my personal package registry - -`libpt` has been packaged for [git.cscherr.de](https://git.cscherr.de). - -You can add the registry to your `config.toml` and then `cargo add libpt` - -[Package](https://git.cscherr.de/PlexSheep/-/packages/cargo/libpt/) - -## Testing - -Testing needs to be done separately for the rust and python parts: - -- Rust testing with `cargo test` -- Python testing with `./scripts/pytests.sh` or `python -m unittest discover -fs tests/python` - -## Documentation - -The documentation can be automatically generated with `cargo doc --open`. - -An up to date version of the Documentation can be found [here](https://docs.rs/libpt/) - -## Mirrored - -The origin of this repository is [git.cscherr.de](https://git.cscherr.de/PlexSheep/pt) - -It is mirrored to: -- [Codeberg](https://codeberg.org/PlexSheep/pt) - - -## License - -**Pt is MIT Licensed** diff --git a/members/libpt-py/pyproject.toml b/members/libpt-py/pyproject.toml deleted file mode 100644 index 4b4f3ee..0000000 --- a/members/libpt-py/pyproject.toml +++ /dev/null @@ -1,25 +0,0 @@ -[build-system] -requires = ["maturin>=0.14,<0.15"] -build-backend = "maturin" - -[project] -name = "libpt" -readme = "README.md" -requires-python = ">=3.7" -authors = [{ name = "Christoph J. Scherr", email = "software@cscherr.de" }] -license = { file = "LICENSE" } -keywords = ["pyo3"] -classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", -] - -[project.urls] -Homepage = "https://git.cscherr.de/PlexSheep/libpt" - - -[tool.maturin] -features = ["pyo3/extension-module"] -python-source = "python" -module-name = "libpt._libpt" diff --git a/members/libpt-py/python/libpt/__init__.py b/members/libpt-py/python/libpt/__init__.py deleted file mode 100644 index 50c3db3..0000000 --- a/members/libpt-py/python/libpt/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from ._libpt import * diff --git a/members/libpt-py/python/libpt/__init__.pyi b/members/libpt-py/python/libpt/__init__.pyi deleted file mode 100644 index 9dc6a5e..0000000 --- a/members/libpt-py/python/libpt/__init__.pyi +++ /dev/null @@ -1,14 +0,0 @@ -""" -# libpt python bindings - -`libpt` is originally implemented in rust, but offers a python module too. -""" -from . import logger -from . import networking -from . import common - -def is_loaded() -> bool: - """ - returns true if `libpt` has been loaded - """ - ... diff --git a/members/libpt-py/python/libpt/common/__init__.pyi b/members/libpt-py/python/libpt/common/__init__.pyi deleted file mode 100644 index 11472a8..0000000 --- a/members/libpt-py/python/libpt/common/__init__.pyi +++ /dev/null @@ -1,7 +0,0 @@ -""" -common functionalities - -This module implements common functionality useful for many use cases, such as macros, -Formatting functions and more. -""" -from . import printing diff --git a/members/libpt-py/python/libpt/common/printing.pyi b/members/libpt-py/python/libpt/common/printing.pyi deleted file mode 100644 index 6cecacc..0000000 --- a/members/libpt-py/python/libpt/common/printing.pyi +++ /dev/null @@ -1,14 +0,0 @@ -""" -tools that make printing stuff better -""" -def divider() -> str: - """ - Quickly get a one line visual divider - """ - ... - -def print_divider(): - """ - Quickly print a one line visual divider - """ - ... diff --git a/members/libpt-py/python/libpt/logger.pyi b/members/libpt-py/python/libpt/logger.pyi deleted file mode 100644 index 4935bb8..0000000 --- a/members/libpt-py/python/libpt/logger.pyi +++ /dev/null @@ -1,65 +0,0 @@ -""" -# A specialized Logger for `libpt` -""" - -""" the default log level """ -DEFAULT_LOG_LEVEL = "INFO" -""" Set the value of this key as envar to set a loglevel """ -LOGGER_ENV_KEY = "LIBPT_LOGLEVEL" - -class Logger: - """ - `libpt` logger - - Call `init` once before usage, else all logging attempts will be ignored. - """ - def __init__(self): - """ - get a new logger - """ - ... - - @staticmethod - def init(): - """ - initialize the logger before the first usage - """ - ... - - @staticmethod - def init_specialized(color: bool): - """ - initialize the logger before the first usage, but with the ability to tweak things a bit - """ - ... - - def error(self, printable: str): - """ - log at level `error` - """ - ... - - def warn(self, printable: str): - """ - log at level `error` - """ - ... - - def info(self, printable: str): - """ - log at level `error` - """ - ... - - def debug(self, printable: str): - """ - log at level `error` - """ - ... - - def trace(self, printable: str): - """ - log at level `error` - """ - ... - diff --git a/members/libpt-py/python/libpt/networking/__init__.pyi b/members/libpt-py/python/libpt/networking/__init__.pyi deleted file mode 100644 index 9ac1f3b..0000000 --- a/members/libpt-py/python/libpt/networking/__init__.pyi +++ /dev/null @@ -1,7 +0,0 @@ -""" -# various networking tools - -The networking module contains various tools related to connections. For example, it contains a -tool that has the purpose to check if your connection is consistently available. -""" -from . import monitoring diff --git a/members/libpt-py/python/libpt/networking/monitoring/__init__.pyi b/members/libpt-py/python/libpt/networking/monitoring/__init__.pyi deleted file mode 100644 index fe0e3e9..0000000 --- a/members/libpt-py/python/libpt/networking/monitoring/__init__.pyi +++ /dev/null @@ -1,7 +0,0 @@ -""" -# monitor your network - -This module offers functions to monitor your network. -""" - -from . import uptime diff --git a/members/libpt-py/python/libpt/networking/monitoring/uptime.pyi b/members/libpt-py/python/libpt/networking/monitoring/uptime.pyi deleted file mode 100644 index f6dc4f8..0000000 --- a/members/libpt-py/python/libpt/networking/monitoring/uptime.pyi +++ /dev/null @@ -1,86 +0,0 @@ -""" -# monitor your network uptime - -This method offers a way to monitor your networks/hosts uptime. This is achieved by making -HTTPS requests to a given list of -""" - -class UptimeStatus: - """ - Describes an uptime status - - UptimeStatus describes the result of an uptime check. - """ - """ true if the [`UptimeStatus`] is considered successful""" - success: bool - """ the percentage of reachable urls out of the total urls""" - success_ratio: int - """ the percentage of reachable urls out of the total urls that need to be reachable in order - for this [`UptimeStatus`] to be considered a success. - """ - success_ratio_target: int - """ the number of reachable [`urls`](UptimeStatus::urls) """ - reachable: int - """ set a timeout (in ms) """ - timeout: int - """URL list cant be ported to python, use UptimeStatus.urls()""" - __urls: ... - - def __init__(self, success_ratio_target: int, url_strs: list[str], timeout: int) -> None: - """ - create a new UptimeStatus and check it - - `success_ratio_target` should never be more than 100 (it represents a success percentage) - """ - ... - - def check(self) -> None: - """ - checks if the stored urls - - Makes the actual https requests and updates fields accordingly. - - This method can block some time, as the web requests are implemented as blocking and - executed by the shared library (not in python) - """ - ... - - def calc_success(self) -> None: - """ - calculate the success based on the `reachable` and `total` - - Calculates the ratio of [reachable]/ - (length of [__urls]). - - Calculates a [`success_ratio`] from that, by multiplying with 100, then flooring. - - If the [`success_ratio`] is greater than or equal to the [`success_ratio_target`], - the [`UptimeStatus`] will be considered a success. - - In the special case that no URLs to check for have been provided, the check will be - considered a success, but the [`success_ratio`] will be `0`. - - Note: does not check for networking, use [`check()`] for that. - """ - ... - - def urls(self) -> list[str]: - """ - get urls for python - - Since [`__urls`] has no python equivalent, return the urls as a `list[str]` in - Python. - """ - ... - -def continuous_uptime_monitor(success_ratio_target: int, urls: list[str], interval: int, timeout: int) -> None: - """ - Uptime monitor - - This function continuously monitors the uptime of your host/network. - - On change of status, an update will be logged at INFO Level, containing - information on your current status, including timestamps of the last up/down time and durations - since. - """ - ... diff --git a/members/libpt-py/python/libpt/py.typed b/members/libpt-py/python/libpt/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/members/libpt-py/scripts/pytests.sh b/members/libpt-py/scripts/pytests.sh deleted file mode 100755 index 1971c0c..0000000 --- a/members/libpt-py/scripts/pytests.sh +++ /dev/null @@ -1 +0,0 @@ -python -m unittest discover -fs tests/python diff --git a/members/libpt-py/src/lib.rs b/members/libpt-py/src/lib.rs deleted file mode 100644 index d132821..0000000 --- a/members/libpt-py/src/lib.rs +++ /dev/null @@ -1,100 +0,0 @@ -// FIXME: Using a local dependency does not work with maturin as it seems? -// TODO: python interface for the logger -// use libpt::log::*; - -use pyo3::prelude::*; - -//// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// -/// ## Check if [`libpt`](crate) has been loaded -/// -/// Always returns `true` if you can execute it. -#[pyfunction] -pub fn is_loaded() -> bool { - true -} - -//// PRIVATE FUNCTIONS ///////////////////////////////////////////////////////////////////////////// -/// ## Python module: logger -#[pymodule] -fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "logger")?; - // module.add_class::()?; - - parent.add_submodule(module)?; - Ok(()) -} -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: common -// #[pymodule] -// fn py_common(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "common")?; -// py_common_printing(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: common.printing -// #[pymodule] -// fn py_common_printing(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "printing")?; -// module.add_function(wrap_pyfunction!(common::printing::divider, module)?)?; -// module.add_function(wrap_pyfunction!(common::printing::print_divider, module)?)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking -// #[pymodule] -// fn py_networking(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "networking")?; -// py_networking_monitoring(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking.monitoring -// #[pymodule] -// fn py_networking_monitoring(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "monitoring")?; -// py_networking_monitoring_uptime(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking.monitoring.uptime -// #[pymodule] -// fn py_networking_monitoring_uptime(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "uptime")?; -// module.add_class::()?; -// module.add_function(wrap_pyfunction!( -// networking::monitoring::uptime::py_continuous_uptime_monitor, -// module -// )?)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// ## Python module: root -/// -/// This function is the entry point of [`PyO3`](pyo3). This is where the main module is built. -#[pymodule] -fn _libpt(py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(is_loaded, m)?)?; - - // load sub modules - // py_common(py, m)?; - py_logger(py, m)?; - // py_networking(py, m)?; - Ok(()) -}