DistroqueryAPI: added children packages via getBuiltPackagesFromSourceID and other improvements
This commit is contained in:
parent
e73d648e1b
commit
0aff59e3f3
@ -91,6 +91,9 @@ json DistroqueryAPI::getPackageSourceDetailsById(configTag* ct, long id) {
|
|||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
ss << std::put_time(gmtime(&itt), "%FT%TZ");
|
ss << std::put_time(gmtime(&itt), "%FT%TZ");
|
||||||
j["buildtime"] = ss.str();
|
j["buildtime"] = ss.str();
|
||||||
|
// Download URL
|
||||||
|
j["download_url"] = string(ct->download_prefix) + ct->download_dir + "/SRPMS.base/" +
|
||||||
|
string(j["name"]) + "-" + string(j["version"]) + "-" + string(j["release"]) + ".src.rpm";
|
||||||
// Source URL
|
// Source URL
|
||||||
j["source_url"] = "https://src.openmamba.org/rpms/" + string(j["name"]);
|
j["source_url"] = "https://src.openmamba.org/rpms/" + string(j["name"]);
|
||||||
} else {
|
} else {
|
||||||
@ -117,7 +120,7 @@ json DistroqueryAPI::getRepositoryPackages(string repository) {
|
|||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "SELECT * FROM sources";
|
sql = "SELECT * FROM sources ORDER BY name COLLATE NOCASE ASC";
|
||||||
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
|
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
|
||||||
j = json::array();
|
j = json::array();
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
@ -134,10 +137,42 @@ json DistroqueryAPI::getRepositoryPackages(string repository) {
|
|||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json DistroqueryAPI::getBuiltPackagesFromSourceID(configTag* ct, long id) {
|
||||||
|
json j = json::array();
|
||||||
|
string sql;
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
|
||||||
|
for (auto arch: ct->arch) {
|
||||||
|
if (arch == NULL) break;
|
||||||
|
auto db = openRepositoryDatabase(ct, arch);
|
||||||
|
if (!db) {
|
||||||
|
j = {};
|
||||||
|
j["error"] = "error opening database for repository '" + string(ct->tag) + "' and arch '" + arch + "'";
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = "SELECT * FROM packages WHERE id_source = " + to_string(id) + " ORDER BY name";
|
||||||
|
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
|
||||||
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
|
json package = {};
|
||||||
|
package["arch"] = arch;
|
||||||
|
package["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "name")));
|
||||||
|
j.push_back(package);
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
} else {
|
||||||
|
j = {};
|
||||||
|
j["error"] = "error preparing query '" + sql + "'";
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
json DistroqueryAPI::getPackageSourceDetails(string repository, string package) {
|
json DistroqueryAPI::getPackageSourceDetails(string repository, string package) {
|
||||||
json j;
|
json j;
|
||||||
string sql;
|
string sql;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt, *stmt2;
|
||||||
|
|
||||||
struct configTag* ct = findRepositoryByTag(repository.c_str());
|
struct configTag* ct = findRepositoryByTag(repository.c_str());
|
||||||
if (ct == NULL) {
|
if (ct == NULL) {
|
||||||
@ -157,8 +192,30 @@ json DistroqueryAPI::getPackageSourceDetails(string repository, string package)
|
|||||||
long id;
|
long id;
|
||||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
id = sqlite3_column_int(stmt,sqlite3_find_column_id(stmt, NULL, "id"));
|
id = sqlite3_column_int(stmt,sqlite3_find_column_id(stmt, NULL, "id"));
|
||||||
return getPackageSourceDetailsById(ct, id);
|
j = getPackageSourceDetailsById(ct, id);
|
||||||
|
} else {
|
||||||
|
j["error"] = "source package '" + package + "' not found in repository '" + repository + "'";
|
||||||
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build requires
|
||||||
|
sql = "SELECT * FROM buildrequires WHERE id_source=" + to_string(id) +
|
||||||
|
" ORDER BY buildrequirename";
|
||||||
|
j["buildrequires"] = json::array();
|
||||||
|
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt2, NULL) == SQLITE_OK) {
|
||||||
|
while (sqlite3_step(stmt2) == SQLITE_ROW) {
|
||||||
|
json buildrequire = {};
|
||||||
|
buildrequire["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "buildrequirename")));
|
||||||
|
buildrequire["flags"] = rpmSenseFlagsToString(sqlite3_column_int(stmt2,sqlite3_find_column_id(stmt2, NULL, "buildrequireflags")));
|
||||||
|
buildrequire["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "buildrequireversion")));
|
||||||
|
j["buildrequires"].push_back(buildrequire);
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Children
|
||||||
|
j["children"] = getBuiltPackagesFromSourceID(ct, id);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
j["error"] = "error preparing query '" + sql + "'";
|
j["error"] = "error preparing query '" + sql + "'";
|
||||||
return j;
|
return j;
|
||||||
@ -204,7 +261,7 @@ json DistroqueryAPI::getPackageDetails(string repository, string package, string
|
|||||||
j["size"] = sqlite3_column_int(stmt,sqlite3_find_column_id(stmt, NULL, "size"));
|
j["size"] = sqlite3_column_int(stmt,sqlite3_find_column_id(stmt, NULL, "size"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
j["error"] = "no results from query '" + sql + "'";
|
j["error"] = "package '" + package + "' not found in repository '" + repository + "'";
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ class DistroqueryAPI {
|
|||||||
json getRepositoryPackages(string repository);
|
json getRepositoryPackages(string repository);
|
||||||
json getPackageSourceDetailsById(configTag* ct, long id);
|
json getPackageSourceDetailsById(configTag* ct, long id);
|
||||||
json getPackageSourceDetails(string repository, string package);
|
json getPackageSourceDetails(string repository, string package);
|
||||||
|
json getBuiltPackagesFromSourceID(configTag* ct, long id);
|
||||||
json getPackageDetails(string repository, string package, string arch);
|
json getPackageDetails(string repository, string package, string arch);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user