Another few modifications to the sysadm/pkg - "pkg_info" action/API.

1) Add a new optional argument: "category". This option will be used if the "pkg_origins" argument is not, and limits the results to packages within the designated category.
2) Add a new optional argument: "result". This option may be set to anything other than "full" to restrict the information output to just the basic/simple information (no sub-categories of info such as "dependencies","requires","depends","options", etc...)

Example JSON request:
{"action":"pkg_info","category":"x11","result":"simple"}
These argument will result in a basic listing of all the packages within the x11 category. (name, version, origin, www, arch, comment, etc....)
{
This commit is contained in:
Ken Moore
2016-03-25 15:15:09 -04:00
parent 147f0c5338
commit 0d478da106
3 changed files with 12 additions and 4 deletions

View File

@@ -705,9 +705,15 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPkgRequest(const QJsonValue
if(in_args.toObject().value("pkg_origins").isString()){ pkgs << in_args.toObject().value("pkg_origins").toString(); }
else if(in_args.toObject().value("pkg_origins").isArray()){ pkgs = JsonArrayToStringList(in_args.toObject().value("pkg_origins").toArray()); }
}
//OPTIONAL: "category" (only used if "pkg_origins" is not specified)
QString cat;
if(in_args.toObject().contains("category")){ cat = in_args.toObject().value("category").toString(); }
//OPTIONAL: "result"
bool fullresults = true;
if(in_args.toObject().contains("result")){ fullresults = (in_args.toObject().value("result").toString()=="full"); }
//Parse
if(act=="pkg_info"){
QJsonObject info = sysadm::PKG::pkg_info(pkgs, repo);
QJsonObject info = sysadm::PKG::pkg_info(pkgs, repo, cat, fullresults);
if(!info.isEmpty()){ out->insert("pkg_info",info); }
else{ return RestOutputStruct::NOCONTENT; }
}else{

View File

@@ -62,7 +62,7 @@ inline QStringList requires_from_ids(QStringList ids){
// =================
// MAIN FUNCTIONS
// =================
QJsonObject PKG::pkg_info(QStringList origins, QString repo){
QJsonObject PKG::pkg_info(QStringList origins, QString repo, QString category, bool fullresults){
QJsonObject retObj;
QString dbname;
if(repo=="local"){ dbname= "/var/db/pkg/local.sqlite"; }
@@ -97,7 +97,8 @@ QJsonObject PKG::pkg_info(QStringList origins, QString repo){
//Now do all the pkg info, one pkg origin at a time
origins.removeAll("");
QString q_string = "SELECT * FROM packages";
if(!origins.isEmpty()){ q_string.append(" WHERE origin = '"+origins.join("' OR origon = '")+"'"); }
if(!origins.isEmpty()){ q_string.append(" WHERE origin = '"+origins.join("' OR origin = '")+"'"); }
else if(!category.isEmpty()){ q_string.append(" WHERE origin LIKE '"+category+"/%'"); }
QSqlQuery query(q_string);
while(query.next()){
QString id = query.value("id").toString(); //need this pkg id for later
@@ -114,6 +115,7 @@ QJsonObject PKG::pkg_info(QStringList origins, QString repo){
//include the annotations as base-level fields as well
info.insert( anno_from_id(q2.value("tag_id").toString()), anno_from_id(q2.value("value_id").toString()) );
}
if(!fullresults){ retObj.insert(origin,info); continue; } //skip the rest of the info queries
//OPTIONS
QSqlQuery q3("SELECT option_id, value FROM pkg_option WHERE package_id = '"+id+"'");
QJsonObject options;

View File

@@ -18,7 +18,7 @@ namespace sysadm{
class PKG{
public:
static QJsonObject pkg_info(QStringList origins, QString repo);
static QJsonObject pkg_info(QStringList origins, QString repo, QString category = "", bool fullresults = true);
};
} //end of sysadm namespace