distroquery: files search and results pagination support

This commit is contained in:
Silvan Calarco 2013-10-15 00:12:47 +02:00
parent adf76fa4fd
commit 4dfb651da5
4 changed files with 204 additions and 83 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: distromatic 1.4.1\n"
"Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n"
"POT-Creation-Date: 2013-10-14 12:08+0200\n"
"POT-Creation-Date: 2013-10-15 00:07+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,112 +17,120 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/distroquery.c:178
#: src/distroquery.c:181
msgid "Source"
msgstr ""
#: src/distroquery.c:204
#: src/distroquery.c:225
msgid "Search"
msgstr ""
#: src/distroquery.c:238
#: src/distroquery.c:259
msgid "sources"
msgstr ""
#: src/distroquery.c:249
#: src/distroquery.c:270
msgid "Search software packages"
msgstr ""
#: src/distroquery.c:354 src/distroquery.c:557 src/distroquery.c:702
#: src/distroquery.c:374 src/distroquery.c:639 src/distroquery.c:807
msgid "Download"
msgstr ""
#: src/distroquery.c:363
#: src/distroquery.c:383
msgid "Details"
msgstr ""
#: src/distroquery.c:380
#: src/distroquery.c:401 src/distroquery.c:436
#, c-format
msgid "Other results in "
msgstr ""
#: src/distroquery.c:381
#: src/distroquery.c:402 src/distroquery.c:437
#, c-format
msgid "Results in"
msgstr ""
#: src/distroquery.c:384
#: src/distroquery.c:405 src/distroquery.c:440
msgid "for arch "
msgstr ""
#: src/distroquery.c:393
#: src/distroquery.c:414
msgid "provides"
msgstr ""
#: src/distroquery.c:456
#: src/distroquery.c:449
msgid "provides file "
msgstr ""
#: src/distroquery.c:516
msgid "result(s) shown"
msgstr ""
#: src/distroquery.c:459
#: src/distroquery.c:534
msgid "Search results for"
msgstr ""
#: src/distroquery.c:523 src/distroquery.c:666
#: src/distroquery.c:604 src/distroquery.c:769
msgid "Version"
msgstr ""
#: src/distroquery.c:528
#: src/distroquery.c:609
msgid "Size"
msgstr ""
#: src/distroquery.c:531
#: src/distroquery.c:612
msgid "Related packages"
msgstr ""
#: src/distroquery.c:559 src/distroquery.c:704
#: src/distroquery.c:641 src/distroquery.c:809
msgid "Developers details"
msgstr ""
#: src/distroquery.c:561
#: src/distroquery.c:643
msgid "Source package"
msgstr ""
#: src/distroquery.c:567 src/distroquery.c:705
#: src/distroquery.c:649 src/distroquery.c:810
msgid "Maintainer"
msgstr ""
#: src/distroquery.c:568 src/distroquery.c:706
#: src/distroquery.c:650 src/distroquery.c:811
msgid "Build date"
msgstr ""
#: src/distroquery.c:571
#: src/distroquery.c:653
msgid "Obsoletes"
msgstr ""
#: src/distroquery.c:583
#: src/distroquery.c:667
msgid "Provides"
msgstr ""
#: src/distroquery.c:597
#: src/distroquery.c:682
msgid "Requires"
msgstr ""
#: src/distroquery.c:673
#: src/distroquery.c:701
msgid "Files list"
msgstr ""
#: src/distroquery.c:776
msgid "Built packages"
msgstr ""
#: src/distroquery.c:709
#: src/distroquery.c:814
msgid "Source files"
msgstr ""
#: src/distroquery.c:718
#: src/distroquery.c:824
msgid "Patches"
msgstr ""
#: src/distroquery.c:728
#: src/distroquery.c:835
msgid "Build requirements"
msgstr ""
#: src/distroquery.c:740
#: src/distroquery.c:849
msgid "Changelog"
msgstr ""

BIN
po/it.gmo

