From: Klaus Kaempf Date: Tue, 12 Aug 2008 12:20:42 +0000 (+0000) Subject: adapt repo_products (/etc/products.d/*.prod parsing) to current definition X-Git-Tag: BASE-SuSE-Code-12_1-Branch~581 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52e01fb8fae0ec3df5c2a8649179973647e3f67f;p=platform%2Fupstream%2Flibsolv.git adapt repo_products (/etc/products.d/*.prod parsing) to current definition fix repodata handling in repo_products move repodata handling to main() --- diff --git a/tools/repo_products.c b/tools/repo_products.c index 42375f1..e2e69c9 100644 --- a/tools/repo_products.c +++ b/tools/repo_products.c @@ -29,6 +29,7 @@ struct parsedata { Repo *repo; char *tmp; int tmpl; + Id langcache[ID_NUM_INTERNAL]; }; @@ -73,6 +74,10 @@ join(struct parsedata *pd, const char *s1, const char *s2, const char *s3) } +/* + * create epoch:version-release as Id + */ + static Id makeevr(Pool *pool, char *s) { @@ -82,10 +87,32 @@ makeevr(Pool *pool, char *s) } +/* + * create localized tag + */ + +static Id +langtag(struct parsedata *pd, Id tag, const char *language) +{ + if (language && !language[0]) + language = 0; + if (!language || tag >= ID_NUM_INTERNAL) + return pool_id2langid(pd->repo->pool, tag, language, 1); + return pool_id2langid(pd->repo->pool, tag, language, 1); + if (!pd->langcache[tag]) + pd->langcache[tag] = pool_id2langid(pd->repo->pool, tag, language, 1); + return pd->langcache[tag]; +} + + + + enum sections { SECTION_UNKNOWN, - SECTION_PRODUCT + SECTION_PRODUCT, + SECTION_TRANSLATED, + SECTION_UPDATE }; @@ -95,7 +122,7 @@ enum sections */ static void -repo_add_product(struct parsedata *pd, FILE *fp) +repo_add_product(struct parsedata *pd, Repodata *data, FILE *fp) { Repo *repo = pd->repo; Pool *pool = repo->pool; @@ -103,15 +130,8 @@ repo_add_product(struct parsedata *pd, FILE *fp) int aline; Solvable *s = 0; Id handle = 0; - Repodata *data; enum sections current_section = SECTION_UNKNOWN; - - if (repo->nrepodata) - /* use last repodata */ - data = repo->repodata + repo->nrepodata - 1; - else - data = repo_add_repodata(repo, 0); line = sat_malloc(1024); aline = 1024; @@ -162,6 +182,10 @@ repo_add_product(struct parsedata *pd, FILE *fp) *endp = 0; if (!strcmp(secp, "product")) current_section = SECTION_PRODUCT; + else if (!strcmp(secp, "translated")) + current_section = SECTION_TRANSLATED; + else if (!strcmp(secp, "update")) + current_section = SECTION_UPDATE; else { fprintf(stderr, "Skipping unknown section '%s'\n", secp); @@ -172,14 +196,24 @@ repo_add_product(struct parsedata *pd, FILE *fp) else if (current_section != SECTION_UNKNOWN) { char *ptr = linep; - char *key, *value; + char *key, *value, *lang; - /* split line into ' = ' */ + lang = 0; + + /* split line into '[] = ' */ while (*ptr && (*ptr == ' ' || *ptr == '\t')) ++ptr; key = ptr; - while (*ptr && !(*ptr == ' ' || *ptr == '\t' || *ptr == '=')) + while (*ptr && !(*ptr == ' ' || *ptr == '\t' || *ptr == '=' || *ptr == '[')) ++ptr; + if (*ptr == '[') + { + *ptr++ = 0; + lang = ptr; + while (*ptr && !(*ptr == ']')) + ++ptr; + *ptr++ = 0; + } if (*ptr != '=') *ptr++ = 0; while (*ptr && !(*ptr == '=')) @@ -189,10 +223,11 @@ repo_add_product(struct parsedata *pd, FILE *fp) while (*ptr && (*ptr == ' ' || *ptr == '\t')) ++ptr; value = ptr; - while (*ptr && !(*ptr == ' ' || *ptr == '\t')) - ++ptr; - *ptr++ = 0; + /* + * [product] + */ + if (current_section == SECTION_PRODUCT) { if (!s) @@ -205,9 +240,31 @@ repo_add_product(struct parsedata *pd, FILE *fp) s->name = str2id(pool, join(pd, "product", ":", value), 1); else if (!strcmp(key, "version")) s->evr = makeevr(pool, value); + else if (!strcmp(key, "vendor")) + s->vendor = str2id(pool, value, 1); + else if (!strcmp(key, "distribution")) + repo_set_str(repo, s - pool->solvables, SOLVABLE_DISTRIBUTION, value); else if (!strcmp (key, "flavor")) repo_set_str(repo, s - pool->solvables, PRODUCT_FLAVOR, value); } + /* + * [translated] + */ + else if (current_section == SECTION_TRANSLATED) + { + if (!strcmp(key, "summary")) + { + repodata_set_str(data, handle, langtag(pd, SOLVABLE_SUMMARY, lang), value ); + } + else if (!strcmp(key, "description")) + repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, lang), value ); + } + /* + * [update] + */ + else if (current_section == SECTION_UPDATE) + { + } } else fprintf (stderr, "malformed line: %s\n", line); @@ -236,7 +293,7 @@ repo_add_product(struct parsedata *pd, FILE *fp) */ void -repo_add_products(Repo *repo, const char *proddir) +repo_add_products(Repo *repo, Repodata *repodata, const char *proddir) { DIR *dir = opendir(proddir); struct dirent *entry; @@ -264,7 +321,7 @@ repo_add_products(Repo *repo, const char *proddir) perror(fullpath); break; } - repo_add_product(&pd, fp); + repo_add_product(&pd, repodata, fp); fclose(fp); } } diff --git a/tools/repo_products.h b/tools/repo_products.h index 8b607ae..2c2114b 100644 --- a/tools/repo_products.h +++ b/tools/repo_products.h @@ -5,4 +5,4 @@ * for further information */ -void repo_add_products(Repo *repo, const char *proddir); +void repo_add_products(Repo *repo, Repodata *repodata, const char *proddir); diff --git a/tools/repo_rpmdb.c b/tools/repo_rpmdb.c index c974a65..bbc15cb 100644 --- a/tools/repo_rpmdb.c +++ b/tools/repo_rpmdb.c @@ -1184,7 +1184,7 @@ mkrpmdbcookie(struct stat *st, unsigned char *cookie) */ void -repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) +repo_add_rpmdb(Repo *repo, Repodata *repodata, Repo *ref, const char *rootdir) { Pool *pool = repo->pool; unsigned char buf[16]; @@ -1202,7 +1202,6 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) Id id, *refhash; unsigned int refmask, h; int asolv; - Repodata *repodata; char dbpath[PATH_MAX]; DB_ENV *dbenv = 0; DBT dbkey; @@ -1218,8 +1217,6 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) if (!rootdir) rootdir = ""; - repodata = repo_add_repodata(repo, 0); - if (ref && !(ref->nsolvables && ref->rpmdbid)) ref = 0; @@ -1531,16 +1528,16 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) if (db) db->close(db, 0); dbenv->close(dbenv, 0); - if (repodata) - repodata_internalize(repodata); } + static inline unsigned int getu32(unsigned char *dp) { return dp[0] << 24 | dp[1] << 16 | dp[2] << 8 | dp[3]; } + static void add_location(Repodata *data, Solvable *s, Id handle, const char *location) { @@ -1600,12 +1597,11 @@ nontrivial: } void -repo_add_rpms(Repo *repo, const char **rpms, int nrpms) +repo_add_rpms(Repo *repo, Repodata *repodata, const char **rpms, int nrpms) { int i, sigdsize, sigcnt, l; Pool *pool = repo->pool; Solvable *s; - Repodata *repodata; RpmHead *rpmhead = 0; int rpmheadsize = 0; char *payloadformat; @@ -1616,7 +1612,7 @@ repo_add_rpms(Repo *repo, const char **rpms, int nrpms) if (nrpms <= 0) return; - repodata = repo_add_repodata(repo, 0); + for (i = 0; i < nrpms; i++) { if ((fp = fopen(rpms[i], "r")) == 0) @@ -1729,6 +1725,4 @@ repo_add_rpms(Repo *repo, const char **rpms, int nrpms) } if (rpmhead) sat_free(rpmhead); - if (repodata) - repodata_internalize(repodata); } diff --git a/tools/repo_rpmdb.h b/tools/repo_rpmdb.h index 42e31c0..7eab539 100644 --- a/tools/repo_rpmdb.h +++ b/tools/repo_rpmdb.h @@ -5,5 +5,5 @@ * for further information */ -extern void repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir); -extern void repo_add_rpms(Repo *repo, const char **rpms, int nrpms); +extern void repo_add_rpmdb(Repo *repo, Repodata *repodata, Repo *ref, const char *rootdir); +extern void repo_add_rpms(Repo *repo, Repodata *repodata, const char **rpms, int nrpms); diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index 8209ae1..1e015ef 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -33,10 +33,12 @@ main(int argc, char **argv) { Pool *pool = pool_create(); Repo *repo, *ref = 0; + Repodata *repodata; FILE *fp; Pool *refpool; int c; int extrapool = 0; + int nopacks = 0; const char *root = 0; const char *basefile = 0; const char *proddir = 0; @@ -45,7 +47,7 @@ main(int argc, char **argv) * parse arguments */ - while ((c = getopt (argc, argv, "xb:r:p:")) >= 0) + while ((c = getopt (argc, argv, "nxb:r:p:")) >= 0) switch (c) { case 'r': @@ -54,6 +56,9 @@ main(int argc, char **argv) case 'b': basefile = optarg; break; + case 'n': + nopacks = 1; + break; case 'p': proddir = optarg; break; @@ -93,13 +98,17 @@ main(int argc, char **argv) */ repo = repo_create(pool, "installed"); + repodata = repo_add_repodata(repo, 0); - repo_add_rpmdb(repo, ref, root); + if (!nopacks) + repo_add_rpmdb(repo, repodata, ref, root); if (proddir) - { - repo_add_products(repo, proddir); - } + repo_add_products(repo, repodata, proddir); + + if (repodata) + repodata_internalize(repodata); + if (ref) { if (ref->pool != pool) diff --git a/tools/rpms2solv.c b/tools/rpms2solv.c index 1aa59b0..0965e71 100644 --- a/tools/rpms2solv.c +++ b/tools/rpms2solv.c @@ -31,6 +31,7 @@ main(int argc, char **argv) int c, nrpms = 0; Pool *pool = pool_create(); Repo *repo; + Repodata *repodata; FILE *fp; char buf[4096], *p; const char *basefile = 0; @@ -74,8 +75,11 @@ main(int argc, char **argv) rpms[nrpms++] = strdup(argv[optind++]); } repo = repo_create(pool, "rpms2solv"); - repo_add_rpms(repo, rpms, nrpms); + repodata = repo_add_repodata(repo, 0); + repo_add_rpms(repo, repodata, rpms, nrpms); tool_write(repo, basefile, 0); + if (repodata) + repodata_internalize(repodata); pool_free(pool); for (c = 0; c < nrpms; c++) free((char *)rpms[c]);