Skip to content

Commit 8b97aae

Browse files
committed
Refactoring: Seperate utils-box-linux
1 parent bb14856 commit 8b97aae

6 files changed

Lines changed: 394 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ members = [
1111
"utils-box-mathematics",
1212
"utils-box-pathfinder",
1313
"utils-box-stopwatch",
14-
# "utils-box-threads",
14+
"utils-box-linux",
1515
# "utils-box-versions",
1616
]

utils-box-linux/Cargo.toml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[package]
2+
name = "utils-box-linux"
3+
version = "1.0.1"
4+
edition = "2024"
5+
authors = ["Agathoklis Papadopoulos <klis.pap@gmail.com>"]
6+
license = "MIT"
7+
readme = "README.md"
8+
publish = ["crates-io"]
9+
10+
description = "A toolbox of various small RUST utilities that make UNIX thread handling easier"
11+
categories = ["development-tools", "config", "network-programming", "parsing"]
12+
keywords = ["tools", "utilities", "utils", "toolbox"]
13+
exclude = [".github", "Cargo.toml.orig", "cargo_vcs_info.json"]
14+
repository = "https://github.com/klispap/utils-box"
15+
16+
[dependencies]
17+
anyhow = "1.0.100"
18+
log = "0.4.28"
19+
simplelog = "0.11.2"
20+
file-rotate = "0.7.6"
21+
chrono = "0.4.42"
22+
lazy_static = "1.5.0"
23+
tokio = { version = "1", features = [
24+
"rt",
25+
"net",
26+
"macros",
27+
"time",
28+
"rt-multi-thread",
29+
] }
30+
tokio-util = "0.6.10"
31+
futures = "0.3.31"
32+
rayon = "1.11.0"
33+
walkdir = "2.5.0"
34+
tar = "0.4.44"
35+
zmq = "0.10.0"
36+
glob = "0.3.3"
37+
flate2 = "1.1"
38+
semver = "1.0.27"
39+
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }
40+
regex = "1.11.2"
41+
names = "0.14.0"
42+
rust-ini = "0.18.0"
43+
directories = "5.0.1"
44+
45+
[target.'cfg(unix)'.dependencies]
46+
ssh2 = { version = "0.9.5", features = ["vendored-openssl"] }
47+
signal-hook = "0.3.18"
48+
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
49+
50+
[dev-dependencies]
51+
indoc = "1.0.9"
52+
tempfile = "3.22.0"
53+
named-lock = "0.3.0"
54+
55+
[lints.rust]
56+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
57+
58+
[features]
59+
default = ["archives", "math"]
60+
archives = []
61+
math = []
62+
connections = []

utils-box-linux/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Agathoklis Papadopoulos
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

