Add no-progress-bars feature so other packages can hide them (#66)

This commit is contained in:
Azrenbeth
2021-09-27 11:35:40 +01:00
committed by GitHub
parent a069d8765a
commit bc30942e2d
6 changed files with 34 additions and 8 deletions

View File

@@ -32,4 +32,5 @@ features = ["extension-module","abi3-py36"]
[features]
default = ["jemalloc"]
jemalloc = []
jemalloc = []
no-progress-bars = []

View File

@@ -14,7 +14,7 @@ postgres-openssl = "0.5.0"
jemallocator = "0.3.2"
rand = "0.8.0"
serial_test = "0.5.1"
synapse_compress_state = { path = "../" }
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
env_logger = { version = "0.9.0", git = "https://github.com/TilCreator/env_logger", branch = "fix_pipe" }
log = "0.4.14"
log-panics = "2.0.0"

View File

@@ -12,7 +12,7 @@ openssl = "0.10.32"
postgres = "0.19.0"
postgres-openssl = "0.5.0"
rand = "0.8.0"
synapse_compress_state = { path = "../" }
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
auto_compressor = { path = "../auto_compressor/" }
env_logger = "0.9.0"
log = "0.4.14"

View File

@@ -181,7 +181,12 @@ impl<'a> Compressor<'a> {
panic!("Can only call `create_new_tree` once");
}
let pb = ProgressBar::new(self.original_state_map.len() as u64);
let pb: ProgressBar;
if cfg!(feature = "no-progress-bars") {
pb = ProgressBar::hidden();
} else {
pb = ProgressBar::new(self.original_state_map.len() as u64);
}
pb.set_style(
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
);

View File

@@ -373,7 +373,12 @@ fn get_initial_data_from_db(
// Copy the data from the database into a map
let mut state_group_map: BTreeMap<i64, StateGroupEntry> = BTreeMap::new();
let pb = ProgressBar::new_spinner();
let pb: ProgressBar;
if cfg!(feature = "no-progress-bars") {
pb = ProgressBar::hidden();
} else {
pb = ProgressBar::new_spinner();
}
pb.set_style(
ProgressStyle::default_spinner().template("{spinner} [{elapsed}] {pos} rows retrieved"),
);
@@ -533,7 +538,12 @@ pub fn send_changes_to_db(
println!("Writing changes...");
// setup the progress bar
let pb = ProgressBar::new(old_map.len() as u64);
let pb: ProgressBar;
if cfg!(feature = "no-progress-bars") {
pb = ProgressBar::hidden();
} else {
pb = ProgressBar::new(old_map.len() as u64);
}
pb.set_style(
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
);

View File

@@ -487,7 +487,12 @@ fn output_sql(
println!("Writing changes...");
let pb = ProgressBar::new(old_map.len() as u64);
let pb: ProgressBar;
if cfg!(feature = "no-progress-bars") {
pb = ProgressBar::hidden();
} else {
pb = ProgressBar::new(old_map.len() as u64);
}
pb.set_style(
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
);
@@ -597,7 +602,12 @@ fn check_that_maps_match(
) {
println!("Checking that state maps match...");
let pb = ProgressBar::new(old_map.len() as u64);
let pb: ProgressBar;
if cfg!(feature = "no-progress-bars") {
pb = ProgressBar::hidden();
} else {
pb = ProgressBar::new(old_map.len() as u64);
}
pb.set_style(
ProgressStyle::default_bar().template("[{elapsed_precise}] {bar} {pos}/{len} {msg}"),
);