rework section loading
This commit is contained in:
@@ -20,5 +20,18 @@ macro_rules! impl_backend_constants {
|
|||||||
fn get_managed_packages(&self) -> &HashSet<Package> {
|
fn get_managed_packages(&self) -> &HashSet<Package> {
|
||||||
&self.packages
|
&self.packages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load(&mut self, groups: &HashSet<Group>) {
|
||||||
|
let own_section_name = self.get_section();
|
||||||
|
|
||||||
|
groups
|
||||||
|
.iter()
|
||||||
|
.flat_map(|g| &g.sections)
|
||||||
|
.filter(|section| section.name == own_section_name)
|
||||||
|
.flat_map(|section| §ion.packages)
|
||||||
|
.for_each(|package| {
|
||||||
|
self.packages.insert(package.clone());
|
||||||
|
})
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -6,7 +6,7 @@ use std::collections::HashSet;
|
|||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::Package;
|
use crate::{Group, Package};
|
||||||
|
|
||||||
pub use pacman::Pacman;
|
pub use pacman::Pacman;
|
||||||
pub use rust::Rust;
|
pub use rust::Rust;
|
||||||
@@ -36,6 +36,7 @@ impl Backends {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct BackendIter(Option<Backends>);
|
pub(crate) struct BackendIter(Option<Backends>);
|
||||||
|
|
||||||
impl Iterator for BackendIter {
|
impl Iterator for BackendIter {
|
||||||
@@ -62,6 +63,7 @@ pub(crate) trait Backend {
|
|||||||
fn get_switches_install(&self) -> Switches;
|
fn get_switches_install(&self) -> Switches;
|
||||||
fn get_switches_remove(&self) -> Switches;
|
fn get_switches_remove(&self) -> Switches;
|
||||||
fn get_managed_packages(&self) -> &HashSet<Package>;
|
fn get_managed_packages(&self) -> &HashSet<Package>;
|
||||||
|
fn load(&mut self, groups: &HashSet<Group>);
|
||||||
|
|
||||||
/// Get all packages that are installed in the system.
|
/// Get all packages that are installed in the system.
|
||||||
fn get_all_installed_packages(&self) -> HashSet<Package>;
|
fn get_all_installed_packages(&self) -> HashSet<Package>;
|
||||||
@@ -118,10 +120,7 @@ pub(crate) trait Backend {
|
|||||||
fn get_unmanaged_packages_sorted(&self) -> Vec<Package> {
|
fn get_unmanaged_packages_sorted(&self) -> Vec<Package> {
|
||||||
let installed = self.get_explicitly_installed_packages();
|
let installed = self.get_explicitly_installed_packages();
|
||||||
let required = self.get_managed_packages();
|
let required = self.get_managed_packages();
|
||||||
let mut diff: Vec<_> = dbg!(installed)
|
let mut diff: Vec<_> = installed.difference(required).cloned().collect();
|
||||||
.difference(dbg!(required))
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
diff.sort_unstable();
|
diff.sort_unstable();
|
||||||
diff
|
diff
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use alpm::Alpm;
|
|||||||
use alpm::PackageReason::Explicit;
|
use alpm::PackageReason::Explicit;
|
||||||
|
|
||||||
use super::{Backend, Switches, Text};
|
use super::{Backend, Switches, Text};
|
||||||
use crate::{impl_backend_constants, Package};
|
use crate::{impl_backend_constants, Group, Package};
|
||||||
|
|
||||||
pub struct Pacman {
|
pub struct Pacman {
|
||||||
pub packages: HashSet<Package>,
|
pub packages: HashSet<Package>,
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
use std::{collections::HashSet, process::Command};
|
use std::{collections::HashSet, process::Command};
|
||||||
|
|
||||||
use super::{Backend, Switches, Text};
|
use super::{Backend, Switches, Text};
|
||||||
use crate::{impl_backend_constants, Package};
|
use crate::{impl_backend_constants, Group, Package};
|
||||||
|
|
||||||
pub struct Rust {
|
pub struct Rust {
|
||||||
pub packages: HashSet<Package>,
|
pub packages: HashSet<Package>,
|
||||||
|
|||||||
+8
-2
@@ -24,16 +24,22 @@ impl Pacdef {
|
|||||||
pub(crate) fn install_packages(&self) {
|
pub(crate) fn install_packages(&self) {
|
||||||
let mut to_install = ToInstallPerBackend::new();
|
let mut to_install = ToInstallPerBackend::new();
|
||||||
|
|
||||||
for b in Backends::iter() {
|
for mut b in Backends::iter() {
|
||||||
print!("{}: ", b.get_binary());
|
print!("{}: ", b.get_binary());
|
||||||
|
|
||||||
|
// dbg!(&self.groups);
|
||||||
|
|
||||||
|
b.load(&self.groups);
|
||||||
|
|
||||||
|
// dbg!(b.get_managed_packages());
|
||||||
|
|
||||||
let diff = b.get_missing_packages_sorted();
|
let diff = b.get_missing_packages_sorted();
|
||||||
if diff.is_empty() {
|
if diff.is_empty() {
|
||||||
println!("nothing to do");
|
println!("nothing to do");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(" Would install the following packages:");
|
println!("would install the following packages");
|
||||||
for p in &diff {
|
for p in &diff {
|
||||||
println!(" {p}");
|
println!(" {p}");
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ impl Group {
|
|||||||
let file = entry.context("getting a file")?;
|
let file = entry.context("getting a file")?;
|
||||||
let path = file.path();
|
let path = file.path();
|
||||||
|
|
||||||
let group = Group::try_from(dbg!(path))?;
|
let group = Group::try_from(path)?;
|
||||||
result.insert(group);
|
result.insert(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -13,7 +13,7 @@ impl Section {
|
|||||||
Self { name, packages }
|
Self { name, packages }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_lines<'a>(iter: &mut impl Iterator<Item = &'a str>) -> Self {
|
pub fn from_lines<'a>(iter: &mut (impl Iterator<Item = &'a str> + std::fmt::Debug)) -> Self {
|
||||||
let name = iter
|
let name = iter
|
||||||
.find(|line| line.starts_with('['))
|
.find(|line| line.starts_with('['))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -24,8 +24,8 @@ impl Section {
|
|||||||
|
|
||||||
let packages = iter
|
let packages = iter
|
||||||
.take_while(|line| !line.starts_with('['))
|
.take_while(|line| !line.starts_with('['))
|
||||||
.filter(|line| !line.contains(char::is_alphabetic))
|
.map(Package::try_from)
|
||||||
.map(Package::from)
|
.filter_map(|p| p.ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Self::new(name, packages)
|
Self::new(name, packages)
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ pub(crate) fn get_user_confirmation() -> bool {
|
|||||||
print!("Continue? [Y/n] ");
|
print!("Continue? [Y/n] ");
|
||||||
std::io::stdout().flush().unwrap();
|
std::io::stdout().flush().unwrap();
|
||||||
let reply = std::io::stdin().lock().lines().next().unwrap().unwrap();
|
let reply = std::io::stdin().lock().lines().next().unwrap().unwrap();
|
||||||
!(reply.is_empty() || reply.to_lowercase().contains('y'))
|
reply.trim().is_empty() || reply.to_lowercase().contains('y')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user