generated from PlexSheep/baserepo
Compare commits
3 commits
341a64a0f5
...
0e9da09102
Author | SHA1 | Date | |
---|---|---|---|
0e9da09102 | |||
9d1a242060 | |||
cbd0717cc6 |
16 changed files with 175 additions and 78 deletions
|
@ -61,9 +61,6 @@ hedu = ["bintols"]
|
|||
|
||||
[lib]
|
||||
name = "libpt"
|
||||
# I chose a bad name for my package and i will have to live with it.
|
||||
# make issue here to make it possible to name the lib file in cargo
|
||||
# https://github.com/rust-lang/cargo/issues/1970
|
||||
crate-type = [
|
||||
"dylib", # .dll, .so, .dynlib
|
||||
"staticlib" # .lib, .a
|
||||
|
|
|
@ -15,4 +15,16 @@ categories.workspace = true
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[[bin]]
|
||||
name = "ccc"
|
||||
path = "src/ccc/mod.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "pt"
|
||||
path = "src/main/mod.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.4.4", features = ["derive"] }
|
||||
clap-num = "1.0.2"
|
||||
clap-verbosity-flag = "2.0.1"
|
||||
libpt = { version = "0.1.7", path = "../..", features = ["ccc", "math", "hedu", "net"] }
|
||||
|
|
|
@ -15,11 +15,10 @@
|
|||
#![warn(clippy::pedantic)]
|
||||
|
||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
use pt::math::calculator::{*, self};
|
||||
use pt::logger::*;
|
||||
use libpt::ccc::*;
|
||||
use libpt::log::*;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap_num::number_range;
|
||||
use clap::Parser;
|
||||
use clap_verbosity_flag::{Verbosity, InfoLevel};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
@ -42,6 +41,7 @@ static LONG_ABOUT_ROOT: &'static str = r##"
|
|||
"##;
|
||||
|
||||
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
/// defines CLI interface
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[command(
|
||||
author,
|
||||
|
@ -81,12 +81,12 @@ pub struct Cli {
|
|||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let ll: tracing::Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => tracing::Level::TRACE,
|
||||
"DEBUG" => tracing::Level::DEBUG,
|
||||
"INFO" => tracing::Level::INFO,
|
||||
"WARN" => tracing::Level::WARN,
|
||||
"ERROR" => tracing::Level::ERROR,
|
||||
let ll: Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => Level::TRACE,
|
||||
"DEBUG" => Level::DEBUG,
|
||||
"INFO" => Level::INFO,
|
||||
"WARN" => Level::WARN,
|
||||
"ERROR" => Level::ERROR,
|
||||
_ => {
|
||||
eprintln!("'{}' is not a valid loglevel", cli.verbose.to_string());
|
||||
std::process::exit(1);
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
|
@ -15,11 +15,7 @@
|
|||
|
||||
|
||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
use pt::{logger, networking::monitoring::uptime, common::*};
|
||||
|
||||
// we want the log macros in any case
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
use libpt::{log::*, net::monitoring::uptime};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
|
@ -45,19 +41,19 @@ use std::path::PathBuf;
|
|||
/// ## Main function of the [`pt`](crate) binary
|
||||
pub fn main() {
|
||||
let cli = Cli::parse();
|
||||
let ll: tracing::Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => tracing::Level::TRACE,
|
||||
"DEBUG" => tracing::Level::DEBUG,
|
||||
"INFO" => tracing::Level::INFO,
|
||||
"WARN" => tracing::Level::WARN,
|
||||
"ERROR" => tracing::Level::ERROR,
|
||||
let ll: Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => Level::TRACE,
|
||||
"DEBUG" => Level::DEBUG,
|
||||
"INFO" => Level::INFO,
|
||||
"WARN" => Level::WARN,
|
||||
"ERROR" => Level::ERROR,
|
||||
_ => {
|
||||
eprintln!("'{}' is not a valid loglevel", cli.verbose.to_string());
|
||||
std::process::exit(EXIT_FAILURE_USAGE);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
if cli.log_meta {
|
||||
logger::Logger::init_customized(
|
||||
Logger::init_customized(
|
||||
false,
|
||||
PathBuf::from("/dev/null"),
|
||||
true,
|
||||
|
@ -72,7 +68,7 @@ pub fn main() {
|
|||
.expect("could not initialize Logger");
|
||||
} else {
|
||||
// less verbose version
|
||||
logger::Logger::init_customized(
|
||||
Logger::init_customized(
|
||||
false,
|
||||
PathBuf::from("/dev/null"),
|
||||
true,
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
//* # Tools to work with binary values, memory, storage
|
||||
//!
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
|
||||
// official binary prefixes, see [https://en.wikipedia.org/wiki/Binary_prefix]
|
||||
/// 2^10
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
//! # Calculate expressions
|
||||
//!
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! Calculate Calculations with your Calculator (`ccc`)
|
||||
//!
|
||||
//! This modules aim is to take a term of any kind ([String]) and calculate it's value, be it
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
//! # common functionalities
|
||||
//!
|
||||
//! This module implements common functionality useful for many use cases, such as macros,
|
||||
//! Formatting functions and more.
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! This crate implements core functionality useful for many use cases, such as macros,
|
||||
//! formatting functions and more.
|
||||
|
||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||
// we want docs
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
//! # Dump data
|
||||
//!
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! This crate is currently empty.
|
||||
|
|
|
@ -16,7 +16,6 @@ categories.workspace = true
|
|||
tracing = "0.1.37"
|
||||
tracing-appender = "0.2.2"
|
||||
tracing-subscriber = "0.3.17"
|
||||
env_logger = "0.10.0"
|
||||
pyo3 = {workspace = true}
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
//! # very short description
|
||||
//! # Error module for [`pt-log`](crate)
|
||||
//!
|
||||
//! Short description
|
||||
//!
|
||||
//! Details
|
||||
//!
|
||||
//! ## Section 1
|
||||
//!
|
||||
//! ## Section 2
|
||||
//! This module handles errors in logging contexts.
|
||||
|
||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||
// we want docs
|
||||
|
@ -22,7 +16,7 @@ use pyo3::{exceptions::PyException, PyErr};
|
|||
use tracing::subscriber::SetGlobalDefaultError;
|
||||
|
||||
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// a quick alias for a result with a [`LoggerError`]
|
||||
/// a quick alias for a result with a [`Error`]
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -32,7 +26,7 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// ## Errors for the [logger](crate::logger)
|
||||
/// ## Errors for the [Logger](super::Logger)
|
||||
pub enum Error {
|
||||
/// Bad IO operation
|
||||
IO(std::io::Error),
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
//! # A specialized Logger for [`pt`](crate)
|
||||
//! # A specialized Logger for [`pt`](../libpt/index.html)
|
||||
//!
|
||||
//! For the library version, only the basic [`log`] is used, so that it is possible for
|
||||
//! the end user to use the [`log`] frontend they desire.
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! For the library version, only the basic [`tracing`] is used, so that it is possible for
|
||||
//! the end user to use the [`tracing`] frontend they desire.
|
||||
//!
|
||||
//! I did however decide to create a [`Logger`] struct. This struct is mainly intended to be used
|
||||
//! with the python module of [`pt`](crate), but is still just as usable in other contexts.
|
||||
//! with the python module of [`pt`](../libpt/index.html), but is still just as usable in other contexts.
|
||||
//!
|
||||
//! ## Technologies used for logging:
|
||||
//! - [`log`]: base logging crate
|
||||
//! - [`env_logger`]: used for the executable
|
||||
//! - [`tracing`]: base logging crate
|
||||
//! - [`tracing_appender`]: Used to log to files
|
||||
//! - [`tracing_subscriber`]: Used to do actual logging, formatting, to stdout
|
||||
|
||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -39,21 +43,10 @@ pub const DEFAULT_LOG_DIR: &'static str = "/dev/null";
|
|||
static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
/// ## Logger for [`pt`](crate)
|
||||
/// ## Logger for [`pt`](../libpt/index.html)
|
||||
///
|
||||
/// This struct exists mainly for the python module, so that we can use the same logger with both
|
||||
/// python and rust.
|
||||
///
|
||||
/// ### Setting a [`Level`](log::Level)
|
||||
///
|
||||
/// To set a [`Level`](log::Level), you need to set the environment variable `LIBPT_LOGLEVEL`
|
||||
/// to either of:
|
||||
///
|
||||
/// - `Trace`
|
||||
/// - `Debug`
|
||||
/// - `Info`
|
||||
/// - `Warn`
|
||||
/// - `Error`
|
||||
#[pyclass]
|
||||
pub struct Logger {}
|
||||
|
||||
|
@ -71,7 +64,7 @@ impl Logger {
|
|||
///
|
||||
/// Will enable the logger to be used.
|
||||
///
|
||||
/// Assumes some defaults, use [`init_customized`](init_customized) for more control
|
||||
/// Assumes some defaults, use [`init_customized`](Self::init_customized) for more control
|
||||
pub fn init(log_dir: Option<PathBuf>, max_level: Option<Level>) -> Result<()> {
|
||||
Self::init_customized(
|
||||
log_dir.is_some(),
|
||||
|
@ -154,35 +147,35 @@ impl Logger {
|
|||
}
|
||||
}
|
||||
|
||||
/// ## logging at [`Level::Error`]
|
||||
/// ## logging at [`Level::ERROR`]
|
||||
pub fn error<T>(&self, printable: T)
|
||||
where
|
||||
T: fmt::Display,
|
||||
{
|
||||
error!("{}", printable)
|
||||
}
|
||||
/// ## logging at [`Level::Warn`]
|
||||
/// ## logging at [`Level::WARN`]
|
||||
pub fn warn<T>(&self, printable: T)
|
||||
where
|
||||
T: fmt::Display,
|
||||
{
|
||||
warn!("{}", printable)
|
||||
}
|
||||
/// ## logging at [`Level::Info`]
|
||||
/// ## logging at [`Level::INFO`]
|
||||
pub fn info<T>(&self, printable: T)
|
||||
where
|
||||
T: fmt::Display,
|
||||
{
|
||||
info!("{}", printable)
|
||||
}
|
||||
/// ## logging at [`Level::Debug`]
|
||||
/// ## logging at [`Level::DEBUG`]
|
||||
pub fn debug<T>(&self, printable: T)
|
||||
where
|
||||
T: fmt::Display,
|
||||
{
|
||||
debug!("{}", printable)
|
||||
}
|
||||
/// ## logging at [`Level::Trace`]
|
||||
/// ## logging at [`Level::TRACE`]
|
||||
pub fn trace<T>(&self, printable: T)
|
||||
where
|
||||
T: fmt::Display,
|
||||
|
@ -248,7 +241,7 @@ impl Logger {
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
impl fmt::Debug for Logger {
|
||||
/// ## Debug representation for [`Logger`]
|
||||
/// ## DEBUG representation for [`Logger`]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
//! # very short description
|
||||
//! # General Mathmatics functionalities
|
||||
//!
|
||||
//! Short description
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! Details
|
||||
//!
|
||||
//! ## Section 1
|
||||
//!
|
||||
//! ## Section 2
|
||||
//! This module is currently empty, but will contain many math functionalities in a future version.
|
||||
|
||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||
// we want docs
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
//! # various networking tools
|
||||
//!
|
||||
//! This crate is part of [`pt`](../libpt/index.html), but can also be used as a standalone
|
||||
//! module.
|
||||
//!
|
||||
//! 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.
|
||||
|
||||
|
|
21
members/pt-py/LICENSE
Normal file
21
members/pt-py/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
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.
|
76
members/pt-py/README.md
Normal file
76
members/pt-py/README.md
Normal file
|
@ -0,0 +1,76 @@
|
|||
# pt / libpt
|
||||
|
||||

|
||||
|
||||
`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**
|
Reference in a new issue