COPKGManager: add methodes to get infos and status of packages

This commit is contained in:
2015-02-04 11:17:16 +01:00
parent 2ca1648070
commit 55a027efbf
2 changed files with 23 additions and 5 deletions

View File

@@ -209,11 +209,14 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
bool COPKGManager::checkSize(const string& pkg_name) bool COPKGManager::checkSize(const string& pkg_name)
{ {
//get package size //get package size
string s_pkgsize = getPkgInfo(pkg_name, "Size"); string s_pkgsize = getPkgInfo(pkg_name, "Size", false);
std::istringstream s(s_pkgsize); std::istringstream s(s_pkgsize);
u_int64_t pkg_size; u_int64_t pkg_size;
s >> pkg_size; s >> pkg_size;
string status = getPkgInfo(pkg_name, "Status");
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] Status of %s: %s\n", __func__, __LINE__, pkg_name.c_str(), status.c_str());
//get available size //get available size
//TODO: Check writability! //TODO: Check writability!
struct statfs root_fs; struct statfs root_fs;
@@ -230,6 +233,8 @@ bool COPKGManager::checkSize(const string& pkg_name)
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Package: %s [required size=%lld (free size: %lld)]\n", __func__, __LINE__, pkg_name.c_str(), req_size, free_size); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Package: %s [required size=%lld (free size: %lld)]\n", __func__, __LINE__, pkg_name.c_str(), req_size, free_size);
if (free_size < req_size){ if (free_size < req_size){
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] WARNING: size check freesize=%lld package size=%lld (recommended: %lld)\n", __func__, __LINE__, free_size, pkg_size, req_size); dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] WARNING: size check freesize=%lld package size=%lld (recommended: %lld)\n", __func__, __LINE__, free_size, pkg_size, req_size);
//exit with false if package not installed, allready installed packages will be be removed before install, therefore it should be enough disk space available
// if (status.empty())
return false; return false;
} }
return true; return true;
@@ -573,10 +578,10 @@ string COPKGManager::getBlankPkgName(const string& line)
return ""; return "";
} }
string COPKGManager::getPkgInfo(const string& pkg_name, const string& pkg_key) string COPKGManager::getPkgInfo(const string& pkg_name, const string& pkg_key, bool current_status)
{ {
tmp_str.clear(); tmp_str.clear();
execCmd(pkg_types[OM_INFO] + pkg_name, false, true); execCmd(pkg_types[current_status ? OM_STATUS : OM_INFO] + pkg_name, false, true);
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] [data: %s]\n", __func__, __LINE__, tmp_str.c_str()); dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] [data: %s]\n", __func__, __LINE__, tmp_str.c_str());
return getKeyInfo(tmp_str, pkg_key, ":"); return getKeyInfo(tmp_str, pkg_key, ":");

View File

@@ -68,7 +68,20 @@ class COPKGManager : public CMenuTarget
}; };
void getPkgData(const int pkg_content_id); void getPkgData(const int pkg_content_id);
std::string getBlankPkgName(const std::string& line); std::string getBlankPkgName(const std::string& line);
std::string getPkgInfo(const std::string& pkg_name, const std::string& pkg_key);
/*
* Gets an info from opkg command info or status from a package via keywords as std::string
* 1st parameter is name of package as string eg. "gdb", without file extension or version data
* 2nd parameter needs a keyword like:
* Package, Version, Depends, Status, Section, Architecture, Maintainer, MD5Sum, Size, Filename, Source, Description
* These kewords are to find in the control package inside of the opkg package file and the package list.
* 3rd parameter sets the sub command status or info. For more details, take a look to the opkg commands via command line.
*/
std::string getPkgInfo(const std::string& pkg_name, const std::string& pkg_key, bool current_status = false);
//Does the same like getPkgInfo(), but only for status
std::string getPkgStatus(const std::string& pkg_name, const std::string& pkg_key){return getPkgInfo(pkg_name, pkg_key, true);}
std::string getKeyInfo(const std::string& input, const std::string& pkg_info_key, const std::string& delimiters); std::string getKeyInfo(const std::string& input, const std::string& pkg_info_key, const std::string& delimiters);
int showMenu(); int showMenu();
void updateMenu(); void updateMenu();