Binary file not shown.

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: distromatic 1.4.1\n"
"Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n"
"POT-Creation-Date: 2013-10-14 12:08+0200\n"
"POT-Creation-Date: 2013-10-15 00:07+0200\n"
"PO-Revision-Date: 2013-10-14 01:19+0200\n"
"Last-Translator: Silvan Calarco <silvan.calarco@mambasoft.it>\n"
"Language-Team: Italian\n"
@ -17,112 +17,120 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: src/distroquery.c:178
#: src/distroquery.c:181
msgid "Source"
msgstr "Sorgente"
#: src/distroquery.c:204
#: src/distroquery.c:225
msgid "Search"
msgstr "Cerca"
#: src/distroquery.c:238
#: src/distroquery.c:259
msgid "sources"
msgstr "sorgenti"
#: src/distroquery.c:249
#: src/distroquery.c:270
msgid "Search software packages"
msgstr "Cerca pacchetti software"
#: src/distroquery.c:354 src/distroquery.c:557 src/distroquery.c:702
#: src/distroquery.c:374 src/distroquery.c:639 src/distroquery.c:807
msgid "Download"
msgstr "Scarica"
#: src/distroquery.c:363
#: src/distroquery.c:383
msgid "Details"
msgstr "Dettagli"
#: src/distroquery.c:380
#: src/distroquery.c:401 src/distroquery.c:436
#, c-format
msgid "Other results in "
msgstr "Altri risultati in "
#: src/distroquery.c:381
#: src/distroquery.c:402 src/distroquery.c:437
#, c-format
msgid "Results in"
msgstr "Risultati in"
#: src/distroquery.c:384
#: src/distroquery.c:405 src/distroquery.c:440
msgid "for arch "
msgstr "per l'architettura "
#: src/distroquery.c:393
#: src/distroquery.c:414
msgid "provides"
msgstr "fornisce"
#: src/distroquery.c:456
#: src/distroquery.c:449
msgid "provides file "
msgstr "fornisce il file "
#: src/distroquery.c:516
msgid "result(s) shown"
msgstr "risultati mostrati"
#: src/distroquery.c:459
#: src/distroquery.c:534
msgid "Search results for"
msgstr "Risultati della ricerca per"
#: src/distroquery.c:523 src/distroquery.c:666
#: src/distroquery.c:604 src/distroquery.c:769
msgid "Version"
msgstr "Versione"
#: src/distroquery.c:528
#: src/distroquery.c:609
msgid "Size"
msgstr "Dimensione"
#: src/distroquery.c:531
#: src/distroquery.c:612
msgid "Related packages"
msgstr "Pacchetti collegati"
#: src/distroquery.c:559 src/distroquery.c:704
#: src/distroquery.c:641 src/distroquery.c:809
msgid "Developers details"
msgstr "Dettagli per gli sviluppatori"
#: src/distroquery.c:561
#: src/distroquery.c:643
msgid "Source package"
msgstr "Pacchetto sorgente"
#: src/distroquery.c:567 src/distroquery.c:705
#: src/distroquery.c:649 src/distroquery.c:810
msgid "Maintainer"
msgstr "Manutentore"
#: src/distroquery.c:568 src/distroquery.c:706
#: src/distroquery.c:650 src/distroquery.c:811
msgid "Build date"
msgstr "Data di compilazione"
#: src/distroquery.c:571
#: src/distroquery.c:653
msgid "Obsoletes"
msgstr "Rende obsoleti"
#: src/distroquery.c:583
#: src/distroquery.c:667
msgid "Provides"
msgstr "Fornisce"
#: src/distroquery.c:597
#: src/distroquery.c:682
msgid "Requires"
msgstr "Richiede"
#: src/distroquery.c:673
#: src/distroquery.c:701
msgid "Files list"
msgstr "Lista dei file"
#: src/distroquery.c:776
msgid "Built packages"
msgstr "Pacchetti compilati"
#: src/distroquery.c:709
#: src/distroquery.c:814
msgid "Source files"
msgstr "File sorgenti"
#: src/distroquery.c:718
#: src/distroquery.c:824
msgid "Patches"
msgstr "Patch"
#: src/distroquery.c:728
#: src/distroquery.c:835
msgid "Build requirements"
msgstr "Requisiti per la compilazione"
#: src/distroquery.c:740
#: src/distroquery.c:849
msgid "Changelog"
msgstr "Modifiche"

View File

