forked from pierre/GrammalecteClient
Compare commits
5 Commits
use_thiser
...
0.1.5
Author | SHA1 | Date | |
---|---|---|---|
150097f77a | |||
d33202816f | |||
b0543aaba9 | |||
597a681801 | |||
74ff8463ba |
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -502,7 +502,7 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grammalecte_client"
|
name = "grammalecte_client"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
@ -896,9 +896,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.3"
|
version = "2.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6d0d8b92cd8358e8d229c11df9358decae64d137c5be540952c5ca7b25aea768"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
@ -1172,9 +1172,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
|
checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
]
|
]
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grammalecte_client"
|
name = "grammalecte_client"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Pierre Hubert <pierre.git@communiquons.org>"]
|
authors = ["Pierre Hubert <pierre.git@communiquons.org>"]
|
||||||
description = "Grammalecte HTTP client"
|
description = "Grammalecte HTTP client"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://gitea.communiquons.org/pierre/GrammalecteClient"
|
repository = "https://gitea.communiquons.org/pierre/GrammalecteClient"
|
||||||
keywords = ["grammalecte", "spell-check"]
|
keywords = ["grammalecte", "spell-check", "spellcheck"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
categories = ["text-processing"]
|
categories = ["text-processing"]
|
||||||
|
|
||||||
|
9
renovate.json
Normal file
9
renovate.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchUpdateTypes": ["major", "minor", "patch"],
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
use crate::server::utils::{get_free_port, wait_for_port};
|
use crate::server::utils::{get_free_port, wait_for_server};
|
||||||
use mktemp::Temp;
|
use mktemp::Temp;
|
||||||
use std::io::{self, Cursor, Read};
|
use std::io::{self, Cursor, Read};
|
||||||
use std::process::{Child, Stdio};
|
use std::process::{Child, ExitStatus, Stdio};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use zip::{result::ZipError, ZipArchive};
|
use zip::{result::ZipError, ZipArchive};
|
||||||
|
|
||||||
@ -13,6 +13,15 @@ pub enum Error {
|
|||||||
#[error("Get an available port failed")]
|
#[error("Get an available port failed")]
|
||||||
GetFreePort(#[source] io::Error),
|
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!")]
|
#[error("Port {port} did not open in time!")]
|
||||||
WaitPortOpen { port: u16 },
|
WaitPortOpen { port: u16 },
|
||||||
|
|
||||||
@ -80,16 +89,16 @@ impl EmbeddedServer {
|
|||||||
log::info!("Will execute file {}", server_file);
|
log::info!("Will execute file {}", server_file);
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
let child = std::process::Command::new("/usr/bin/python3")
|
let mut child = std::process::Command::new("/usr/bin/python3")
|
||||||
.arg(server_file)
|
.arg(server_file)
|
||||||
.arg("-p")
|
.arg("-p")
|
||||||
.arg(port.to_string())
|
.arg(port.to_string())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(Error::StartServerProcess)?;
|
.map_err(Error::StartServerProcess)?;
|
||||||
|
|
||||||
wait_for_port(port)?;
|
wait_for_server(&mut child, port)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_srv_dir: dest,
|
_srv_dir: dest,
|
||||||
@ -111,9 +120,11 @@ impl Drop for EmbeddedServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod utils {
|
mod utils {
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
use std::fmt::Write;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::process::Child;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Get a free port
|
/// Get a free port
|
||||||
pub fn get_free_port() -> u16 {
|
pub fn get_free_port() -> u16 {
|
||||||
@ -130,8 +141,9 @@ mod utils {
|
|||||||
port
|
port
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_for_port(port: u16) -> Result<(), Error> {
|
pub fn wait_for_server(child: &mut Child, port: u16) -> Result<(), Error> {
|
||||||
for _ in 0..50 {
|
for _ in 0..50 {
|
||||||
|
check_server(child)?;
|
||||||
if port_scanner::scan_port(port) {
|
if port_scanner::scan_port(port) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -140,4 +152,28 @@ mod utils {
|
|||||||
|
|
||||||
Err(Error::WaitPortOpen { port })
|
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 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user