Browse Source

Manager: Move package list grabbing to separate function

master
Riyyi 3 years ago
parent
commit
aa702b79b9
  1. 65
      src/package.cpp
  2. 11
      src/package.h

65
src/package.cpp

@ -14,6 +14,8 @@
#include "util/file.h" #include "util/file.h"
#include "util/system.h" #include "util/system.h"
std::string Package::m_hostname;
Package::Package() Package::Package()
{ {
} }
@ -24,38 +26,17 @@ Package::~Package()
// ----------------------------------------- // -----------------------------------------
void Package::aurInstall(const std::vector<std::string>& targets) void Package::aurInstall()
{ {
} }
void Package::install(const std::vector<std::string>& targets) void Package::install()
{ {
} }
void Package::list(const std::vector<std::string>& targets) void Package::list(const std::vector<std::string>& targets)
{ {
distroDetect(); std::string packages = getPackageList();
distroDependencies();
std::string packages;
Util::System $;
if (m_distro == Distro::Arch) {
auto basePackages = $("pactree -u base").tail(2, true);
auto develPackages = $("pacman -Qqg base-devel");
auto filterList = (basePackages + develPackages).sort(true);
auto packageList = ($("pacman -Qqe") | $("grep -xv " + filterList.output())).sort();
packages = packageList.output();
}
else if (m_distro == Distro::Debian) {
auto installedList = $("dpkg-query --show --showformat=${Package}\\t${Priority}\\n");
auto filterList = (installedList | $("grep -E required|important|standard")).cut(1);
installedList = installedList.cut(1);
auto installedManuallyList = $("awk '/Commandline:.* install / && !/APT::/ { print $NF }' /var/log/apt/history.log");
installedManuallyList = (installedManuallyList + $("apt-mark showmanual")).sort(true);
auto packageList = installedManuallyList | $("grep -x " + installedList.output()) | $("grep -xv " + filterList.output());
packages = packageList.output();
}
if (targets.empty()) { if (targets.empty()) {
printf("%s", packages.c_str()); printf("%s", packages.c_str());
@ -79,8 +60,14 @@ void Package::list(const std::vector<std::string>& targets)
printf("%s", packages.c_str()); printf("%s", packages.c_str());
} }
void Package::store(const std::vector<std::string>& targets) void Package::store()
{ {
std::string packages = getPackageList();
auto packageFile = Util::File("./packages");
packageFile.clear();
packageFile.append(packages);
packageFile.flush();
} }
// ----------------------------------------- // -----------------------------------------
@ -152,3 +139,31 @@ bool Package::distroDependencies()
return true; return true;
} }
std::string Package::getPackageList()
{
distroDetect();
distroDependencies();
std::string packages;
Util::System $;
if (m_distro == Distro::Arch) {
auto basePackages = $("pactree -u base").tail(2, true);
auto develPackages = $("pacman -Qqg base-devel");
auto filterList = (basePackages + develPackages).sort(true);
auto packageList = ($("pacman -Qqe") | $("grep -xv " + filterList.output())).sort();
packages = packageList.output();
}
else if (m_distro == Distro::Debian) {
auto installedList = $("dpkg-query --show --showformat=${Package}\\t${Priority}\\n");
auto filterList = (installedList | $("grep -E required|important|standard")).cut(1);
installedList = installedList.cut(1);
auto installedManuallyList = $("awk '/Commandline:.* install / && !/APT::/ { print $NF }' /var/log/apt/history.log");
installedManuallyList = (installedManuallyList + $("apt-mark showmanual")).sort(true);
auto packageList = installedManuallyList | $("grep -x " + installedList.output()) | $("grep -xv " + filterList.output());
packages = packageList.output();
}
return packages;
}

11
src/package.h

@ -21,14 +21,19 @@ public:
Debian, Debian,
}; };
void aurInstall(const std::vector<std::string>& targets = {}); void aurInstall();
void install(const std::vector<std::string>& targets = {}); void install();
void list(const std::vector<std::string>& targets = {}); void list(const std::vector<std::string>& targets = {});
void store(const std::vector<std::string>& targets = {}); void store();
static void setHostname(const std::string& hostname) { m_hostname = hostname; }
private: private:
bool distroDetect(); bool distroDetect();
bool distroDependencies(); bool distroDependencies();
std::string getPackageList();
static std::string m_hostname;
Distro m_distro { Distro::Unsupported }; Distro m_distro { Distro::Unsupported };
}; };

Loading…
Cancel
Save