Skip to content

Commit

Permalink
refactor: add pip module for installing requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kremilly committed Aug 13, 2024
1 parent a0306da commit 0501394
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/configs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod env;
pub mod pip;
pub mod settings;
pub mod configs_files;
62 changes: 62 additions & 0 deletions src/configs/pip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::{
error::Error,

process::{
Stdio,
Command,
},
};

use crate::{
ui::{
ui_base::UI,
success_alerts::SuccessAlerts,
},

consts::{
addons::Addons,
folders::Folders,
},

utils::{
remote::Remote,
file::FileUtils,
},
};

pub struct Pip;

impl Pip {

async fn exec(path: &str) -> Result<(), Box<dyn Error>> {
let output = Command::new("pip")
.arg("install")
.arg("-r")
.arg("requirements.txt")
.current_dir(path)
.stdout(Stdio::piped())
.output()?;

if output.status.success() {
let _ = String::from_utf8_lossy(&output.stdout);
SuccessAlerts::pip();
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
println!("{}", stderr);
}

Ok(())
}

pub async fn install() -> Result<(), Box<dyn Error>> {
UI::section_header("Installing requirements", "info");
let path = Folders::SCRIPTS_FOLDER.to_str().unwrap_or_default().to_string();

FileUtils::create_path(&path);
Remote::download(&Addons::INSTALL_REQUIREMENTS_PLUGINS, &path).await?;

Self::exec(&path).await?;
Ok(())
}

}
1 change: 1 addition & 0 deletions src/consts/addons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ impl Addons {

// Plugins
pub const EXTRACT_COVERS_PLUGIN: &'static str = "https://raw.githubusercontent.com/Scibun/MonPlugins/main/extract_covers.py";
pub const INSTALL_REQUIREMENTS_PLUGINS: &'static str = "https://raw.githubusercontent.com/Scibun/MonPlugins/main/requirements.txt";

// Scimon
pub const SCIMON_API_REQUEST: &'static str = "http://localhost/Scimon/api/";
Expand Down
8 changes: 5 additions & 3 deletions src/scimon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ use crate::{

addons::{
scrape::Scrape,
scibun::Scibun,
scibun::Scibun,
},

configs::{
env::Env,
pip::Pip,
settings::Settings,
configs_files::DownloadConfigsFiles,
},
Expand All @@ -30,6 +31,7 @@ impl Scimon {
async fn options(options: &str) -> Result<(), Box<dyn Error>> {
match options {
"open-env" => Env::open_env_file()?,
"install-requirements" => Pip::install().await?,
"open-settings" => Settings::open_settings_file()?,
"download-env" => DownloadConfigsFiles::env_file(true, true).await?,
"download-settings" => DownloadConfigsFiles::settings_file(true, true).await?,
Expand All @@ -54,10 +56,10 @@ impl Scimon {
let url = flags.url.as_deref().unwrap_or_default();
let run = flags.run.as_deref().unwrap_or_default();
let options = flags.options.as_deref().unwrap_or_default();

UI::header();

if !run.is_empty() {
UI::header();

if !Scibun::check_is_user(run) {
let _ = Monset::prints(run).await;

Expand Down
2 changes: 1 addition & 1 deletion src/system/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Scripts;

impl Scripts {

pub fn exec(line: &str, program: &str) -> Result<(), Box<dyn Error>> {
fn exec(line: &str, program: &str) -> Result<(), Box<dyn Error>> {
let language = Plataforms::get_bin_name(program);

let line_cleanned = Regex::new(
Expand Down
7 changes: 6 additions & 1 deletion src/ui/success_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ impl SuccessAlerts {

pub fn env() {
let current_datetime = General::date_time();
println!("{} Downloaded env file", current_datetime.blue().bold());
println!("{} Downloaded env file", current_datetime.green().bold());
}

pub fn pip() {
let current_datetime = General::date_time();
println!("{} Dependencies was installed successfully", current_datetime.green().bold());
}

pub fn download(file: &str, url: &str, password: bool, hash: &str) {
Expand Down

0 comments on commit 0501394

Please sign in to comment.