utils-box-linux/README.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
[![Coverage Status](https://coveralls.io/repos/github/klispap/utils-box/badge.svg?branch=main)](https://coveralls.io/github/klispap/utils-box?branch=main)
2+
3+
# Summary
4+
A toolbox library that holds a useful collection of small unitilies written in Rust that make our life easier when writting Rust applications.
5+
6+
# Utilities provided:
7+
8+
## Mathematics
9+
A collection of useful methematic methods used in various DSP and other applications
10+
11+
## Archives
12+
Extract files from Tar, Gz and Zip Files
13+
14+
Mininal Example:
15+
```rust
16+
let archive: PathBuf = std::env::current_exe()
17+
.unwrap()
18+
.parent()
19+
.unwrap()
20+
.join("test_archive.tar.gz");
21+
22+
let file: PathBuf = "treasure.hex".into();
23+
24+
let destination: PathBuf = std::env::current_exe()
25+
.unwrap()
26+
.parent()
27+
.unwrap();
28+
29+
archives::extract_file(archive, ArchiveType::Gz, file, destination).unwrap();
30+
31+
```
32+
33+
## Bits
34+
Convertions between different representations of raw bit streams
35+
36+
Mininal Example:
37+
```rust
38+
let received_bit_stream: u64 = 0b110101000100111010110;
39+
40+
let bytes = bits::bits_to_vec(received_bit_stream,21);
41+
42+
println!("Received bit stream: {} ", bits::bit_vec_to_hex_string(&bytes));
43+
44+
```
45+
46+
## Config
47+
Manipulate INI-style configuration files by checking for changes, updates etc
48+
49+
Mininal Example:
50+
```rust
51+
let mut config_changes = ini_compare(
52+
&old_config_path.to_path_buf(),
53+
&new_config_path.to_path_buf(),
54+
)
55+
.unwrap();
56+
57+
println!("{:#?}", config_changes);
58+
59+
```
60+
61+
## Logger
62+
Initialize terminal and file loggers fast. Macros for log printing to either log or stdout (if a global logger is not initialized)
63+
64+
Mininal Example:
65+
```rust
66+
log_info!("INFO Test TO PRINTLN!");
67+
log_debug!("DEBUG Test TO PRINTLN!");
68+
69+
terminal_logger_init(LevelFilter::Debug);
70+
71+
log_info!("INFO Test TO LOGGER!");
72+
log_debug!("DEBUG Test TO LOGGER!");
73+
74+
```
75+
76+
## Paths
77+
Search paths for a specific file in directories with known or unknown paths
78+
79+
Mininal Example:
80+
```rust
81+
let paths = IncludePathsBuilder::new()
82+
.include_exe_dir()
83+
.include_known("/home/user/")
84+
.include_unknown("utils-box")
85+
.build();
86+
87+
let pattern = "test_*.tar";
88+
89+
let file_found_in = paths.search_glob(pattern);
90+
91+
```
92+
93+
## Stopwatch and Timekeper
94+
Keep track of execution times in various points in binaries. Print records.
95+
96+
Minimal Example:
97+
```rust
98+
let mut s = TimeKeeper::init();
99+
let mut t = TimeKeeper::init();
100+
101+
s.totals();
102+
103+
s.lap("init");
104+
105+
for _ in 0..5 {
106+
std::thread::sleep(Duration::from_millis(5));
107+
s.lap("loop");
108+
t.lap("loop");
109+
}
110+
s.lap_totals("loop");
111+
std::thread::sleep(Duration::from_millis(1234));
112+
s.lap("after");
113+
114+
s.totals();
115+
t.totals();
116+
117+
s.merge(t);
118+
119+
s.totals();
120+
121+
```
122+
123+
## Versions
124+
version parser from strings using the `semver.org` notations
125+
126+
Mininal Example:
127+
```rust
128+
let version = "0.9.2-1e341234";
129+
130+
let mut expected = Version::new(0, 9, 2);
131+
expected.pre = Prerelease::new("1e341234").unwrap();
132+
133+
assert_eq!(semver_parse(version).unwrap(), expected);
134+
135+
```
136+
137+
## SSH Client
138+
Connect via SSH to a server to perform commands, upload & download files
139+
140+
Mininal Example:
141+
```rust
142+
let ssh = SshClient::local("user".to_string(), "1234".to_string()).unwrap();
143+
144+
let stdout = ssh.execute_cmd("ls").unwrap();
145+
146+
println!("{:?}", stdout);
147+
148+
```
149+
150+
## TCP Client
151+
Connect via TCP to a socket to send and receive data
152+
153+
Mininal Example:
154+
```rust
155+
let mut tcp_client = TcpClient::new("192.168.1.17".to_string(), 36457)?;
156+
157+
let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
158+
159+
tcp_client.send(&data)?;
160+
161+
// Block and wait for response
162+
let resp = tcp_client.receive()?;
163+
164+
println!("{:?}", resp);
165+
166+
```
167+
168+
## TCP Client
169+
Connect via UDP to a socket to send and receive data
170+
171+
Mininal Example:
172+
```rust
173+
let mut udp =
174+
UdpClient::new("0.0.0.0".to_string(), "192.168.1.31".to_string(), 6123).unwrap();
175+
176+
udp.send(b"\r").unwrap();
177+
178+
// Block and wait for response
179+
let data = udp.receive().unwrap();
180+
181+
println!("{:?} => {}", data, String::from_utf8_lossy(&data));
182+
183+
```
184+
185+
## ZMQ Client
186+
Connect to a ZMQ server to send and receive data
187+
188+
Mininal Example:
189+
```rust
190+
let zmq_client = ZmqClient::new(("192.168.1.17".to_string(), 36457)?;
191+
192+
let data: Vec<u8> = vec![8, 30, 15, 30, 5, 19, 0, 7];
193+
194+
zmq_client.send(&data)?;
195+
196+
// Block and wait for response
197+
let resp = zmq_client.receive()?;
198+
199+
println!("{:?}", resp);
200+
201+
```
202+
203+
# Tips for resolving Ubuntu 22.04 build issues:
204+
205+
1) Make sure you have the following system-level dependencies installed:
206+
```
207+
sudo apt install pkg-config build-essential fontconfig libfontconfig1-dev
208+
```
209+
210+
2) Verify that `pkg-config` can detect `libstdc++` properly:
211+
```
212+
pkg-config --libs libstdc++
213+
```
214+
215+
3) If `libstdc++` is not detected, add the symbolic link:
216+
```
217+
sudo ln -s /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so /usr/lib/libstdc++.so
218+
```
219+

utils-box-linux/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! # Summary
2+
//! A toolbox library that holds a useful collection of small unitilies written in Rust that make our life easier when writting Rust applications.
3+
//!
4+
//! # Utilities provided:
5+
//!
6+
//! ## Linux OS utilities
7+
//! A toolbox of small utilities for Linux environments.
8+
//! Useful for fast binary development via the provided signal handling and panic hooks.
9+
//!
10+
//!
11+
12+
#[cfg(target_family = "unix")]
13+
#[cfg(not(tarpaulin_include))]
14+
pub mod threads;

0 commit comments

Comments
 (0)