summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-06 11:40:07 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-06 11:41:08 +0200
commit9f29c971e589fd07c9da5871959bffaabf0f70ff (patch)
tree3cd43ec6158b55fbc0ae440b4be2083e676b1888
parentcaf7aa235c6c305e59a2587348eda9300736fc72 (diff)
Remove compare functionality
This functionality was fundamentally broken and not good. We will (re)implement similar functionality in the future, though. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/cli.rs30
-rw-r--r--src/compare.rs15
-rw-r--r--src/frontend/json.rs49
-rw-r--r--src/frontend/list.rs31
-rw-r--r--src/frontend/mod.rs8
-rw-r--r--src/frontend/table.rs27
-rw-r--r--src/main.rs54
7 files changed, 0 insertions, 214 deletions
diff --git a/src/cli.rs b/src/cli.rs
index c99bbd9..871f941 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -142,36 +142,6 @@ pub fn build_cli<'a>() -> App<'a, 'a> {
)
)
- .subcommand(SubCommand::with_name("compare")
- .about("Compare a list of packages to distro repositories")
- .arg(Arg::with_name("compare-list")
- .index(1)
- .required(true)
- .multiple(false)
- .takes_value(true)
- .value_name("FILE")
- .help("Compare the data from this list to a list of distros out there. Supports JSON and CSV, based on file extension (.json / .csv)"))
- .arg(Arg::with_name("compare-distros")
- .index(2)
- .required(true)
- .multiple(true)
- .takes_value(true)
- .value_name("DIST")
- .help("A list of repology distribution names to compare to"))
-
- .after_help(r#"
- Compare a list of packages to all supplied repology distributions.
- The list of packages shall have the following format:
-
- * CSV:
- Header: name;version;comment
-
- * JSON:
- { "name": "...", "version": "...", "comment": "..." }
-
- "#)
- )
-
.after_help(r#"
repolocli can read data from stdin, if you want to postprocess repology.org data you already
fetched from repology.org/api/v1 via curl (or some other method).
diff --git a/src/compare.rs b/src/compare.rs
deleted file mode 100644
index 047fc99..0000000
--- a/src/compare.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
-pub struct ComparePackage {
- name: String,
- version: String,
-}
-
-impl ComparePackage {
- pub fn name(&self) -> &String {
- &self.name
- }
-
- pub fn version(&self) -> &String {
- &self.version
- }
-}
diff --git a/src/frontend/json.rs b/src/frontend/json.rs
index 42e44d1..2a7f40a 100644
--- a/src/frontend/json.rs
+++ b/src/frontend/json.rs
@@ -1,17 +1,12 @@
use std::io::Stdout;
use std::io::Write;
-use std::ops::Deref;
use anyhow::Error;
use anyhow::Result;
use librepology::v1::types::Package;
use librepology::v1::types::Problem;
-use librepology::v1::types::Repo;
-use crate::backend::Backend;
-use crate::compare::ComparePackage;
use crate::frontend::Frontend;
-use librepology::v1::api::Api;
pub struct JsonFrontend(Stdout);
@@ -43,48 +38,4 @@ impl Frontend for JsonFrontend {
fn list_problems(&self, problems: Vec<Problem>) -> Result<()> {
self.write(serde_json::ser::to_string_pretty(&problems).map_err(Error::from)?)
}
-
- fn compare_packages(
- &self,
- packages: Vec<ComparePackage>,
- backend: &Backend,
- filter_repos: Vec<Repo>,
- ) -> Result<()> {
- #[derive(Serialize)]
- struct PackageComp {
- // not optimal, as we have to clone the inner variables from the package
- // but using references is too complicated right now
- package_name: String,
- local_version: String,
- comparisons: Vec<CompareTarget>,
- }
-
- #[derive(Serialize)]
- struct CompareTarget {
- version: String,
- repo: String,
- }
-
- let mut output: Vec<PackageComp> = vec![];
-
- for package in packages.iter() {
- let comparisons = backend
- .project(package.name().deref())?
- .into_iter()
- .filter(|p| filter_repos.contains(p.repo()))
- .map(|upstream_package| CompareTarget {
- version: upstream_package.version().deref().clone(),
- repo: upstream_package.repo().deref().clone(),
- })
- .collect();
-
- output.push(PackageComp {
- package_name: package.name().clone(),
- local_version: package.version().clone(),
- comparisons,
- });
- }
-
- self.write(serde_json::ser::to_string_pretty(&output)?)
- }
}
diff --git a/src/frontend/list.rs b/src/frontend/list.rs
index 469d6ec..9e06828 100644
--- a/src/frontend/list.rs
+++ b/src/frontend/list.rs
@@ -7,12 +7,8 @@ use anyhow::Result;
use librepology::v1::types::Name;
use librepology::v1::types::Package;
use librepology::v1::types::Problem;
-use librepology::v1::types::Repo;
-use crate::backend::Backend;
-use crate::compare::ComparePackage;
use crate::frontend::Frontend;
-use librepology::v1::api::Api;
pub struct ListFrontend(Stdout);
@@ -86,31 +82,4 @@ impl Frontend for ListFrontend {
})
}
- fn compare_packages(
- &self,
- packages: Vec<ComparePackage>,
- backend: &Backend,
- filter_repos: Vec<Repo>,
- ) -> Result<()> {
- let mut output = self.0.lock();
-
- for package in packages {
- backend
- .project(package.name().deref())?
- .into_iter()
- .filter(|p| filter_repos.contains(p.repo()))
- .map(|upstream_package| {
- writeln!(output,
- "{our_package_name} - {our_package_version} - {up_repo_name} - {up_package_version}",
- our_package_name = package.name().deref(),
- our_package_version = package.version().deref(),
- up_repo_name = upstream_package.repo().deref(),
- up_package_version = upstream_package.version().deref()
- ).map_err(Error::from)
- })
- .collect::<Result<Vec<()>>>()?;
- }
-
- Ok(())
- }
}
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index c9ef381..f1d5001 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -3,8 +3,6 @@ use clap::ArgMatches;
use librepology::v1::types::*;
-use crate::backend::Backend;
-use crate::compare::ComparePackage;
use crate::config::Configuration;
use crate::frontend::json::JsonFrontend;
use crate::frontend::list::ListFrontend;
@@ -14,12 +12,6 @@ use crate::frontend::table::TableFrontend;
pub trait Frontend {
fn list_packages(&self, packages: Vec<Package>) -> Result<()>;
fn list_problems(&self, problems: Vec<Problem>) -> Result<()>;
- fn compare_packages(
- &self,
- packages: Vec<ComparePackage>,
- backend: &Backend,
- filter_repos: Vec<Repo>,
- ) -> Result<()>;
}
pub mod json;
diff --git a/src/frontend/table.rs b/src/frontend/table.rs
index 6bb42d2..6a18af3 100644
--- a/src/frontend/table.rs
+++ b/src/frontend/table.rs
@@ -5,14 +5,10 @@ use anyhow::Result;
use librepology::v1::types::Name;
use librepology::v1::types::Package;
use librepology::v1::types::Problem;
-use librepology::v1::types::Repo;
use prettytable::format;
use prettytable::Table;
-use crate::backend::Backend;
-use crate::compare::ComparePackage;
use crate::frontend::Frontend;
-use librepology::v1::api::Api;
/// A Frontend that formats the output in a nice ASCII-art table
pub struct TableFrontend(Stdout);
@@ -95,27 +91,4 @@ impl Frontend for TableFrontend {
self.print(table)
}
- fn compare_packages(
- &self,
- packages: Vec<ComparePackage>,
- backend: &Backend,
- filter_repos: Vec<Repo>,
- ) -> Result<()> {
- let mut table = self.mktable();
- for package in packages {
- backend
- .project(package.name().deref())?
- .into_iter()
- .filter(|p| filter_repos.contains(p.repo()))
- .for_each(|upstream_package| {
- table.add_row(row![
- package.name().clone(),
- package.version().clone(),
- upstream_package.repo().clone(),
- upstream_package.version().clone(),
- ]);
- });
- }
- self.print(table)
- }
}
diff --git a/src/main.rs b/src/main.rs
index 6a171a6..838f4a2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,9 +9,6 @@ extern crate toml;
extern crate url;
extern crate xdg;
-#[cfg(feature = "compare_csv")]
-extern crate csv;
-
#[macro_use]
extern crate serde_derive;
#[macro_use]
@@ -23,16 +20,12 @@ extern crate prettytable;
mod backend;
mod cli;
-mod compare;
mod config;
mod frontend;
use std::cmp::Ordering;
use std::path::PathBuf;
-#[cfg(feature = "compare_csv")]
-use std::io::Cursor;
-
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
@@ -42,7 +35,6 @@ use filters::filter::Filter;
use itertools::Itertools;
use semver::Version as SemverVersion;
-use compare::ComparePackage;
use config::Configuration;
use librepology::v1::api::Api;
use librepology::v1::types::Package;
@@ -75,36 +67,6 @@ fn initialize_logging(app: &ArgMatches) -> Result<()> {
.map_err(Error::from)
}
-fn deserialize_package_list(s: String, filepath: &str) -> Result<Vec<ComparePackage>> {
- let pb = PathBuf::from(filepath);
- let ext = pb
- .extension()
- .ok_or_else(|| format_err!("Couldn't get file extension: {}", filepath))?
- .to_str()
- .ok_or_else(|| format_err!("Not valid Unicode: {}", filepath))?;
-
- match ext {
- "json" => serde_json::from_str(&s).map_err(Error::from),
-
- #[cfg(feature = "compare_csv")]
- "csv" => {
- let cursor = Cursor::new(s);
- let mut v: Vec<ComparePackage> = vec![];
- let mut reader = csv::ReaderBuilder::new()
- .has_headers(true)
- .delimiter(b';')
- .from_reader(cursor);
-
- for element in reader.deserialize() {
- v.push(element?);
- }
- Ok(v)
- }
-
- other => Err(format_err!("Unknown file extension: {}", other)),
- }
-}
-
fn app() -> Result<()> {
let app = cli::build_cli().get_matches();
initialize_logging(&app)?;
@@ -267,22 +229,6 @@ fn app() -> Result<()> {
frontend.list_problems(problems)
}
- ("compare", Some(mtch)) => {
- debug!("Subcommand: 'compare'");
- let repos = mtch
- .values_of("compare-distros")
- .unwrap()
- .map(String::from)
- .map(Repo::new)
- .collect();
- let file_path = mtch.value_of("compare-list").unwrap(); // safe by clap
- let content = ::std::fs::read_to_string(file_path)?;
- let pkgs: Vec<ComparePackage> = deserialize_package_list(content, file_path)?;
-
- debug!("Comparing packages...");
- frontend.compare_packages(pkgs, &backend, repos)
- }
-
(other, _mtch) => {
debug!("Subcommand: {}", other);
app.is_present("input_stdin")