add debian backend
This commit is contained in:
@@ -13,7 +13,6 @@ categories = ["command-line-utilities"]
|
||||
features = ["alpm/docs-rs"]
|
||||
|
||||
[dependencies]
|
||||
alpm = { version = "2.2", optional = true }
|
||||
anyhow = { workspace = true }
|
||||
clap = "4.1"
|
||||
const_format = { version = "0.2", default-features = false }
|
||||
@@ -21,13 +20,18 @@ path-absolutize = "3.0"
|
||||
regex = "1.7"
|
||||
termios = "0.3"
|
||||
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_yaml = "0.9"
|
||||
serde_derive = "1.0"
|
||||
serde = "1.0"
|
||||
|
||||
pacdef_macros = { path = "../pacdef_macros", version = "0.1" }
|
||||
|
||||
# backends
|
||||
alpm = { version = "2.2", optional = true }
|
||||
rust-apt = { version = "0.5", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["arch"]
|
||||
arch = ["dep:alpm"]
|
||||
debian = ["dep:rust-apt"]
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
use std::collections::HashSet;
|
||||
use std::process::Command;
|
||||
use std::process::ExitStatus;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use rust_apt::cache::PackageSort;
|
||||
use rust_apt::new_cache;
|
||||
|
||||
use crate::backend::backend_trait::{Backend, Switches, Text};
|
||||
use crate::{impl_backend_constants, Group, Package};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Debian {
|
||||
pub(crate) packages: HashSet<Package>,
|
||||
}
|
||||
|
||||
const BINARY: Text = "apt";
|
||||
const SECTION: Text = "debian";
|
||||
|
||||
const SWITCHES_INFO: Switches = &["show"];
|
||||
const SWITCHES_INSTALL: Switches = &["install"];
|
||||
const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; // not needed
|
||||
const SWITCHES_REMOVE: Switches = &["remove"];
|
||||
|
||||
impl Backend for Debian {
|
||||
impl_backend_constants!();
|
||||
|
||||
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||
let cache = new_cache!()?;
|
||||
let sort = PackageSort::default().installed();
|
||||
|
||||
let mut result = HashSet::new();
|
||||
for pkg in cache.packages(&sort) {
|
||||
result.insert(Package::from(pkg.name().to_string()));
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||
let cache = new_cache!()?;
|
||||
let sort = PackageSort::default().installed().manually_installed();
|
||||
|
||||
let mut result = HashSet::new();
|
||||
for pkg in cache.packages(&sort) {
|
||||
result.insert(Package::from(pkg.name().to_string()));
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn make_dependency(&self, packages: &[Package]) -> Result<ExitStatus> {
|
||||
let mut cmd = Command::new("apt-mark");
|
||||
cmd.arg("auto");
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.status()
|
||||
.with_context(|| format!("running command [{cmd:?}]"))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debian {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
packages: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "arch")]
|
||||
pub mod arch;
|
||||
#[cfg(feature = "debian")]
|
||||
pub mod debian;
|
||||
pub mod rust;
|
||||
|
||||
@@ -14,5 +14,7 @@ use pacdef_macros::Register;
|
||||
pub enum Backends {
|
||||
#[cfg(feature = "arch")]
|
||||
Arch,
|
||||
#[cfg(feature = "debian")]
|
||||
Debian,
|
||||
Rust,
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ pub const fn get_version_string() -> &'static str {
|
||||
fn get_included_backends() -> Vec<&'static str> {
|
||||
let mut result = vec![];
|
||||
for backend in Backends::iter() {
|
||||
result.push(backend.get_section())
|
||||
result.push(backend.get_section());
|
||||
}
|
||||
result.sort_unstable();
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user