@ -83,6 +83,9 @@ char *query = "";
char *query_package;
char *query_repository;
char *query_arch = NULL;
int query_limit = 10;
int query_offset = 0;
char query_next[PATH_MAX] = "";
char *lang = "";
int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 };
@ -184,6 +187,24 @@ void printTagsLine(const char* arch, const char* tag, const char* group, const c
tag, group, license);
}
char* resolveFilePath(sqlite3 *db, long id, char *buffer) {
long currid = id;
sqlite3_stmt *stmt;
char sql[PATH_MAX];
buffer[0]='\0';
do {
snprintf(sql, PATH_MAX, "SELECT * FROM files WHERE id=%d", currid);
if (!sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL) == SQLITE_OK) return NULL;
if (sqlite3_step(stmt) != SQLITE_ROW) return NULL;
snprintf(sql, PATH_MAX, "/%s%s", sqlite3_column_text(stmt,1), buffer);
snprintf(buffer, PATH_MAX, "%s", sql);
currid = sqlite3_column_int(stmt,4); /* parent */
} while (currid >= 0);
return buffer;
}
void printInputForm() {
struct configTag *ct = firstconfigtag;
@ -254,6 +275,7 @@ void printQueryData() {
int a, i, j, k, numresults = 0, localresults, localprovidesresults;
char dbname[PATH_MAX];
sqlite3 *dbf;
sqlite3_stmt *statement, *stmt1;
char sql[PATH_MAX];
char buffer[PATH_MAX];
@ -304,7 +326,7 @@ void printQueryData() {
"groupdescr LIKE 'Graphical Desktop/%%' DESC, groupdescr LIKE 'Applications/%%' DESC, "
"groupdescr LIKE 'Development/%%' ASC, groupdescr LIKE 'Documentation%%' ASC, groupdescr LIKE 'System/Libraries%%' ASC, "
"name LIKE '%%-devel' ASC, name LIKE '%%-debug' ASC "
"LIMIT 100", queryenc, queryenc, queryenc, queryenc, queryenc, queryenc);
"LIMIT %d OFFSET %d", queryenc, queryenc, queryenc, queryenc, queryenc, queryenc, queryenc, query_limit, query_offset);
if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[a], sql, strlen(sql), &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++;
@ -370,7 +392,7 @@ void printQueryData() {
"(provides.id_package=packages.id AND provided.id=provides.id_provided) "
"AND provided.name LIKE '%%%s%%' "
"ORDER BY provided.name = '%s' DESC, provided.name LIKE '%s%%' DESC, provided.name LIKE '%%%s%%' DESC "
"LIMIT 100", queryenc, queryenc, queryenc, queryenc);
"LIMIT %d OFFSET %d", queryenc, queryenc, queryenc, queryenc, query_limit, query_offset);
if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[a], sql, strlen(sql), &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++;
@ -392,8 +414,47 @@ void printQueryData() {
_("provides"),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, "provided", "name")));
}
if (localprovidesresults > 0) printf("</div>");
}
/* files search */
snprintf(dbname, PATH_MAX, "%s%s-%s-files.db",
query_repositories[i]->repository_dir,
query_repositories[i]->tag,
query_repositories[i]->arch[a]);
if (!sqlite3_open_v2(dbname, &dbf, SQLITE_OPEN_READONLY, NULL)) {
snprintf(sql, PATH_MAX, "SELECT * FROM files,packages_files_rel "
"WHERE files.name LIKE '%%%s%%' AND "
"packages_files_rel.id_file = files.id "
"ORDER BY files.name = '%s' DESC, files.name LIKE '%s%%' DESC, "
"files.name LIKE '%%%s%%' DESC LIMIT %d OFFSET %d",
queryenc, queryenc, queryenc, queryenc, query_limit, query_offset);
if (sqlite3_prepare_v2(dbf, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) {
numresults++;
if (++localprovidesresults == 1) {
printf("<div style='position:relative'><hr><b>");
if (localresults > 0) printf(_("Other results in "));
else printf(_("Results in"));
printf(" %s %s %s:</b><br>",
query_repositories[i]->tag,
_("for arch "),
query_repositories[i]->arch[a]);
}
printf("<a href='javascript:distroquery_request("
"\"repository=%s&package=%s&arch=%s\")' style=\"color:black;background-color:lightblue\">%s</a> %s %s<br>",
query_repositories[i]->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packages_files_rel", "name")),
query_repositories[i]->arch[a],
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, "packages_files_rel", "name")),
_("provides file "),
resolveFilePath(dbf, sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "id_file")), buffer));
}
sqlite3_finalize(stmt1);
}
sqlite3_close(dbf);
}
if (localprovidesresults > 0) printf("</div>");
sqlite3_finalize(statement);
}
}
@ -403,8 +464,8 @@ void printQueryData() {
if (search_sources) {
snprintf(sql, PATH_MAX,
"SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%' OR version LIKE '%%%s%%' "
"ORDER BY name = '%s' DESC, name LIKE '%s%%' DESC, name LIKE '%%%s%%' DESC LIMIT 100",
queryenc, queryenc, queryenc, queryenc, queryenc, queryenc, queryenc);
"ORDER BY name = '%s' DESC, name LIKE '%s%%' DESC, name LIKE '%%%s%%' DESC LIMIT %d OFFSET %d",
queryenc, queryenc, queryenc, queryenc, queryenc, queryenc, queryenc, query_limit, query_offset);
for (i = 0; query_repositories[i] != NULL; i++) {
if (!query_repositories[i]->db[ARCHS_MAX]) {
snprintf(dbname, PATH_MAX, "%s%s-sources.db", query_repositories[i]->repository_dir, query_repositories[i]->tag);
@ -452,7 +513,22 @@ void printQueryData() {
printf("<hr>");
printf("]]></queryreply>");
printf("<querystatus><![CDATA[%d %s.]]></querystatus>", numresults, _("result(s) shown"));
printf("<querystatus><![CDATA[%d %s.&nbsp;", numresults, _("result(s) shown"));
k = query_offset / query_limit + 1; /* k = current shown page */
if (k < 7) j=1; else j=k-5; /* j = start pages list from */
if (numresults < query_limit) {
/* current page is last available */
a=k;
j=a-10;
if (j <= 0) j=1;
} else a=j+9; /* a = number of page links displayed */
for (i = j; i <= a; i++) {
if (i != k) printf("<a href='javascript:distroquery_request(\"%s&limit=%d&offset=%d\")'>",
query_next, query_limit, query_limit * (i-1));
printf("%d", i);
printf("</a>&nbsp");
}
printf("]]></querystatus>");
printf("<title><![CDATA[%s '%s' :: %s]]></title>",
_("Search results for"),
@ -473,7 +549,7 @@ void printPackageData() {
int a, i, j, k;
char dbname[PATH_MAX];
sqlite3 *db, *dbs, *dba;
sqlite3 *db, *dbs, *dbf;
sqlite3_stmt *statement, *stmt1, *stmt2;
char sql[PATH_MAX];
char buffer[PATH_MAX];
@ -618,6 +694,20 @@ void printPackageData() {
}
sqlite3_finalize(stmt1);
}
/* files list */
snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", ct->repository_dir, ct->tag, query_arch);
if (!sqlite3_open_v2(dbname, &dbf, SQLITE_OPEN_READONLY, NULL)) {
printf("<br><br>%s:<br>", _("Files list"));
snprintf(sql, PATH_MAX, "SELECT * FROM packages_files_rel WHERE name='%s'", query_package);
if (sqlite3_prepare_v2(dbf, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s<br>", resolveFilePath(dbf, sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "id_file")), buffer));
}
sqlite3_finalize(stmt1);
}
sqlite3_close(dbf);
}
sqlite3_close(dbs);
}
snprintf(buffer, PATH_MAX, "%s - %s",
@ -801,7 +891,20 @@ void parse_request_variables(char *data) {
query_package = valuetok;
} else if (!strcmp(vartok, "arch")) {
query_arch = valuetok;
} else if (!strcmp(vartok, "query")) {
} else if (!strcmp(vartok, "offset")) {
query_offset = atoi(url_decode(valuetok));
if (query_offset < 0) query_offset = 0;
} else if (!strcmp(vartok, "limit")) {
query_limit = atoi(url_decode(valuetok));
if (query_limit < 0) query_limit = 10;
else if (query_limit > 20) query_limit = 20;
} else if (!strcmp(vartok, "searchbox")) {
searchbox = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "lang")) {
lang = valuetok;
} else {
/* fields to make reusable query string for next pages */
if (!strcmp(vartok, "query")) {
query = url_decode(valuetok);
} else if (!strcmp(vartok, "search_milestone2")) {
search_milestone2 = strstr(valuetok, "false") != valuetok;
@ -817,12 +920,14 @@ void parse_request_variables(char *data) {
query_archs[2] = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "search_sources")) {
search_sources = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "searchbox")) {
searchbox = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "lang")) {
lang = valuetok;
}
strcat(query_next, vartok);
strcat(query_next, "=");
strcat(query_next, valuetok);
strcat(query_next, "&");
}
}
if (query_next[strlen(query_next)] == '&') query_next[strlen(query_next)] = '\0';
ct = firstconfigtag;
i = 0;