added first parts of statically defined packages

i18n
Amy 3 years ago
parent 29b7fc85a1
commit f3c8a6d463
No known key found for this signature in database
GPG Key ID: 6672E6DD65BEA50B

@ -1,7 +1,7 @@
[package]
name = "ame"
version = "0.0.0"
authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@salyut.one>" ]
authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@tar.black>" ]
edition = "2018"
description = "a fast and efficient aur helper."
@ -19,4 +19,5 @@ toml = "*"
bytes = "*"
nix = "*"
clap = "*"
sqlite = "*"
sqlite = "*"
file_diff = "*"

@ -16,6 +16,8 @@ use mods::{
upgrade::upgrade,
ver::ver,
xargs::*,
statpkgs::*,
stat_database::*,
};
use std::{env, process::exit};
@ -53,8 +55,7 @@ fn main() {
inssort_from_file(noconfirm, false, &pkgs[0]); // install from file
}
"-B" | "-Bn" | "build" => {
//rebuild(noconfirm); // install as a dependency
add_pkg(noconfirm, &pkgs[0]);
rebuild(noconfirm); // install as a dependency
}
"-R" | "-Rn" | "rm" => {
uninstall(noconfirm, pkgs); // uninstall

@ -7,9 +7,10 @@ pub mod install;
pub mod purge;
pub mod search;
pub mod statpkgs;
pub mod stat_database;
pub mod strs;
pub mod uninstall;
pub mod update;
pub mod upgrade;
pub mod ver;
pub mod xargs;
pub mod xargs;

@ -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) {
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…
Cancel
Save