Cleanup unused stuff
This commit is contained in:
parent
19e9b98302
commit
6ed76928db
30
src/db.rs
30
src/db.rs
|
@ -94,33 +94,8 @@ pub fn read_or_none(path: &Path) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn list_files(path: &Path) -> Vec<PathBuf> {
|
||||
let mut res = Vec::new();
|
||||
match fs::read_dir(path) {
|
||||
Ok(files) => {
|
||||
for r in files {
|
||||
match r {
|
||||
Ok(entry) => {
|
||||
let file = entry.path();
|
||||
if file.is_file() {
|
||||
res.push(file);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("IOERROR: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("IOERROR: {}", e);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// If the file doesn't exist or fails, return false
|
||||
/// Returns true when the file exists and has user exec
|
||||
/// permission. Returns false otherwise.
|
||||
pub fn is_executable(path: &Path) -> bool {
|
||||
// Do not match directories
|
||||
if !path.is_file() {
|
||||
|
@ -143,7 +118,6 @@ pub fn is_executable(path: &Path) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
21
src/dvcs.rs
21
src/dvcs.rs
|
@ -1,15 +1,6 @@
|
|||
use std::process::Command;
|
||||
use std::path::{Path,PathBuf};
|
||||
|
||||
pub fn from_setting(setting: Option<String>) -> Backend {
|
||||
// Git is the default setting until further notice
|
||||
setting.map_or(Backend::Git, |name| match name.as_ref() {
|
||||
"git" => Backend::Git,
|
||||
"mercurial" => Backend::Mercurial,
|
||||
_ => Backend::Unknown(name.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Backend {
|
||||
Git,
|
||||
|
@ -17,6 +8,18 @@ pub enum Backend {
|
|||
Unknown(String),
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
pub fn from_setting(setting: Option<String>) -> Backend {
|
||||
// Git is the default setting until further notice
|
||||
setting.map_or(Backend::Git, |name| match name.as_ref() {
|
||||
"git" => Backend::Git,
|
||||
"mercurial" => Backend::Mercurial,
|
||||
_ => Backend::Unknown(name.to_string())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Repo {
|
||||
pub backend: Backend,
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use std::env;
|
||||
use std::env::{set_current_dir as cd, set_var};
|
||||
use std::collections::HashMap;
|
||||
use structopt::StructOpt;
|
||||
// For UNIX extended metadata
|
||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||
let cmd = cli::Cli::from_args();
|
||||
let base_dir: String = cmd.basedir().to_str().unwrap().into();
|
||||
|
||||
std::env::set_var("GITBUILDDIR", &base_dir);
|
||||
set_var("GITBUILDDIR", &base_dir);
|
||||
|
||||
let mut tasks = if cmd.tasks.is_empty() {
|
||||
task::from_dir(&base_dir).expect("Could not load DB")
|
||||
|
@ -23,7 +23,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||
|
||||
let (config_folder, ignored_tasks) = task::config(&std::path::Path::new(&base_dir));
|
||||
|
||||
std::env::set_var("GITBUILDCONF", &config_folder);
|
||||
set_var("GITBUILDCONF", &config_folder);
|
||||
|
||||
// Reorder tasks alphanumerically
|
||||
tasks.sort_unstable_by_key(|t| t.name.clone());
|
||||
|
@ -42,8 +42,10 @@ fn main() -> Result<(), std::io::Error> {
|
|||
log::debug("found_task", Some(&context));
|
||||
// Maybe the task has a source we should clone?
|
||||
if let Some(repo) = &task.repo {
|
||||
context.insert("$i18n_source", &repo.source);
|
||||
let source_dir = format!("{}/.{}", base_dir, &task.name);
|
||||
if task.cloned == false {
|
||||
log::info("clone", Some(&context));
|
||||
if !repo.clone() {
|
||||
context.insert("$i18n_source", &repo.source);
|
||||
log::error("clone_failed", Some(&context));
|
||||
|
@ -53,7 +55,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||
// New repo just cloned
|
||||
// TODO: submodule and submodule updates
|
||||
println!("Downloaded source for {}", task.name);
|
||||
std::env::set_current_dir(&source_dir);
|
||||
cd(&source_dir).expect("Failed to change working dir");
|
||||
|
||||
// Checkout specific branch?
|
||||
task.checkout();
|
||||
|
@ -62,14 +64,14 @@ fn main() -> Result<(), std::io::Error> {
|
|||
// So the cloned repo is already here maybe update?
|
||||
// Let's say there was an update and run
|
||||
println!("Task {} already exists, run i t only if updates", task.name);
|
||||
std::env::set_current_dir(&source_dir);
|
||||
cd(&source_dir).expect("Failed to change working dir");
|
||||
task.checkout();
|
||||
task.update_and_run(&cmd.force);
|
||||
//task.run();
|
||||
}
|
||||
} else {
|
||||
// No source, chaneg working dir to basedir
|
||||
std::env::set_current_dir(&base_dir);
|
||||
cd(&base_dir).expect("Failed to change working dir");
|
||||
println!("Taks {} doesn't have a source, run it", task.name);
|
||||
task.run_once();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::collections::HashMap;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::dvcs;
|
||||
use crate::dvcs::{Backend,Repo};
|
||||
use crate::dvcs::{Backend, Repo};
|
||||
use crate::db;
|
||||
use crate::db::{Entry,is_executable};
|
||||
use crate::log;
|
||||
|
@ -52,14 +51,13 @@ impl Task {
|
|||
dest.is_dir()
|
||||
});
|
||||
let subupdates = entry.read_setting("subupdates").is_some();
|
||||
let dvcs = dvcs::from_setting(entry.read_setting("dvcs"));
|
||||
|
||||
Task {
|
||||
name: entry.name.to_str().unwrap().to_string(),
|
||||
bin: entry.path.clone(),
|
||||
// None source = None repo
|
||||
repo: source.as_ref().map(|s|
|
||||
Repo::new(dvcs, s, &dest, subupdates)
|
||||
Repo::new(Backend::from_setting(entry.read_setting("dvcs")), s, &dest, subupdates)
|
||||
),
|
||||
source,
|
||||
config: HashMap::new(),
|
||||
|
@ -137,7 +135,7 @@ impl Task {
|
|||
done_path.set_extension("done");
|
||||
if !done_path.exists() {
|
||||
self.run();
|
||||
std::fs::write(&done_path, "");
|
||||
std::fs::write(&done_path, "").expect("Failed to register task as done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue