distroquery: make files search optional and refine check for other available results and paging

This commit is contained in:
Silvan Calarco 2013-10-15 11:40:22 +02:00
parent 4dfb651da5
commit 07d3dbdf7d
4 changed files with 146 additions and 107 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: distromatic 1.4.1\n" "Project-Id-Version: distromatic 1.4.1\n"
"Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n" "Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n"
"POT-Creation-Date: 2013-10-15 00:07+0200\n" "POT-Creation-Date: 2013-10-15 11:33+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,120 +17,128 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: src/distroquery.c:181 #: src/distroquery.c:182
msgid "Source" msgid "Source"
msgstr "" msgstr ""
#: src/distroquery.c:225 #: src/distroquery.c:227
msgid "Search" msgid "Search"
msgstr "" msgstr ""
#: src/distroquery.c:259 #: src/distroquery.c:261
msgid "sources" msgid "sources"
msgstr "" msgstr ""
#: src/distroquery.c:270 #: src/distroquery.c:265
msgid "files"
msgstr ""
#: src/distroquery.c:276
msgid "Search software packages" msgid "Search software packages"
msgstr "" msgstr ""
#: src/distroquery.c:374 src/distroquery.c:639 src/distroquery.c:807 #: src/distroquery.c:380 src/distroquery.c:658 src/distroquery.c:826
msgid "Download" msgid "Download"
msgstr "" msgstr ""
#: src/distroquery.c:383 #: src/distroquery.c:389
msgid "Details" msgid "Details"
msgstr "" msgstr ""
#: src/distroquery.c:401 src/distroquery.c:436 #: src/distroquery.c:407 src/distroquery.c:443
#, c-format #, c-format
msgid "Other results in " msgid "Other results in "
msgstr "" msgstr ""
#: src/distroquery.c:402 src/distroquery.c:437 #: src/distroquery.c:408 src/distroquery.c:444
#, c-format #, c-format
msgid "Results in" msgid "Results in"
msgstr "" msgstr ""
#: src/distroquery.c:405 src/distroquery.c:440 #: src/distroquery.c:411 src/distroquery.c:447
msgid "for arch " msgid "for arch "
msgstr "" msgstr ""
#: src/distroquery.c:414 #: src/distroquery.c:420
msgid "provides" msgid "provides"
msgstr "" msgstr ""
#: src/distroquery.c:449 #: src/distroquery.c:456
msgid "provides file " msgid "provides file "
msgstr "" msgstr ""
#: src/distroquery.c:516 #: src/distroquery.c:529
msgid "result(s) shown" msgid "result(s) shown"
msgstr "" msgstr ""
#: src/distroquery.c:534 #: src/distroquery.c:531
msgid "result(s) found"
msgstr ""
#: src/distroquery.c:553
msgid "Search results for" msgid "Search results for"
msgstr "" msgstr ""
#: src/distroquery.c:604 src/distroquery.c:769 #: src/distroquery.c:623 src/distroquery.c:788
msgid "Version" msgid "Version"
msgstr "" msgstr ""
#: src/distroquery.c:609 #: src/distroquery.c:628
msgid "Size" msgid "Size"
msgstr "" msgstr ""
#: src/distroquery.c:612 #: src/distroquery.c:631
msgid "Related packages" msgid "Related packages"
msgstr "" msgstr ""
#: src/distroquery.c:641 src/distroquery.c:809 #: src/distroquery.c:660 src/distroquery.c:828
msgid "Developers details" msgid "Developers details"
msgstr "" msgstr ""
#: src/distroquery.c:643 #: src/distroquery.c:662
msgid "Source package" msgid "Source package"
msgstr "" msgstr ""
#: src/distroquery.c:649 src/distroquery.c:810 #: src/distroquery.c:668 src/distroquery.c:829
msgid "Maintainer" msgid "Maintainer"
msgstr "" msgstr ""
#: src/distroquery.c:650 src/distroquery.c:811 #: src/distroquery.c:669 src/distroquery.c:830
msgid "Build date" msgid "Build date"
msgstr "" msgstr ""
#: src/distroquery.c:653 #: src/distroquery.c:672
msgid "Obsoletes" msgid "Obsoletes"
msgstr "" msgstr ""
#: src/distroquery.c:667 #: src/distroquery.c:686
msgid "Provides" msgid "Provides"
msgstr "" msgstr ""
#: src/distroquery.c:682 #: src/distroquery.c:701
msgid "Requires" msgid "Requires"
msgstr "" msgstr ""
#: src/distroquery.c:701 #: src/distroquery.c:720
msgid "Files list" msgid "Files list"
msgstr "" msgstr ""
#: src/distroquery.c:776 #: src/distroquery.c:795
msgid "Built packages" msgid "Built packages"
msgstr "" msgstr ""
#: src/distroquery.c:814 #: src/distroquery.c:833
msgid "Source files" msgid "Source files"
msgstr "" msgstr ""
#: src/distroquery.c:824 #: src/distroquery.c:843
msgid "Patches" msgid "Patches"
msgstr "" msgstr ""
#: src/distroquery.c:835 #: src/distroquery.c:854
msgid "Build requirements" msgid "Build requirements"
msgstr "" msgstr ""
#: src/distroquery.c:849 #: src/distroquery.c:868
msgid "Changelog" msgid "Changelog"
msgstr "" msgstr ""

