Compare commits

..

No commits in common. "master" and "fix_grammalect_archive" have entirely different histories.

4 changed files with 251 additions and 492 deletions

666
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,31 @@
[package]
name = "grammalecte_client"
version = "0.1.5"
version = "0.1.4"
edition = "2021"
authors = ["Pierre Hubert <pierre.git@communiquons.org>"]
description = "Grammalecte HTTP client"
license = "MIT"
repository = "https://gitea.communiquons.org/pierre/GrammalecteClient"
keywords = ["grammalecte", "spell-check", "spellcheck"]
keywords = ["grammalecte", "spell-check"]
readme = "README.md"
categories = ["text-processing"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde_json = "1.0.140"
reqwest = { version = "0.12.15", features = ["json"] }
serde = { version = "1.0.219", features = ["derive"] }
log = "0.4.27"
serde_json = "1.0.96"
reqwest = { version = "0.12.4", features = ["json"] }
serde = { version = "1.0.163", features = ["derive"] }
log = "0.4.17"
zip = { version = "2.1.3", optional = true }
mktemp = { version = "0.5.1", optional = true }
rand = { version = "0.9.0", optional = true }
mktemp = { version = "0.5.0", optional = true }
rand = { version = "0.8.5", optional = true }
port_scanner = { version = "0.1.5", optional = true }
thiserror = "2.0.12"
thiserror = "1.0.61"
[features]
embedded-server = ["zip", "mktemp", "rand", "port_scanner"]
[dev-dependencies]
env_logger = "0.11.8"
tokio = { version = "1.44.1", features = ["full"] }
env_logger = "0.11.3"
tokio = { version = "1.28.1", features = ["full"] }

View File

@ -1,3 +0,0 @@
{
"extends": ["local>renovate/presets"]
}

View File

@ -1,7 +1,7 @@
use crate::server::utils::{get_free_port, wait_for_server};
use crate::server::utils::{get_free_port, wait_for_port};
use mktemp::Temp;
use std::io::{self, Cursor, Read};
use std::process::{Child, ExitStatus, Stdio};
use std::process::{Child, Stdio};
use thiserror::Error;
use zip::{result::ZipError, ZipArchive};
@ -13,15 +13,6 @@ pub enum Error {
#[error("Get an available port failed")]
GetFreePort(#[source] io::Error),
#[error("Server exit with `{status}`")]
ServerExitWithStatus { status: ExitStatus },
#[error("Server exit with `{status}` :\n{msg}")]
ServerExitWithError { status: ExitStatus, msg: String },
#[error("Error append during check grammalecte-server status")]
ServerCheckStatus(#[source] io::Error),
#[error("Port {port} did not open in time!")]
WaitPortOpen { port: u16 },
@ -89,16 +80,16 @@ impl EmbeddedServer {
log::info!("Will execute file {}", server_file);
// Start server
let mut child = std::process::Command::new("/usr/bin/python3")
let child = std::process::Command::new("/usr/bin/python3")
.arg(server_file)
.arg("-p")
.arg(port.to_string())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.stderr(Stdio::null())
.spawn()
.map_err(Error::StartServerProcess)?;
wait_for_server(&mut child, port)?;
wait_for_port(port)?;
Ok(Self {
_srv_dir: dest,
@ -120,12 +111,10 @@ impl Drop for EmbeddedServer {
}
mod utils {
use super::Error;
use std::fmt::Write;
use std::io::{BufRead, BufReader};
use std::process::Child;
use std::time::Duration;
use super::Error;
/// Get a free port
pub fn get_free_port() -> u16 {
let mut port = 0;
@ -141,9 +130,8 @@ mod utils {
port
}
pub fn wait_for_server(child: &mut Child, port: u16) -> Result<(), Error> {
pub fn wait_for_port(port: u16) -> Result<(), Error> {
for _ in 0..50 {
check_server(child)?;
if port_scanner::scan_port(port) {
return Ok(());
}
@ -152,28 +140,4 @@ mod utils {
Err(Error::WaitPortOpen { port })
}
fn check_server(child: &mut Child) -> Result<(), Error> {
match child.try_wait().map_err(Error::ServerCheckStatus)? {
None => Ok(()), // Continue
Some(status) => {
if let Some(err) = child.stderr.take() {
let mut msg = format!("grammalecte-server exit with `{status}`");
writeln!(&mut msg, " :").unwrap();
let err = BufReader::new(err);
err.lines().for_each(|line| match line {
Ok(line) => {
writeln!(&mut msg, "\t{}", line).unwrap();
}
Err(err) => {
writeln!(&mut msg, "__{err:?}").unwrap();
}
});
Err(Error::ServerExitWithError { status, msg })
} else {
Err(Error::ServerExitWithStatus { status })
}
}
}
}
}