rustfmt + code cleanup

i18n
jnats 3 years ago
parent ea5f18af9e
commit a12b2f692a

@ -1,6 +1,6 @@
[package]
name = "ame"
version = "2.3.2"
version = "2.4.0"
authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@salyut.one>" ]
edition = "2018"
description = "a fast and efficient aur helper."

@ -34,8 +34,7 @@ fn main() {
// update
} else if oper == "-Sy" || oper == "upd" {
update();
} else if oper == "-db" {
addPkg(pkgs);
// general search
} else if oper == "-Ss" || oper == "sea" {
r_search(&args[2]);

@ -14,7 +14,6 @@ use mods::{
upgrade::upgrade,
ver::ver,
xargs::*,
database::{addPkg, remPkg}
};
use std::{env, process::exit, process::Command};

@ -1,5 +1,6 @@
pub mod clearcache;
pub mod clone;
pub mod database;
pub mod help;
pub mod inssort;
pub mod install;
@ -10,4 +11,3 @@ pub mod update;
pub mod upgrade;
pub mod ver;
pub mod xargs;
pub mod database;

@ -1,6 +1,6 @@
use crate::{
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ,
mods::uninstall::uninstall, mods::database::addPkg
err_unrec, inf, inssort, mods::database::add_pkg, mods::strs::prompt, mods::strs::sec,
mods::strs::succ, mods::uninstall::uninstall,
};
use git2::Repository;
use moins::Moins;
@ -102,7 +102,11 @@ pub fn clone(noconfirm: bool, pkg: &str) {
match install_result {
Ok(_) => {
uninstall_make_depend(pkg);
addPkg(false, pkg);
let add_pkg_res = add_pkg(false, pkg);
match add_pkg_res {
Ok(_) => inf(format!("Added package {} to database", pkg)),
Err(_) => err_unrec(format!("Couldn't add package {} to database", pkg)),
}
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
@ -118,7 +122,11 @@ pub fn clone(noconfirm: bool, pkg: &str) {
match install_result.code() {
Some(0) => {
uninstall_make_depend(pkg);
addPkg(false, pkg);
let add_pkg_res = add_pkg(false, pkg);
match add_pkg_res {
Ok(_) => inf(format!("Added package {} to database", pkg)),
Err(_) => err_unrec(format!("Couldn't add package {} to database", pkg)),
}
}
Some(_) => {
err_unrec(format!("Couldn't install {}", pkg));

@ -1,46 +1,54 @@
use regex::bytes;
use toml_edit::{Document, value};
use std::io::{Read, Write, Error};
use crate::{err_unrec, inf};
use std::fs::File;
use std::io::{Error, Write};
use toml_edit::{value, Document};
pub fn remPkg(pkgs: &Vec<String>) {
pub fn rem_pkg(pkgs: &Vec<String>) {
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let mut database = std::fs::read_to_string(&file).expect("cant open database");
let database = std::fs::read_to_string(&file).expect("Can't Open Database");
let mut updateDatabase = database;
let mut update_database = database;
for i in pkgs {
if updateDatabase.contains(i) {
if update_database.contains(i) {
let results = raur::search(&i);
for res in &results {
let databaseEntry = format!("{} = {{ name = \"{}\", version = \"{}\"}}\n",&res[0].name, &res[0].name, &res[0].version);
updateDatabase = format!("{}",updateDatabase.replace(&databaseEntry, ""));
let database_entry = format!(
"{} = {{ name = \"{}\", version = \"{}\"}}\n",
&res[0].name, &res[0].name, &res[0].version
);
update_database = format!("{}", update_database.replace(&database_entry, ""));
}
}
}
let fileAsPath = File::create(std::path::Path::new(&file)).unwrap();
write!(&fileAsPath, "{}", updateDatabase);
let file_as_path = File::create(std::path::Path::new(&file)).unwrap();
let db_update_res = write!(&file_as_path, "{}", update_database);
match db_update_res {
Ok(_) => inf(format!("Database update successful")),
Err(_) => err_unrec(format!("Couldn't update database")),
}
}
pub fn addPkg(fromRepo: bool, pkg: &str) -> Result<(), Error> {
pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> {
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = std::fs::read_to_string(&file).expect("cant open database");
let mut fileAsPath = File::create(std::path::Path::new(&file))?;
let mut file_as_path = File::create(std::path::Path::new(&file))?;
let mut dbParsed = database.parse::<Document>().expect("invalid Database");
if fromRepo == false {
let mut db_parsed = database.parse::<Document>().expect("invalid Database");
if from_repo == false {
let results = raur::search(&pkg);
for res in &results {
for r in res {
dbParsed[&r.name]["name"] = value(&r.name);
dbParsed[&r.name]["version"] = value(&r.version);
db_parsed[&r.name]["name"] = value(&r.name);
db_parsed[&r.name]["version"] = value(&r.version);
}
}
} else {
dbParsed[&pkg]["name"] = value(pkg);
dbParsed[&pkg]["version"] = value(pkg);
db_parsed[&pkg]["name"] = value(pkg);
db_parsed[&pkg]["version"] = value(pkg);
}
print!("{}",dbParsed);
fileAsPath.write_all(format!("{}",dbParsed).as_bytes()).unwrap();
print!("{}", db_parsed);
file_as_path
.write_all(format!("{}", db_parsed).as_bytes())
.unwrap();
Ok(())
}

@ -1,4 +1,7 @@
use crate::mods::{strs::{err_rec, err_unrec, sec, succ}, database::remPkg};
use crate::mods::{
database::rem_pkg,
strs::{err_rec, err_unrec, sec, succ},
};
use runas::Command;
use std::{fs, path::Path};
@ -18,9 +21,10 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")));
remPkg(&pkgs);
},
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};
@ -34,9 +38,10 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")));
remPkg(&pkgs);
},
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};

@ -1,13 +1,11 @@
//use crate::mods::strs::{err_unrec, inf, sec, succ};
use crate::{
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ,
mods::uninstall::uninstall, mods::database::addPkg
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ, uninstall,
};
use git2::Repository;
use runas::Command;
use std::{env, fs, path::Path};
use toml;
use git2::Repository;
fn uninstall_make_depend(pkg: &str) {
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
@ -31,18 +29,15 @@ pub fn upgrade(noconfirm: bool) {
let cachedir = format!("/{}/.cache/ame/", homepath);
let cache_exists = std::path::Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = std::fs::read_to_string(&file).expect("cant open database");
let mut dbParsed = database.parse::<toml::Value>().expect("invalid Database");
let database = std::fs::read_to_string(&file).expect("Can't open database");
let db_parsed = database.parse::<toml::Value>().expect("Invalid Database");
if cache_exists == false {
let cachecreate = fs::create_dir_all(&cachedir);
match cachecreate {
Ok(_) => {
inf(format!("Creating cachedir. (didn't exist previously)"))
Ok(_) => inf(format!("Creating cachedir. (didn't exist previously)")),
Err(_) => err_unrec(format!("Couldn't create cachedir")),
}
Err(_) => {
err_unrec(format!("Couldn't create cachedir"))
}}
}
sec(format!("Performing system upgrade"));
if noconfirm == true {
@ -68,19 +63,31 @@ pub fn upgrade(noconfirm: bool) {
};
}
println!("{:?}", dbParsed);
for entry in dbParsed.as_table() {
println!("{:?}", db_parsed);
for entry in db_parsed.as_table() {
for (key, value) in &*entry {
let results = raur::search(format!("{}",key));
let results = raur::search(format!("{}", key));
for res in results {
println!("{}",&res[0].name);
println!("{}", &res[0].name);
let url = format!("https://aur.archlinux.org/{}.git", key);
let package = raur::info(&[key]).unwrap();
let version = value.to_string().replace("name", "").replace("version","").replace(" = ","").replace("\"","").replace(format!("{}",&res[0].name.to_string()).as_str(),"");
let name = value.to_string().replace("name", "").replace("version","").replace(" = ","").replace("\"","").replace(format!("{}",&res[0].version.to_string()).as_str(),"");
println!("{} / {}",name,version);
let version = value
.to_string()
.replace("name", "")
.replace("version", "")
.replace(" = ", "")
.replace("\"", "")
.replace(format!("{}", &res[0].name.to_string()).as_str(), "");
let name = value
.to_string()
.replace("name", "")
.replace("version", "")
.replace(" = ", "")
.replace("\"", "")
.replace(format!("{}", &res[0].version.to_string()).as_str(), "");
println!("{} / {}", name, version);
if res[0].version.contains(&version) {
let keydir = format!("{}{}",&cachedir,&key);
let keydir = format!("{}{}", &cachedir, &key);
if std::path::Path::new(&keydir).is_dir() {
let cd_result = env::set_current_dir(&keydir);
match cd_result {
@ -121,7 +128,6 @@ pub fn upgrade(noconfirm: bool) {
err_unrec(format!("Couldn't install {}", &key));
}
};
} else {
inf(format!("Cloning {} ...", &key));
@ -142,7 +148,9 @@ pub fn upgrade(noconfirm: bool) {
let dir_result = fs::create_dir(&keydir);
match dir_result {
Ok(_) => inf(format!("Created package directory for {}", &key)),
Err(_) => err_unrec(format!("Couldn't create package directory for {}", &key)),
Err(_) => {
err_unrec(format!("Couldn't create package directory for {}", &key))
}
}
let cd_result = env::set_current_dir(&keydir);
@ -158,7 +166,9 @@ pub fn upgrade(noconfirm: bool) {
Ok(_) => {
inf(format!("Cloning {} into package directory", &key));
}
Err(_) => err_unrec(format!("Failed cloning {} into package directory", &key)),
Err(_) => {
err_unrec(format!("Failed cloning {} into package directory", &key))
}
}
}
@ -193,17 +203,15 @@ pub fn upgrade(noconfirm: bool) {
err_unrec(format!("Couldn't install {}", &key));
}
};
} else {
println!("not upgrading!");
if std::path::Path::new(&format!("{}{}",&cachedir,&key)).is_dir() {
if std::path::Path::new(&format!("{}{}", &cachedir, &key)).is_dir() {
println!("not cloning");
} else {
println!("cloning");
}
}
}
}
}
}

@ -1,9 +1,9 @@
use crate::mods::strs::inf;
use crate::inf;
use ansi_term::Colour;
pub fn ver() {
println!("");
inf(format!("ame - v2.3.2"));
inf(format!("ame - v2.4.0"));
println!("");
inf(format!("Contributors:"));
println!("- axtlos <axtlos@salyut.one>");

Loading…
Cancel
Save