BIN
po/it.gmo

Binary file not shown.

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: distromatic 1.4.1\n" "Project-Id-Version: distromatic 1.4.1\n"
"Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n" "Report-Msgid-Bugs-To: silvan.calarco@mambasoft.it\n"
"POT-Creation-Date: 2013-10-15 00:07+0200\n" "POT-Creation-Date: 2013-10-15 11:33+0200\n"
"PO-Revision-Date: 2013-10-14 01:19+0200\n" "PO-Revision-Date: 2013-10-14 01:19+0200\n"
"Last-Translator: Silvan Calarco <silvan.calarco@mambasoft.it>\n" "Last-Translator: Silvan Calarco <silvan.calarco@mambasoft.it>\n"
"Language-Team: Italian\n" "Language-Team: Italian\n"
@ -17,120 +17,128 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: src/distroquery.c:181 #: src/distroquery.c:182
msgid "Source" msgid "Source"
msgstr "Sorgente" msgstr "Sorgente"
#: src/distroquery.c:225 #: src/distroquery.c:227
msgid "Search" msgid "Search"
msgstr "Cerca" msgstr "Cerca"
#: src/distroquery.c:259 #: src/distroquery.c:261
msgid "sources" msgid "sources"
msgstr "sorgenti" msgstr "sorgenti"
#: src/distroquery.c:270 #: src/distroquery.c:265
msgid "files"
msgstr "file"
#: src/distroquery.c:276
msgid "Search software packages" msgid "Search software packages"
msgstr "Cerca pacchetti software" msgstr "Cerca pacchetti software"
#: src/distroquery.c:374 src/distroquery.c:639 src/distroquery.c:807 #: src/distroquery.c:380 src/distroquery.c:658 src/distroquery.c:826
msgid "Download" msgid "Download"
msgstr "Scarica" msgstr "Scarica"
#: src/distroquery.c:383 #: src/distroquery.c:389
msgid "Details" msgid "Details"
msgstr "Dettagli" msgstr "Dettagli"
#: src/distroquery.c:401 src/distroquery.c:436 #: src/distroquery.c:407 src/distroquery.c:443
#, c-format #, c-format
msgid "Other results in " msgid "Other results in "
msgstr "Altri risultati in " msgstr "Altri risultati in "
#: src/distroquery.c:402 src/distroquery.c:437 #: src/distroquery.c:408 src/distroquery.c:444
#, c-format #, c-format
msgid "Results in" msgid "Results in"
msgstr "Risultati in" msgstr "Risultati in"
#: src/distroquery.c:405 src/distroquery.c:440 #: src/distroquery.c:411 src/distroquery.c:447
msgid "for arch " msgid "for arch "
msgstr "per l'architettura " msgstr "per l'architettura "
#: src/distroquery.c:414 #: src/distroquery.c:420
msgid "provides" msgid "provides"
msgstr "fornisce" msgstr "fornisce"
#: src/distroquery.c:449 #: src/distroquery.c:456
msgid "provides file " msgid "provides file "
msgstr "fornisce il file " msgstr "fornisce il file "
#: src/distroquery.c:516 #: src/distroquery.c:529
msgid "result(s) shown" msgid "result(s) shown"
msgstr "risultati mostrati" msgstr "risultati mostrati"
#: src/distroquery.c:534 #: src/distroquery.c:531
msgid "result(s) found"
msgstr "risultati trovati"
#: src/distroquery.c:553
msgid "Search results for" msgid "Search results for"
msgstr "Risultati della ricerca per" msgstr "Risultati della ricerca per"
#: src/distroquery.c:604 src/distroquery.c:769 #: src/distroquery.c:623 src/distroquery.c:788
msgid "Version" msgid "Version"
msgstr "Versione" msgstr "Versione"
#: src/distroquery.c:609 #: src/distroquery.c:628
msgid "Size" msgid "Size"
msgstr "Dimensione" msgstr "Dimensione"
#: src/distroquery.c:612 #: src/distroquery.c:631
msgid "Related packages" msgid "Related packages"
msgstr "Pacchetti collegati" msgstr "Pacchetti collegati"
#: src/distroquery.c:641 src/distroquery.c:809 #: src/distroquery.c:660 src/distroquery.c:828
msgid "Developers details" msgid "Developers details"
msgstr "Dettagli per gli sviluppatori" msgstr "Dettagli per gli sviluppatori"
#: src/distroquery.c:643 #: src/distroquery.c:662
msgid "Source package" msgid "Source package"
msgstr "Pacchetto sorgente" msgstr "Pacchetto sorgente"
#: src/distroquery.c:649 src/distroquery.c:810 #: src/distroquery.c:668 src/distroquery.c:829
msgid "Maintainer" msgid "Maintainer"
msgstr "Manutentore" msgstr "Manutentore"
#: src/distroquery.c:650 src/distroquery.c:811 #: src/distroquery.c:669 src/distroquery.c:830
msgid "Build date" msgid "Build date"
msgstr "Data di compilazione" msgstr "Data di compilazione"
#: src/distroquery.c:653 #: src/distroquery.c:672
msgid "Obsoletes" msgid "Obsoletes"
msgstr "Rende obsoleti" msgstr "Rende obsoleti"
#: src/distroquery.c:667 #: src/distroquery.c:686
msgid "Provides" msgid "Provides"
msgstr "Fornisce" msgstr "Fornisce"
#: src/distroquery.c:682 #: src/distroquery.c:701
msgid "Requires" msgid "Requires"
msgstr "Richiede" msgstr "Richiede"
#: src/distroquery.c:701 #: src/distroquery.c:720
msgid "Files list" msgid "Files list"
msgstr "Lista dei file" msgstr "Lista dei file"
#: src/distroquery.c:776 #: src/distroquery.c:795
msgid "Built packages" msgid "Built packages"
msgstr "Pacchetti compilati" msgstr "Pacchetti compilati"
#: src/distroquery.c:814 #: src/distroquery.c:833
msgid "Source files" msgid "Source files"
msgstr "File sorgenti" msgstr "File sorgenti"
#: src/distroquery.c:824 #: src/distroquery.c:843
msgid "Patches" msgid "Patches"
msgstr "Patch" msgstr "Patch"
#: src/distroquery.c:835 #: src/distroquery.c:854
msgid "Build requirements" msgid "Build requirements"
msgstr "Requisiti per la compilazione" msgstr "Requisiti per la compilazione"
#: src/distroquery.c:849 #: src/distroquery.c:868
msgid "Changelog" msgid "Changelog"
msgstr "Modifiche" msgstr "Modifiche"

