mpm

morphux package manager
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/mpm

commit 3a6b85568c49c8678b960538be984cae13497fc1
parent 38e01e370867ca25df90c4b0882953f3a1a1075a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon,  2 Nov 2015 00:34:02 +0100

Add(Packages): Dependencies handle

Diffstat:
Minc/Download.hpp | 1+
Minc/Package.hpp | 4+++-
Msrc/Download.cpp | 39++++++++++++++++++++++++++++++++++-----
Msrc/Package.cpp | 56++++++++++++++++++++++++++++++++++++++++++++------------
Msrc/main.cpp | 3+++
Dsrc/mpm | 0
6 files changed, 85 insertions(+), 18 deletions(-)

diff --git a/inc/Download.hpp b/inc/Download.hpp @@ -24,6 +24,7 @@ class Download { public: Download(std::list<std::string>); + Download(std::string); ~Download(void); void getAllPackages(void); diff --git a/inc/Package.hpp b/inc/Package.hpp @@ -26,7 +26,7 @@ class Package { public: Package(std::string name, Json::Value init); - Package(std::string name); + Package(std::string name, int toTest = 0); ~Package(void); void install(void); @@ -50,6 +50,7 @@ class Package { std::string getUrl(void); std::string getError(void); std::list<std::string> getNeededDeps(void); + std::list<std::string> getRecDeps(void); std::list<std::string> getOptionnalDeps(void); float getSize(void); int getToDownload(void); @@ -64,6 +65,7 @@ class Package { std::string _dir; std::string _error; std::list<std::string> _neededDeps; + std::list<std::string> _recoDeps; std::list<std::string> _optDeps; int _toDownload; int _toInstall; diff --git a/src/Download.cpp b/src/Download.cpp @@ -7,10 +7,35 @@ #include "Download.hpp" Download::Download(std::list<std::string> pack) : _packages(pack) { - this->_getInfo(); + if (this->_packages.size() > 0) + this->_getInfo(); + else + Error::warning("Need arguments !"); return ; } +Download::Download(std::string path) { + std::list<std::string> tmp; + std::list<std::string>::iterator it; + Package *p = new Package(path, 1); + + if (p->getNeededDeps().size() > 0) { + tmp = p->getNeededDeps(); + for (it = tmp.begin(); it != tmp.end(); it++) + this->_packages.push_back(*it); + } + if (p->getRecDeps().size() > 0) { + tmp = p->getRecDeps(); + for (it = tmp.begin(); it != tmp.end(); it++) + this->_packages.push_back(*it); + } + if (this->_packages.size() > 0) { + this->_getInfo(); + this->getAllPackages(); + } + this->_packList.push_back(p); +} + Download::~Download(void) { return ; } @@ -70,9 +95,9 @@ void Download::_createPackages(std::string file) { void Download::_addPackage(std::string name) { Package *p; + std::list<std::string> tmp; std::list<std::string>::iterator it; std::list<Package *>::iterator it2; - int i; for (it2 = this->_packList.begin(); it2 != this->_packList.end() && (*it2)->getName() != name; it2++); if (it2 != this->_packList.end()) @@ -92,10 +117,14 @@ void Download::_addPackage(std::string name) { Error::info("Package " + name + " already downloaded, skipping it"); } if (p->getNeededDeps().size() > 0) { - for (it = p->getNeededDeps().begin(), i = 0; - it != p->getNeededDeps().end(), i < (int)p->getNeededDeps().size(); it++, i++) { + tmp = p->getNeededDeps(); + for (it = tmp.begin(); it != tmp.end(); it++) + this->_addPackage(*it); + } + if (p->getRecDeps().size() > 0) { + tmp = p->getRecDeps(); + for (it = tmp.begin(); it != tmp.end(); it++) this->_addPackage(*it); - } } this->_packList.push_front(p); } diff --git a/src/Package.cpp b/src/Package.cpp @@ -6,7 +6,7 @@ # include "Package.hpp" -Package::Package(std::string name, Json::Value init) : _name(name), _error(""), _toDownload(0), _toInstall(0) { +Package::Package(std::string name, Json::Value init) : _name(name), _dir(""), _error(""), _toDownload(0), _toInstall(0) { Json::ValueIterator it; std::string path; struct stat buffer; @@ -17,16 +17,19 @@ Package::Package(std::string name, Json::Value init) : _name(name), _error(""), this->_error = init["Error"].asString(); return ; } - path = "/etc/mpm/packages/" + std::string(1, name[0]) + "/" + name; + this->_name = init["name"].asString(); + path = "/etc/mpm/packages/" + std::string(1, this->_name[0]) + "/" + this->_name; if (!(stat(path.c_str(), &buffer))) this->_toInstall = 1; this->_version = init["version"].asString(); this->_size = init["size"].asFloat(); this->_packageUrl = init["package"].asString(); - /* for (it = init["dependencies"]["needed"].begin(); it != init["dependencies"]["needed"].end(); it++)*/ - //this->_neededDeps.push_back(it->asString()); - //for (it = init["dependencies"]["optionnal"].begin(); it != init["dependencies"]["optionnal"].end(); it++) - /*this->_optDeps.push_back(it->asString());*/ + for (it = init["dependencies"]["needed"].begin(); it != init["dependencies"]["needed"].end(); it++) + this->_neededDeps.push_back(it->asString()); + for (it = init["dependencies"]["recommended"].begin(); it != init["dependencies"]["recommended"].end(); it++) + this->_recoDeps.push_back(it->asString()); + for (it = init["dependencies"]["optionnal"].begin(); it != init["dependencies"]["optionnal"].end(); it++) + this->_optDeps.push_back(it->asString()); for (i = this->_packageUrl.length() - 1; i > 0 && this->_packageUrl[i - 1] != '/'; i--); path = "/tmp/" + this->_packageUrl.substr(i, this->_packageUrl.length() - i); if (!(stat(path.c_str(), &buffer))) { @@ -35,14 +38,31 @@ Package::Package(std::string name, Json::Value init) : _name(name), _error(""), } } -Package::Package(std::string name) : _name(name), _toInstall(0) { +Package::Package(std::string name, int toTest) : _name(name), _toInstall(0) { std::string path; struct stat buffer; path = "/etc/mpm/packages/" + std::string(1, name[0]) + "/" + name; if (!(stat(path.c_str(), &buffer))) this->_toInstall = 1; - + if (toTest) { + Json::Value init; + Json::ValueIterator it; + + Error::info("Testing the archive " + name); + this->_archive = name; + this->decompress(); + this->readPackageInfos(); + init = this->_infos; + this->_version = init["package"]["version"].asString(); + this->_name = init["package"]["name"].asString(); + for (it = init["dependencies"]["needed"].begin(); it != init["dependencies"]["needed"].end(); it++) + this->_neededDeps.push_back(it->asString()); + for (it = init["dependencies"]["recommended"].begin(); it != init["dependencies"]["recommended"].end(); it++) + this->_recoDeps.push_back(it->asString()); + for (it = init["dependencies"]["optionnal"].begin(); it != init["dependencies"]["optionnal"].end(); it++) + this->_optDeps.push_back(it->asString()); + } } Package::~Package(void) { @@ -50,13 +70,19 @@ Package::~Package(void) { } void Package::install(void) { - this->decompress(); - this->readPackageInfos(); + Error::info("Installing " + this->_name + ":"); + if (this->_dir == "") { + this->decompress(); + this->readPackageInfos(); + } if (this->_infos["compilation"]["patches"].size()) this->patches(); if (this->_infos["compilation"]["before"].size()) this->before(); - this->configure(); + if (this->_infos["compilation"]["configure"].size()) + this->configure(); + else + chdir("srcs/"); this->make(); this->minstall(); if (this->_infos["compilation"]["after"].size()) @@ -147,7 +173,12 @@ void Package::configure(void) { Json::Value val = this->_infos["compilation"]["configure"]; Json::ValueIterator it; std::list<std::string> args; + std::string key = "configure"; + if (!this->_infos["compilation"].isMember("configure")) { + val = this->_infos["compilation"]["config"]; + key = "config"; + } chdir("srcs/"); Error::info("Configuring package"); for (it = val.begin(); it != val.end(); it++) { @@ -157,7 +188,7 @@ void Package::configure(void) { args.push_back("--" + it->asString()); } args.push_back("--prefix=" + Options::config["installation-directory"].asString()); - args.push_front("configure"); + args.push_front(key); this->_exec->execute(args); } @@ -263,6 +294,7 @@ std::string Package::getName(void) { return this->_name; }; std::string Package::getUrl(void) { return this->_packageUrl; }; std::string Package::getError(void) { return this->_error; }; std::list<std::string> Package::getNeededDeps(void) { return this->_neededDeps; }; +std::list<std::string> Package::getRecDeps(void) { return this->_recoDeps; }; std::list<std::string> Package::getOptionnalDeps(void) { return this->_optDeps; }; float Package::getSize(void) { return this->_size; }; int Package::getToDownload(void) { return this->_toDownload; }; diff --git a/src/main.cpp b/src/main.cpp @@ -44,6 +44,9 @@ void execute(void) { } else if (cmd == "remove") { Manager *m = new Manager(Options::args); m->uninstall(); + } else if (cmd == "test") { + Download *d = new Download(Options::args.front()); + d->installAll(); } else { Error::error("Unknown action: " + cmd); } diff --git a/src/mpm b/src/mpm Binary files differ.