Author: mlschroe
Date: Mon Mar 3 18:11:40 2008
New Revision: 8987
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8987&view=rev
Log:
- add '-d' option to susetags2solv, reads all packages files
- add '-b' option to susetags2solv and rpmdb2solv
- both options currently a bit experimental
Modified:
trunk/sat-solver/tools/CMakeLists.txt
trunk/sat-solver/tools/common_write.c
trunk/sat-solver/tools/repo_susetags.c
trunk/sat-solver/tools/repo_susetags.h
trunk/sat-solver/tools/rpmdb2solv.c
trunk/sat-solver/tools/susetags2solv.c
Modified: trunk/sat-solver/tools/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/CMakeLists.txt?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/CMakeLists.txt (original)
+++ trunk/sat-solver/tools/CMakeLists.txt Mon Mar 3 18:11:40 2008
@@ -24,7 +24,7 @@
SET(susetags2solv_REPOS susetags2solv.c repo_susetags.h repo_susetags.c repo_content.c repo_write.c common_write.c)
ADD_EXECUTABLE( susetags2solv ${susetags2solv_REPOS} )
-TARGET_LINK_LIBRARIES( susetags2solv satsolver)
+TARGET_LINK_LIBRARIES( susetags2solv satsolver ${ZLIB_LIBRARY})
SET(patchxml2solv_REPOS patchxml2solv.c repo_patchxml.h repo_patchxml.c repo_write.c common_write.c)
ADD_EXECUTABLE( patchxml2solv ${patchxml2solv_REPOS} )
Modified: trunk/sat-solver/tools/common_write.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/common_write.c?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/common_write.c (original)
+++ trunk/sat-solver/tools/common_write.c Mon Mar 3 18:11:40 2008
@@ -17,94 +17,254 @@
#include "repo_write.h"
#include "common_write.h"
-static char *verticals[] = {
- "authors",
- "description",
- "messagedel",
- "messageins",
- "eula",
- "diskusage",
- "filelist",
+static Id verticals[] = {
+ SOLVABLE_AUTHORS,
+ SOLVABLE_DESCRIPTION,
+ SOLVABLE_MESSAGEDEL,
+ SOLVABLE_MESSAGEINS,
+ SOLVABLE_EULA,
+ SOLVABLE_DISKUSAGE,
+ SOLVABLE_FILELIST,
0
};
-static unsigned char *filter;
-static int nfilter;
-
-static void
-create_filter(Pool *pool)
-{
- char **s;
- Id id;
- for (s = verticals; *s; s++)
- {
- id = str2id(pool, *s, 1);
- if (id >= nfilter)
- {
- filter = sat_realloc(filter, id + 16);
- memset(filter + nfilter, 0, id + 16 - nfilter);
- nfilter = id + 16;
- }
- filter[id] = 1;
- }
-}
+static char *languagetags[] = {
+ "solvable:summary:",
+ "solvable:description:",
+ "solvable:messageins:",
+ "solvable:messagedel:",
+ 0
+};
static int test_separate = 0;
static int
keyfilter_solv(Repo *data, Repokey *key, void *kfdata)
{
+ int i;
if (test_separate && key->storage != KEY_STORAGE_SOLVABLE)
return KEY_STORAGE_DROPPED;
- if (key->name < nfilter && filter[key->name])
- return KEY_STORAGE_VERTICAL_OFFSET;
+ for (i = 0; verticals[i]; i++)
+ if (key->name == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
return KEY_STORAGE_INCORE;
}
static int
keyfilter_attr(Repo *data, Repokey *key, void *kfdata)
{
+ int i;
if (key->storage == KEY_STORAGE_SOLVABLE)
return KEY_STORAGE_DROPPED;
- if (key->name < nfilter && filter[key->name])
- return KEY_STORAGE_VERTICAL_OFFSET;
+ for (i = 0; verticals[i]; i++)
+ if (key->name == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
+ return KEY_STORAGE_INCORE;
+}
+
+static int
+keyfilter_language(Repo *repo, Repokey *key, void *kfdata)
+{
+ const char *name, *p;
+ char *lang = kfdata, *bname;
+ int i;
+ Id id;
+
+ name = id2str(repo->pool, key->name);
+ p = strrchr(name, ':');
+ if (!p || strcmp(p + 1, lang) != 0)
+ return KEY_STORAGE_DROPPED;
+ /* find base name id */
+ bname = strdup(name);
+ bname[p - name] = 0;
+ id = str2id(repo->pool, bname, 1);
+ for (i = 0; verticals[i]; i++)
+ if (id == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
+ return KEY_STORAGE_INCORE;
+}
+
+static int
+keyfilter_DU(Repo *repo, Repokey *key, void *kfdata)
+{
+ int i;
+ if (key->name != SOLVABLE_DISKUSAGE)
+ return KEY_STORAGE_DROPPED;
+ for (i = 0; verticals[i]; i++)
+ if (key->name == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
+ return KEY_STORAGE_INCORE;
+}
+
+static int
+keyfilter_FL(Repo *repo, Repokey *key, void *kfdata)
+{
+ int i;
+ if (key->name != SOLVABLE_FILELIST)
+ return KEY_STORAGE_DROPPED;
+ for (i = 0; verticals[i]; i++)
+ if (key->name == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
+ return KEY_STORAGE_INCORE;
+}
+
+struct keyfilter_other_data {
+ char **languages;
+ int nlanguages;
+};
+
+static int
+keyfilter_other(Repo *repo, Repokey *key, void *kfdata)
+{
+ const char *name, *p;
+ struct keyfilter_other_data *kd = kfdata;
+ int i;
+
+ if (key->name == SOLVABLE_FILELIST || key->name == SOLVABLE_DISKUSAGE)
+ return KEY_STORAGE_DROPPED;
+ name = id2str(repo->pool, key->name);
+ p = strrchr(name, ':');
+ if (p)
+ {
+ for (i = 0; i < kd->nlanguages; i++)
+ if (!strcmp(p + 1, kd->languages[i]))
+ return KEY_STORAGE_DROPPED;
+ }
+ for (i = 0; verticals[i]; i++)
+ if (key->name == verticals[i])
+ return KEY_STORAGE_VERTICAL_OFFSET;
return KEY_STORAGE_INCORE;
}
/*
* Write <repo> to stdout
* If <attrname> is given, write attributes to <attrname>
+ * If <basename> is given, split attributes
*/
int
tool_write(Repo *repo, const char *basename, const char *attrname)
{
- Pool *pool = repo->pool;
- Repodatafile fileinfoa[1];
- Repodatafile *fileinfo = 0;
- int nsubfiles = 0;
+ Repodata *data;
+ Repokey *key;
+ Repodatafile *fileinfos = 0;
+ int nfileinfos = 0;
+ char **languages = 0;
+ int nlanguages = 0;
+ int i, j, k, l;
+
+ if (basename)
+ {
+ struct keyfilter_other_data kd;
+ char fn[4096];
+ FILE *fp;
+ int has_DU = 0;
+ int has_FL = 0;
- create_filter(pool);
- memset (fileinfoa, 0, sizeof fileinfoa);
+ /* find languages and other info */
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+ {
+ for (j = 1, key = data->keys + j; j < data->nkeys; j++, key++)
+ {
+ const char *keyname = id2str(repo->pool, key->name);
+ if (key->name == SOLVABLE_DISKUSAGE)
+ has_DU = 1;
+ if (key->name == SOLVABLE_FILELIST)
+ has_FL = 1;
+ for (k = 0; languagetags[k] != 0; k++)
+ if (!strncmp(keyname, languagetags[k], strlen(languagetags[k])))
+ break;
+ if (!languagetags[k])
+ continue;
+ l = strlen(languagetags[k]);
+ if (strlen(keyname + l) > 5)
+ continue;
+ for (k = 0; k < nlanguages; k++)
+ if (!strcmp(languages[k], keyname + l))
+ break;
+ if (k < nlanguages)
+ continue;
+ languages = sat_realloc2(languages, nlanguages + 1, sizeof(char *));
+ languages[nlanguages++] = strdup(keyname + l);
+ }
+ }
+ fileinfos = sat_calloc(nlanguages + 2, sizeof(Repodatafile));
+ /* write language subfiles */
+ for (i = 0; i < nlanguages; i++)
+ {
+ sprintf(fn, "%s.%s.solv", basename, languages[i]);
+ if (!(fp = fopen(fn, "w")))
+ {
+ perror(fn);
+ exit(1);
+ }
+ repo_write(repo, fp, keyfilter_language, languages[i], fileinfos + nfileinfos, 0);
+ fileinfos[nfileinfos++].location = strdup(fn);
+ fclose(fp);
+ }
+ /* write DU subfile */
+ if (has_DU)
+ {
+ sprintf(fn, "%s.DU.solv", basename);
+ if (!(fp = fopen(fn, "w")))
+ {
+ perror(fn);
+ exit(1);
+ }
+ repo_write(repo, fp, keyfilter_DU, 0, fileinfos + nfileinfos, 0);
+ fileinfos[nfileinfos++].location = strdup(fn);
+ fclose(fp);
+ }
+ /* write filelist */
+ if (has_FL)
+ {
+ sprintf(fn, "%s.FL.solv", basename);
+ if (!(fp = fopen(fn, "w")))
+ {
+ perror(fn);
+ exit(1);
+ }
+ repo_write(repo, fp, keyfilter_FL, 0, fileinfos + nfileinfos, 0);
+ fileinfos[nfileinfos++].location = strdup(fn);
+ fclose(fp);
+ }
+ /* write everything else */
+ sprintf(fn, "%s.solv", basename);
+ if (!(fp = fopen(fn, "w")))
+ {
+ perror(fn);
+ exit(1);
+ }
+ kd.languages = languages;
+ kd.nlanguages = nlanguages;
+ repo_write(repo, fp, keyfilter_other, &kd, fileinfos, nfileinfos);
+ fclose(fp);
+ for (i = 0; i < nlanguages; i++)
+ free(languages[i]);
+ sat_free(languages);
+ for (i = 0; i < nfileinfos; i++)
+ {
+ sat_free(fileinfos[i].location);
+ sat_free(fileinfos[i].keys);
+ }
+ sat_free(fileinfos);
+ exit(0);
+ }
if (attrname)
{
+ fileinfos = sat_calloc(1, sizeof(Repodatafile));
test_separate = 1;
- fileinfo = fileinfoa;
FILE *fp = fopen (attrname, "w");
- repo_write(repo, fp, keyfilter_attr, 0, fileinfo, 0);
+ repo_write(repo, fp, keyfilter_attr, 0, fileinfos + nfileinfos++, 0);
+ fileinfos[nfileinfos - 1].location = strdup(attrname);
fclose(fp);
- fileinfo->location = strdup(attrname);
- fileinfo++;
-
- nsubfiles = fileinfo - fileinfoa;
- fileinfo = fileinfoa;
}
- repo_write(repo, stdout, keyfilter_solv, 0, fileinfo, nsubfiles);
- if (fileinfo)
+ repo_write(repo, stdout, keyfilter_solv, 0, fileinfos, nfileinfos);
+ if (fileinfos)
{
- free(fileinfo->location);
- free(fileinfo->keys);
+ free(fileinfos[0].location);
+ free(fileinfos[0].keys);
+ free(fileinfos);
}
- sat_free(filter);
return 0;
}
Modified: trunk/sat-solver/tools/repo_susetags.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_susetags.c?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/repo_susetags.c (original)
+++ trunk/sat-solver/tools/repo_susetags.c Mon Mar 3 18:11:40 2008
@@ -27,6 +27,7 @@
int nshare;
Id (*dirs)[3]; // dirid, size, nfiles
int ndirs;
+ Id langcache[ID_NUM_INTERNAL];
};
static char *flagtab[] = {
@@ -38,6 +39,26 @@
"<="
};
+
+static Id
+langtag(struct parsedata *pd, Id tag, const char *language)
+{
+ char *p;
+ const char *tagname;
+
+ if (!language || tag >= ID_NUM_INTERNAL)
+ return tag;
+ if (!pd->langcache[tag])
+ {
+ tagname = id2str(pd->repo->pool, tag);
+ p = sat_malloc(strlen(tagname) + strlen(language) + 2);
+ sprintf(p, "%s:%s", tagname, language);
+ pd->langcache[tag] = str2id(pd->repo->pool, p, 1);
+ sat_free(p);
+ }
+ return pd->langcache[tag];
+}
+
/*
* adddep
* create and add dependency
@@ -238,7 +259,7 @@
/* Now sort in dirid order. This ensures that parents come before
their children. */
if (pd->ndirs > 1)
- qsort (pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp);
+ qsort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp);
/* Substract leaf numbers from all parents to make the numbers
non-cumulative. This must be done post-order (i.e. all leafs
adjusted before parents). We ensure this by starting at the end of
@@ -334,7 +355,7 @@
*/
void
-repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int flags)
+repo_add_susetags(Repo *repo, FILE *fp, Id vendor, const char *language, int flags)
{
Pool *pool = repo->pool;
char *line, *linep;
@@ -348,7 +369,14 @@
struct parsedata pd;
Repodata *data = 0;
- data = repo_add_repodata(repo);
+ if ((flags & SUSETAGS_EXTEND) && repo->nrepodata)
+ {
+ /* use last repodata */
+ data = repo->repodata + repo->nrepodata - 1;
+ indesc = 1;
+ }
+ if (!data)
+ data = repo_add_repodata(repo);
memset(&pd, 0, sizeof(pd));
line = malloc(1024);
@@ -562,7 +590,7 @@
solvables. */
if (indesc >= 2 && !s)
{
- fprintf (stderr, "Huh?\n");
+ fprintf (stderr, "Huh %s?\n", line);
continue;
}
switch (tag)
@@ -686,19 +714,19 @@
repodata_set_str(data, last_found_pack, SOLVABLE_AUTHORS, line + 6);
continue;
case CTAG('=', 'S', 'u', 'm'):
- repodata_set_str(data, last_found_pack, SOLVABLE_SUMMARY, line + 6);
+ repodata_set_str(data, last_found_pack, langtag(&pd, SOLVABLE_SUMMARY, language), line + 6);
continue;
case CTAG('=', 'D', 'e', 's'):
- repodata_set_str(data, last_found_pack, SOLVABLE_DESCRIPTION, line + 6);
+ repodata_set_str(data, last_found_pack, langtag(&pd, SOLVABLE_DESCRIPTION, language), line + 6);
continue;
case CTAG('=', 'E', 'u', 'l'):
- repodata_set_str(data, last_found_pack, SOLVABLE_EULA, line + 6);
+ repodata_set_str(data, last_found_pack, langtag(&pd, SOLVABLE_EULA, language), line + 6);
continue;
case CTAG('=', 'I', 'n', 's'):
- repodata_set_str(data, last_found_pack, SOLVABLE_MESSAGEINS, line + 6);
+ repodata_set_str(data, last_found_pack, langtag(&pd, SOLVABLE_MESSAGEINS, language), line + 6);
continue;
case CTAG('=', 'D', 'e', 'l'):
- repodata_set_str(data, last_found_pack, SOLVABLE_MESSAGEDEL, line + 6);
+ repodata_set_str(data, last_found_pack, langtag(&pd, SOLVABLE_MESSAGEDEL, language), line + 6);
continue;
case CTAG('=', 'V', 'i', 's'):
{
@@ -792,3 +820,4 @@
free(pd.common.tmp);
free(line);
}
+
Modified: trunk/sat-solver/tools/repo_susetags.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_susetags.h?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/repo_susetags.h (original)
+++ trunk/sat-solver/tools/repo_susetags.h Mon Mar 3 18:11:40 2008
@@ -10,5 +10,6 @@
*/
#define SUSETAGS_KINDS_SEPARATELY 1
+#define SUSETAGS_EXTEND 2
-extern void repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int flags);
+extern void repo_add_susetags(Repo *repo, FILE *fp, Id vendor, const char *language, int flags);
Modified: trunk/sat-solver/tools/rpmdb2solv.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/rpmdb2solv.c?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/rpmdb2solv.c (original)
+++ trunk/sat-solver/tools/rpmdb2solv.c Mon Mar 3 18:11:40 2008
@@ -31,13 +31,19 @@
Repo *repo, *ref = 0;
FILE *fp;
Pool *refpool;
- int g;
+ int c;
const char *root = "/";
+ const char *basefile = 0;
- while ((g = getopt (argc, argv, "r:")) >= 0)
- switch (g)
+ while ((c = getopt (argc, argv, "b:r:")) >= 0)
+ switch (c)
{
- case 'r': root = optarg; break;
+ case 'r':
+ root = optarg;
+ break;
+ case 'b':
+ basefile = optarg;
+ break;
default:
exit(1);
}
@@ -66,7 +72,7 @@
ref = 0;
}
- tool_write(repo, 0, 0);
+ tool_write(repo, basefile, 0);
pool_free(pool);
exit(0);
Modified: trunk/sat-solver/tools/susetags2solv.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/susetags2solv.c?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- trunk/sat-solver/tools/susetags2solv.c (original)
+++ trunk/sat-solver/tools/susetags2solv.c Mon Mar 3 18:11:40 2008
@@ -5,12 +5,16 @@
* for further information
*/
+#define _GNU_SOURCE
+
#include