Skip to content

Commit

Permalink
Move all utils into utils-box
Browse files Browse the repository at this point in the history
  • Loading branch information
Agathoklis Papadopoulos committed Oct 3, 2023
1 parent 832b759 commit 15e0b47
Show file tree
Hide file tree
Showing 21 changed files with 2,852 additions and 3 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
on: [push, pull_request]

name: Sanity

jobs:
Formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt

- name: Check format
run: cargo fmt -- --check

Linting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

Testing:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo tests
uses: actions-rs/cargo@v1
env:
RUST_BACKTRACE: 1
with:
command: test
args: --all-features -- --show-output

Coverage:
needs: Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Install cargo-tarpaulin
uses: actions-rs/install@v0.1
with:
crate: cargo-tarpaulin
version: latest
use-tool-cache: true

- name: Coverage with tarpaulin
run: cargo tarpaulin --all --all-features --timeout 600 --out lcov -- --test-threads 1

- name: Upload coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
**/target
**/Cargo.lock
**/bindings.rs

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand All @@ -12,3 +13,7 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# SDK Generated files
**/.project
**/.vscode
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: rust
before_install:
- rustup component add rustfmt
script:
- cargo build --all-features --verbose
- cargo fmt --all -- --check
- cargo test --all-features --verbose -- --show-output
53 changes: 53 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "utils-box"
version = "0.1.1"
edition = "2021"
authors = ["Agathoklis Papadopoulos <klis.pap@gmail.com>"]
license = "MIT"
readme = "README.md"

description = "A toolbox of various small RUST utilities that make our lifes easier"
categories = ["utilities"]
keywords = [
"tools", "utilities", "utils", "toolbox"
]
exclude = [
".github",
"Cargo.toml.orig",
"cargo_vcs_info.json",
]
repository = "https://github.com/klispap/utils-box"


[dependencies]
anyhow = "1.0.69"
log = "0.4.17"
simplelog = "0.11.0"
file-rotate = "0.7.1"
chrono = "0.4.22"
lazy_static = "1.4.0"
tokio = { version = "1", features = ["rt", "net", "macros", "time", "rt-multi-thread"] }
tokio-util = "0.6.7"
futures = "0.3.15"
rayon = "1.6.0"
walkdir = "2.3.2"
tar = "0.4.38"
zmq = "0.10.0"
glob = "0.3.1"
flate2 = "1.0"
semver = "1.0.16"
zip = "0.6.4"
regex = "1.7.1"
names = "0.14.0"
rust-ini = "0.18.0"
directories = "5.0.1"

[target.'cfg(unix)'.dependencies]
ssh2 = { version = "0.9.4", features = ["vendored-openssl"] }
signal-hook = "0.3.9"
signal-hook-tokio = { version = "0.3.0", features = ["futures-v0_3"] }

[dev-dependencies]
indoc = "1.0.3"
tempfile = "3.2.0"
named-lock = "0.3.0"
169 changes: 168 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,168 @@
# utils-box
[![Coverage Status](https://coveralls.io/repos/github/klispap/utils-box/badge.svg?branch=master)](https://coveralls.io/github/klispap/utils-box?branch=master)

# Summary
A toolbox library that holds a useful collection of small unitilies written in Rust that make our life easier when writting Rust applications.

# Utilities provided:

## Archives
Extract files from Tar, Gz and Zip Files

Mininal Example:
```rust
let archive: PathBuf = std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("test_archive.tar.gz");

let file: PathBuf = "treasure.hex".into();

let destination: PathBuf = std::env::current_exe()
.unwrap()
.parent()
.unwrap();

archives::extract_file(archive, ArchiveType::Gz, file, destination).unwrap();

```

## Bits
Convertions between different representations of raw bit streams

Mininal Example:
```rust
let received_bit_stream: u64 = 0b110101000100111010110;

let bytes = bits::bits_to_vec(received_bit_stream,21);

println!("Received bit stream: {} ", bits::bit_vec_to_hex_string(&bytes));

```

## Config
Manipulate INI-style configuration files by checking for changes, updates etc

Mininal Example:
```rust
let mut config_changes = ini_compare(
&old_config_path.to_path_buf(),
&new_config_path.to_path_buf(),
)
.unwrap();

println!("{:#?}", config_changes);

```

## Logger
Initialize terminal and file loggers fast. Macros for log printing to either log or stdout (if a global logger is not initialized)

Mininal Example:
```rust
log_info!("INFO Test TO PRINTLN!");
log_debug!("DEBUG Test TO PRINTLN!");

terminal_logger_init(LevelFilter::Debug);

log_info!("INFO Test TO LOGGER!");
log_debug!("DEBUG Test TO LOGGER!");

```

## Paths
Search paths for a specific file in directories with known or unknown paths

Mininal Example:
```rust
let paths = IncludePathsBuilder::new()
.include_exe_dir()
.include_known("/home/user/")
.include_unknown("utils-box")
.build();

let pattern = "test_*.tar";

let file_found_in = paths.search_glob(pattern);

```

## Versions
version parser from strings using the `semver.org` notations

Mininal Example:
```rust
let version = "0.9.2-1e341234";

let mut expected = Version::new(0, 9, 2);
expected.pre = Prerelease::new("1e341234").unwrap();

assert_eq!(semver_parse(version).unwrap(), expected);

```

## SSH Client
Connect via SSH to a server to perform commands, upload & download files

Mininal Example:
```rust
let ssh = SshClient::local("user".to_string(), "1234".to_string()).unwrap();

let stdout = ssh.execute_cmd("ls").unwrap();

println!("{:?}", stdout);

```

## TCP Client
Connect via TCP to a socket to send and receive data

Mininal Example:
```rust
let mut tcp_client = TcpClient::new("192.168.1.17".to_string(), 36457)?;

let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];

tcp_client.send(&data)?;

// Block and wait for response
let resp = tcp_client.receive()?;

println!("{:?}", resp);

```

## TCP Client
Connect via UDP to a socket to send and receive data

Mininal Example:
```rust
let mut udp =
UdpClient::new("0.0.0.0".to_string(), "192.168.1.31".to_string(), 6123).unwrap();

udp.send(b"\r").unwrap();

// Block and wait for response
let data = udp.receive().unwrap();

println!("{:?} => {}", data, String::from_utf8_lossy(&data));

```

## ZMQ Client
Connect to a ZMQ server to send and receive data

Mininal Example:
```rust
let zmq_client = ZmqClient::new(("192.168.1.17".to_string(), 36457)?;

let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];

zmq_client.send(&data)?;

// Block and wait for response
let resp = zmq_client.receive()?;

println!("{:?}", resp);

```
Loading

0 comments on commit 15e0b47

Please sign in to comment.