added first parts of statically defined packages
parent
29b7fc85a1
commit
f3c8a6d463
@ -0,0 +1,114 @@
|
|||||||
|
use crate::{err_unrec, inf};
|
||||||
|
use std::{fs, env};
|
||||||
|
|
||||||
|
pub fn stat_create_database() {
|
||||||
|
let homepath = env::var("HOME").unwrap();
|
||||||
|
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||||
|
if !std::path::Path::new(&format!("{}/.local/share/ame/", env::var("HOME").unwrap())).is_dir() {
|
||||||
|
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath));
|
||||||
|
match _cdar {
|
||||||
|
Ok(_) => {
|
||||||
|
inf(format!("Created path for database (previously missing)"))
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
err_unrec(format!("Couldn't create path for database (~/.local/rhare/ame)"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let connection = sqlite::open(file).unwrap();
|
||||||
|
connection.execute(
|
||||||
|
"
|
||||||
|
CREATE TABLE static_pkgs (name TEXT, pin INTEGER);
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stat_get_value(pkg: &str, sear_value: &str) -> bool {
|
||||||
|
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||||
|
let connection = sqlite::open(file).unwrap();
|
||||||
|
let mut return_val = false;
|
||||||
|
//println!("{}", pkg);
|
||||||
|
match sear_value {
|
||||||
|
"name" => {
|
||||||
|
let result = connection.iterate(format!("SELECT name FROM static_pkgs WHERE name = \"{}\";",&pkg), |pairs| {
|
||||||
|
for &(column, value) in pairs.iter() {
|
||||||
|
return_val = true;
|
||||||
|
}
|
||||||
|
return_val
|
||||||
|
}
|
||||||
|
);
|
||||||
|
match result {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||||
|
}
|
||||||
|
if return_val == true {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"update" => {
|
||||||
|
let result = connection.iterate(format!("SELECT pin FROM static_pkgs WHERE name = \"{}\";",&pkg), |pairs| {
|
||||||
|
for &(column, value) in pairs.iter() {
|
||||||
|
return_val = true;
|
||||||
|
}
|
||||||
|
return_val
|
||||||
|
}
|
||||||
|
);
|
||||||
|
match result {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(_) => err_unrec("Couldn't get value from database".to_string()),
|
||||||
|
}
|
||||||
|
if return_val == true {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
return_val = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return return_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stat_rem_pkg(static_pkgs: &Vec<String>) {
|
||||||
|
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||||
|
let connection = sqlite::open(file).unwrap();
|
||||||
|
|
||||||
|
for i in static_pkgs {
|
||||||
|
let result = connection.execute(
|
||||||
|
format!("
|
||||||
|
DELETE FROM static_pkgs WHERE name = \"{}\";
|
||||||
|
", i),
|
||||||
|
);
|
||||||
|
match result{
|
||||||
|
Ok(_) => {
|
||||||
|
inf(format!("Removed {} from database", i))
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
err_unrec(format!("Couldn't remove {} from database", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stat_add_pkg(update: &str, pkg: &str) {
|
||||||
|
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
|
||||||
|
let connection = sqlite::open(file).unwrap();
|
||||||
|
let pin = if update == "true" { 1 } else { 0 };
|
||||||
|
let result = connection.execute(
|
||||||
|
format!("
|
||||||
|
INSERT INTO static_pkgs (name, pin) VALUES (\"{}\", {});
|
||||||
|
", pkg, pin),
|
||||||
|
);
|
||||||
|
match result{
|
||||||
|
Ok(_) => {
|
||||||
|
inf(format!("Added {} to database", pkg))
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
err_unrec(format!("Couldn't add {} to database", pkg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,37 @@
|
|||||||
|
use std::{fs, env};
|
||||||
|
use crate::inf;
|
||||||
|
use toml::{Value, toml};
|
||||||
|
use crate::{
|
||||||
|
stat_add_pkg,
|
||||||
|
stat_create_database,
|
||||||
|
stat_get_value,
|
||||||
|
stat_rem_pkg,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn rebuild(noconfirm: bool) {
|
pub fn rebuild(noconfirm: bool) {
|
||||||
print!("installing crystal config")
|
let homepath = env::var("HOME").unwrap();
|
||||||
}
|
let file = format!("{}/.config/ame/pkgs.toml", env::var("HOME").unwrap());
|
||||||
|
let mut database = String::new();
|
||||||
|
database = fs::read_to_string(&file).expect("Can't Open Database");
|
||||||
|
inf(format!("installing crystal config"));
|
||||||
|
|
||||||
|
let db_parsed = database.parse::<toml::Value>().expect("Invalid Database");
|
||||||
|
let mut pkgs = Vec::new();
|
||||||
|
for entry in db_parsed.as_table() {
|
||||||
|
for (key, value) in &*entry {
|
||||||
|
let mut tempvec = Vec::new();
|
||||||
|
println!("{}", key);
|
||||||
|
println!("{}", format!("{}",value).replace("update = ", ""));
|
||||||
|
tempvec.push(key.to_string());
|
||||||
|
tempvec.push(format!("{}",value).replace("update = ", ""));
|
||||||
|
pkgs.push(tempvec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut pkgs_to_add: Vec<String> = Vec::new();
|
||||||
|
for i in pkgs {
|
||||||
|
if !stat_get_value(&i[0], "name") {
|
||||||
|
pkgs_to_add.push(i[0].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inf(format!("Installing {}", pkgs_to_add.join(", ")));
|
||||||
|
}
|
Loading…
Reference in New Issue