better error message ( #756), use channels argument for import/export
This commit is contained in:
parent
f1565b5d32
commit
9e005aab1b
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ tmp/
|
|||||||
assets/playlist_template.json
|
assets/playlist_template.json
|
||||||
advanced*.toml
|
advanced*.toml
|
||||||
ffplayout*.toml
|
ffplayout*.toml
|
||||||
|
template.json
|
||||||
|
@ -197,10 +197,16 @@ async fn main() -> std::io::Result<()> {
|
|||||||
let channels = ARGS.channels.clone().unwrap_or_else(|| vec![1]);
|
let channels = ARGS.channels.clone().unwrap_or_else(|| vec![1]);
|
||||||
|
|
||||||
for (index, channel_id) in channels.iter().enumerate() {
|
for (index, channel_id) in channels.iter().enumerate() {
|
||||||
let config = get_config(&pool, *channel_id)
|
let config = match get_config(&pool, *channel_id).await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => {
|
||||||
|
eprint!("No config found, channel may not exists!\nOriginal error message: ");
|
||||||
|
return Err(io::Error::new(io::ErrorKind::Other, e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let channel = handles::select_channel(&pool, channel_id)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
|
||||||
let channel = handles::select_channel(&pool, channel_id).await.unwrap();
|
|
||||||
let manager = ChannelManager::new(Some(pool.clone()), channel.clone(), config.clone());
|
let manager = ChannelManager::new(Some(pool.clone()), channel.clone(), config.clone());
|
||||||
|
|
||||||
if ARGS.foreground {
|
if ARGS.foreground {
|
||||||
|
@ -252,10 +252,7 @@ impl AdvancedConfig {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn import(pool: &Pool<Sqlite>, import: Vec<String>) -> Result<(), ServiceError> {
|
pub async fn import(pool: &Pool<Sqlite>, id: i32, path: &Path) -> Result<(), ServiceError> {
|
||||||
let id = import[0].parse::<i32>()?;
|
|
||||||
let path = Path::new(&import[1]);
|
|
||||||
|
|
||||||
if path.is_file() {
|
if path.is_file() {
|
||||||
let mut file = tokio::fs::File::open(path).await?;
|
let mut file = tokio::fs::File::open(path).await?;
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
|
@ -64,24 +64,20 @@ pub struct Args {
|
|||||||
long,
|
long,
|
||||||
help = "Dump advanced channel configuration to advanced_{channel}.toml"
|
help = "Dump advanced channel configuration to advanced_{channel}.toml"
|
||||||
)]
|
)]
|
||||||
pub dump_advanced: Option<i32>,
|
pub dump_advanced: bool,
|
||||||
|
|
||||||
#[clap(long, help = "Dump channel configuration to ffplayout_{channel}.toml")]
|
#[clap(long, help = "Dump channel configuration to ffplayout_{channel}.toml")]
|
||||||
pub dump_config: Option<i32>,
|
pub dump_config: bool,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
help = "import advanced channel configuration from file. Input must be `{channel id} {path to toml}`",
|
help = "import advanced channel configuration from file.",
|
||||||
num_args = 2
|
num_args = 2
|
||||||
)]
|
)]
|
||||||
pub import_advanced: Option<Vec<String>>,
|
pub import_advanced: Option<PathBuf>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(long, help = "import channel configuration from file.", num_args = 2)]
|
||||||
long,
|
pub import_config: Option<PathBuf>,
|
||||||
help = "import channel configuration from file. Input must be `{channel id} {path to toml}`",
|
|
||||||
num_args = 2
|
|
||||||
)]
|
|
||||||
pub import_config: Option<Vec<String>>,
|
|
||||||
|
|
||||||
#[clap(long, help = "List available channel ids")]
|
#[clap(long, help = "List available channel ids")]
|
||||||
pub list_channels: bool,
|
pub list_channels: bool,
|
||||||
@ -203,7 +199,7 @@ fn global_user(args: &mut Args) {
|
|||||||
pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
|
pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
|
||||||
let mut args = ARGS.clone();
|
let mut args = ARGS.clone();
|
||||||
|
|
||||||
if args.dump_advanced.is_none() && args.dump_config.is_none() && !args.drop_db {
|
if !args.dump_advanced && !args.dump_config && !args.drop_db {
|
||||||
if let Err(e) = handles::db_migrate(pool).await {
|
if let Err(e) = handles::db_migrate(pool).await {
|
||||||
panic!("{e}");
|
panic!("{e}");
|
||||||
};
|
};
|
||||||
@ -507,56 +503,84 @@ pub async fn run_args(pool: &Pool<Sqlite>) -> Result<(), i32> {
|
|||||||
error_code = 0;
|
error_code = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(id) = ARGS.dump_config {
|
if ARGS.dump_advanced {
|
||||||
match PlayoutConfig::dump(pool, id).await {
|
if let Some(channels) = &ARGS.channels {
|
||||||
Ok(_) => {
|
for id in channels {
|
||||||
println!("Dump config to: ffplayout_{id}.toml");
|
match AdvancedConfig::dump(pool, *id).await {
|
||||||
error_code = 0;
|
Ok(_) => {
|
||||||
|
println!("Dump config to: advanced_{id}.toml");
|
||||||
|
error_code = 0;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Dump config: {e}");
|
||||||
|
error_code = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
} else {
|
||||||
eprintln!("Dump config: {e}");
|
eprintln!("Channel ID(s) needed! Use `--channels 1 ...`");
|
||||||
error_code = 1;
|
error_code = 1;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(id) = ARGS.dump_advanced {
|
if ARGS.dump_config {
|
||||||
match AdvancedConfig::dump(pool, id).await {
|
if let Some(channels) = &ARGS.channels {
|
||||||
Ok(_) => {
|
for id in channels {
|
||||||
println!("Dump config to: advanced_{id}.toml");
|
match PlayoutConfig::dump(pool, *id).await {
|
||||||
error_code = 0;
|
Ok(_) => {
|
||||||
|
println!("Dump config to: ffplayout_{id}.toml");
|
||||||
|
error_code = 0;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Dump config: {e}");
|
||||||
|
error_code = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
} else {
|
||||||
eprintln!("Dump config: {e}");
|
eprintln!("Channel ID(s) needed! Use `--channels 1 ...`");
|
||||||
error_code = 1;
|
error_code = 1;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(import) = &ARGS.import_config {
|
if let Some(path) = &ARGS.import_advanced {
|
||||||
match PlayoutConfig::import(pool, import.clone()).await {
|
if let Some(channels) = &ARGS.channels {
|
||||||
Ok(_) => {
|
for id in channels {
|
||||||
println!("Import config done...");
|
match AdvancedConfig::import(pool, *id, path).await {
|
||||||
error_code = 0;
|
Ok(_) => {
|
||||||
|
println!("Import config done...");
|
||||||
|
error_code = 0;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{e}");
|
||||||
|
error_code = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
} else {
|
||||||
eprintln!("{e}");
|
eprintln!("Channel ID(s) needed! Use `--channels 1 ...`");
|
||||||
error_code = 1;
|
error_code = 1;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(import) = &ARGS.import_advanced {
|
if let Some(path) = &ARGS.import_config {
|
||||||
match AdvancedConfig::import(pool, import.clone()).await {
|
if let Some(channels) = &ARGS.channels {
|
||||||
Ok(_) => {
|
for id in channels {
|
||||||
println!("Import config done...");
|
match PlayoutConfig::import(pool, *id, path).await {
|
||||||
error_code = 0;
|
Ok(_) => {
|
||||||
|
println!("Import config done...");
|
||||||
|
error_code = 0;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{e}");
|
||||||
|
error_code = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
} else {
|
||||||
eprintln!("{e}");
|
eprintln!("Channel ID(s) needed! Use `--channels 1 ...`");
|
||||||
error_code = 1;
|
error_code = 1;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if error_code > -1 {
|
if error_code > -1 {
|
||||||
|
@ -756,10 +756,7 @@ impl PlayoutConfig {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn import(pool: &Pool<Sqlite>, import: Vec<String>) -> Result<(), ServiceError> {
|
pub async fn import(pool: &Pool<Sqlite>, id: i32, path: &Path) -> Result<(), ServiceError> {
|
||||||
let id = import[0].parse::<i32>()?;
|
|
||||||
let path = Path::new(&import[1]);
|
|
||||||
|
|
||||||
if path.is_file() {
|
if path.is_file() {
|
||||||
let mut file = tokio::fs::File::open(path).await?;
|
let mut file = tokio::fs::File::open(path).await?;
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user