Skip to content

Commit

Permalink
Merge pull request #5 from isbm/isbm-profile-options
Browse files Browse the repository at this point in the history
Make optional profile settings
  • Loading branch information
isbm authored Sep 11, 2023
2 parents da19718 + fd985b9 commit 2c394bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
14 changes: 14 additions & 0 deletions doc/example-profile.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
# List of binary targets those are used
# as entry points for the bundle apps.
#
# Required
#
targets:
- /usr/bin/bash
- /usr/bin/apt

# List of preserved packages.
#
# Optional
#
packages:
- bash
- apt

# Profile config
#
# Optional
#
config:
# List of applied filters. Filter is active
# if present in this list.
#
# Optional
#
# NOTE: Filters are used to the data what is still left after
# the automatic examination.
filters:
Expand All @@ -39,6 +50,9 @@ config:

# Specific paths that were not automatically detected
# as not needed. Unix glob is used to be more specific, if needed.
#
# Optional
#
prune:
- /usr/share/bug/*
- /usr/share/lintian/*
41 changes: 25 additions & 16 deletions src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use std::{fs, io::Error, path::Path};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct PConfig {
filters: Vec<String>,
prune: Vec<String>,
filters: Option<Vec<String>>,
prune: Option<Vec<String>>,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct PTargets {
targets: Vec<String>,
packages: Vec<String>,
config: PConfig,
packages: Option<Vec<String>>,
config: Option<PConfig>,
}

/// Profile
Expand Down Expand Up @@ -61,23 +61,32 @@ impl Profile {

log::trace!("{:?}", p);

for flt in p.config.filters {
match flt.as_str() {
"l10n" => self.f_l10n = false,
"i18n" => self.f_i18n = false,
"doc" => self.f_doc = false,
"man" => self.f_man = false,
"log" => self.f_log = false,
"dir" => self.f_dir = false,
unknown => {
log::warn!("Unknown filter: {}", unknown);
if let Some(cfg) = p.config {
if let Some(af) = cfg.filters {
for flt in af {
match flt.as_str() {
"l10n" => self.f_l10n = false,
"i18n" => self.f_i18n = false,
"doc" => self.f_doc = false,
"man" => self.f_man = false,
"log" => self.f_log = false,
"dir" => self.f_dir = false,
unknown => {
log::warn!("Unknown filter: {}", unknown);
}
}
}
}
if let Some(prn) = cfg.prune {
self.f_prune.extend(prn);
}
}

self.packages.extend(p.packages);
self.targets.extend(p.targets);
self.f_prune.extend(p.config.prune);

if let Some(pkgs) = p.packages {
self.packages.extend(pkgs);
}

Ok(())
}
Expand Down

0 comments on commit 2c394bb

Please sign in to comment.