View File

@ -76,7 +76,7 @@
#include "functions.h" #include "functions.h"
// must be as big as ARCHS_MAX (5) // must be as big as ARCHS_MAX (5)
const char* ARCHS[ARCHS_MAX] = { "i586" , "x86_64" , "arm" , "", ""}; const char* ARCHS[ARCHS_MAX] = { "i586", "x86_64", "arm", "", "" };
static struct configTag *firstconfigtag = NULL, *configtag = NULL; static struct configTag *firstconfigtag = NULL, *configtag = NULL;
char *query = ""; char *query = "";
@ -93,6 +93,7 @@ struct configTag *query_repositories[100];
int search_milestone1 = 0, search_milestone2 = 1, search_devel = 1; int search_milestone1 = 0, search_milestone2 = 1, search_devel = 1;
int search_sources = 0, searchbox = 0; int search_sources = 0, searchbox = 0;
int search_files = 0;
/* Converts a hex character to its integer value */ /* Converts a hex character to its integer value */
char from_hex(char ch) { char from_hex(char ch) {
@ -217,7 +218,8 @@ void printInputForm() {
"'&search_i586='+getElementById('search_i586').checked+" "'&search_i586='+getElementById('search_i586').checked+"
"'&search_x86_64='+getElementById('search_x86_64').checked+" "'&search_x86_64='+getElementById('search_x86_64').checked+"
"'&search_arm='+getElementById('search_arm').checked+" "'&search_arm='+getElementById('search_arm').checked+"
"'&search_sources='+getElementById('search_sources').checked" "'&search_sources='+getElementById('search_sources').checked+"
"'&search_files='+getElementById('search_files').checked"
")"; ")";
printf("<queryform><![CDATA["); printf("<queryform><![CDATA[");
@ -258,6 +260,10 @@ void printInputForm() {
if (search_sources) printf("checked=checked "); if (search_sources) printf("checked=checked ");
printf("onclick=%s>%s&nbsp;", ajax_call, _("sources")); printf("onclick=%s>%s&nbsp;", ajax_call, _("sources"));
printf("<input type=checkbox id=\"search_files\" ");
if (search_files) printf("checked=checked ");
printf("onclick=%s>%s&nbsp;", ajax_call, _("files"));
printf("<br>"); printf("<br>");
/* ct = firstconfigtag; /* ct = firstconfigtag;
while (ct) { while (ct) {
@ -273,7 +279,7 @@ void printInputForm() {
void printQueryData() { void printQueryData() {
int a, i, j, k, numresults = 0, localresults, localprovidesresults; int a, i, j, k, numresults = 0, otherresults = 0, localresults, localprovidesresults, localsourceresults;
char dbname[PATH_MAX]; char dbname[PATH_MAX];
sqlite3 *dbf; sqlite3 *dbf;
sqlite3_stmt *statement, *stmt1; sqlite3_stmt *statement, *stmt1;
@ -417,49 +423,52 @@ void printQueryData() {
} }
/* files search */ /* files search */
snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", if (search_files) {
query_repositories[i]->repository_dir, snprintf(dbname, PATH_MAX, "%s%s-%s-files.db",
query_repositories[i]->tag, query_repositories[i]->repository_dir,
query_repositories[i]->arch[a]); query_repositories[i]->tag,
if (!sqlite3_open_v2(dbname, &dbf, SQLITE_OPEN_READONLY, NULL)) { query_repositories[i]->arch[a]);
snprintf(sql, PATH_MAX, "SELECT * FROM files,packages_files_rel " 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 " "WHERE files.name LIKE '%%%s%%' AND "
"packages_files_rel.id_file = files.id " "packages_files_rel.id_file = files.id "
"ORDER BY files.name = '%s' DESC, files.name LIKE '%s%%' DESC, " "ORDER BY files.name = '%s' DESC, files.name LIKE '%s%%' DESC, "
"files.name LIKE '%%%s%%' DESC LIMIT %d OFFSET %d", "files.name LIKE '%%%s%%' DESC LIMIT %d OFFSET %d",
queryenc, queryenc, queryenc, queryenc, query_limit, query_offset); queryenc, queryenc, queryenc, queryenc, query_limit, query_offset);
if (sqlite3_prepare_v2(dbf, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2(dbf, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
numresults++; numresults++;
if (++localprovidesresults == 1) { if (++localprovidesresults == 1) {
printf("<div style='position:relative'><hr><b>"); printf("<div style='position:relative'><hr><b>");
if (localresults > 0) printf(_("Other results in ")); if (localresults > 0) printf(_("Other results in "));
else printf(_("Results in")); else printf(_("Results in"));
printf(" %s %s %s:</b><br>", printf(" %s %s %s:</b><br>",
query_repositories[i]->tag, query_repositories[i]->tag,
_("for arch "), _("for arch "),
query_repositories[i]->arch[a]); 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));
} }
printf("<a href='javascript:distroquery_request(" sqlite3_finalize(stmt1);
"\"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);
} }
sqlite3_close(dbf);
} }
if (localprovidesresults > 0) printf("</div>"); if (localprovidesresults > 0) printf("</div>");
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
} if ((localresults >= query_limit) || (localprovidesresults >= query_limit)) otherresults = 1;
} } /* if query_repository */
} } /* archs loop */
} /* repositories loop */
if (search_sources) { if (search_sources) {
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
@ -477,8 +486,10 @@ void printQueryData() {
} }
if (query_repositories[i]->db[ARCHS_MAX] && if (query_repositories[i]->db[ARCHS_MAX] &&
(sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
localsourceresults = 0;
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(statement) == SQLITE_ROW) {
numresults++; numresults++;
localsourceresults++;
get_favicon_from_url(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")),buffer,PATH_MAX); get_favicon_from_url(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")),buffer,PATH_MAX);
@ -508,25 +519,33 @@ void printQueryData() {
} else { } else {
fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql); fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql);
} }
} if (localsourceresults >= query_limit) otherresults = 1;
} } /* repositories loop */
} /* search_sources */
printf("<hr>"); printf("<hr>");
printf("]]></queryreply>"); printf("]]></queryreply>");
printf("<querystatus><![CDATA[%d %s.&nbsp;", numresults, _("result(s) shown")); if (otherresults)
printf("<querystatus><![CDATA[%d %s.", numresults, _("result(s) shown"));
else
printf("<querystatus><![CDATA[%d %s.", numresults, _("result(s) found"));
k = query_offset / query_limit + 1; /* k = current shown page */ 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 (k < 7) j=1; else j=k-5; /* j = start pages list from */
if (numresults < query_limit) { if (!otherresults) {
/* current page is last available */ /* current page is last available */
a=k; a=k;
j=a-10; j=a-10;
if (j <= 0) j=1; if (j <= 0) j=1;
} else a=j+9; /* a = number of page links displayed */ } else a=j+9; /* a = number of page links displayed */
for (i = j; i <= a; i++) { if (a > 1) {
if (i != k) printf("<a href='javascript:distroquery_request(\"%s&limit=%d&offset=%d\")'>", printf("&nbsp;[&nbsp;");
query_next, query_limit, query_limit * (i-1)); for (i = j; i <= a; i++) {
printf("%d", i); if (i != k) printf("<a href='javascript:distroquery_request(\"%s&limit=%d&offset=%d\")'>",
printf("</a>&nbsp"); query_next, query_limit, query_limit * (i-1));
printf("%d", i);
printf("</a>&nbsp");
}
printf("]");
} }
printf("]]></querystatus>"); printf("]]></querystatus>");
@ -920,11 +939,15 @@ void parse_request_variables(char *data) {
query_archs[2] = strstr(valuetok, "false") != valuetok; query_archs[2] = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "search_sources")) { } else if (!strcmp(vartok, "search_sources")) {
search_sources = strstr(valuetok, "false") != valuetok; search_sources = strstr(valuetok, "false") != valuetok;
} else if (!strcmp(vartok, "search_files")) {
search_files = strstr(valuetok, "false") != valuetok;
}
if (vartok && valuetok) {
strcat(query_next, vartok);
strcat(query_next, "=");
strcat(query_next, valuetok);
strcat(query_next, "&");
} }
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'; if (query_next[strlen(query_next)] == '&') query_next[strlen(query_next)] = '\0';