Skip to content

Commit

Permalink
Merge pull request #30 from j-mracek/archfilter
Browse files Browse the repository at this point in the history
Refactor arch_filter() to return including data if arch unset
  • Loading branch information
midnightercz authored Sep 22, 2016
2 parents d86995b + eb4efc4 commit f46fe76
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 49 deletions.
9 changes: 3 additions & 6 deletions libcomps/src/comps_doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) {
list = comps_doc_categories(source);
for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) {
arches2 = comps_doccategory_arches((COMPS_DocCategory*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
cat = comps_doccategory_arch_filter((COMPS_DocCategory*)it->comps_obj,
arches);
comps_doc_add_category(ret, cat);
Expand All @@ -864,8 +863,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) {
list = comps_doc_groups(source);
for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) {
arches2 = comps_docgroup_arches((COMPS_DocGroup*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
group = comps_docgroup_arch_filter((COMPS_DocGroup*)it->comps_obj,
arches);
comps_doc_add_group(ret, group);
Expand All @@ -876,8 +874,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) {
list = comps_doc_environments(source);
for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) {
arches2 = comps_docenv_arches((COMPS_DocEnv*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
env = comps_docenv_arch_filter((COMPS_DocEnv*)it->comps_obj,
arches);
comps_doc_add_environment(ret, env);
Expand Down
3 changes: 1 addition & 2 deletions libcomps/src/comps_doccategory.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ COMPS_DocCategory* comps_doccategory_arch_filter(COMPS_DocCategory *source,
for (COMPS_ObjListIt *it = source->group_ids->first;
it != NULL; it = it->next) {
arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
comps_doccategory_add_groupid(ret, (COMPS_DocGroupId*)
comps_object_copy(it->comps_obj));
}
Expand Down
6 changes: 2 additions & 4 deletions libcomps/src/comps_docenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ COMPS_DocEnv* comps_docenv_arch_filter(COMPS_DocEnv *source,
for (COMPS_ObjListIt *it = source->group_list->first;
it != NULL; it = it->next) {
arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
comps_docenv_add_groupid(ret, (COMPS_DocGroupId*)
comps_object_copy(it->comps_obj));
}
Expand All @@ -463,8 +462,7 @@ COMPS_DocEnv* comps_docenv_arch_filter(COMPS_DocEnv *source,
for (COMPS_ObjListIt *it = source->option_list->first;
it != NULL; it = it->next) {
arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj);
if (!arches2) continue;
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
comps_docenv_add_optionid(ret, (COMPS_DocGroupId*)
comps_object_copy(it->comps_obj));
}
Expand Down
2 changes: 1 addition & 1 deletion libcomps/src/comps_docgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ COMPS_DocGroup* comps_docgroup_arch_filter(COMPS_DocGroup *source,
for (COMPS_ObjListIt *it = source->packages->first;
it != NULL; it = it->next) {
arches2 = comps_docpackage_arches((COMPS_DocGroupPackage*)it->comps_obj);
if (__comps_objlist_intersected(arches, arches2)) {
if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) {
comps_docgroup_add_package(ret, (COMPS_DocGroupPackage*)
comps_object_copy(it->comps_obj));
}
Expand Down
4 changes: 2 additions & 2 deletions libcomps/src/comps_elem.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ COMPS_ObjList * __comps_split_arches(char *arches) {
COMPS_ObjList *list;
char *pch;
list = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL);
pch = strtok(arches, " ");
pch = strtok(arches, " ,");
while (pch != NULL) {
comps_objlist_append_x(list, (COMPS_Object*)comps_str(pch));
pch = strtok(NULL, " ");
pch = strtok(NULL, " ,");
}
return list;
}
Expand Down
21 changes: 15 additions & 6 deletions libcomps/src/python/tests/__test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,9 @@ def test_arches(self):
comps.fromxml_f("comps/main_arches.xml")
filtered = comps.arch_filter(["x86"])
g1_pkgs = ["pkg3", "pkg4", "pkg5", "pkg6", "pkg7"]
c1_gids = ["g1", "g3", "g4", "g6"]
e1_gids = ["g1", "g3", "g4"]
e1_oids = ["o1", "o3", "o4"]
c1_gids = ["g1", "g3", "g4", "g6", "g7"]
e1_gids = ["g1", "g3", "g4", "g6"]
e1_oids = ["o1", "o3", "o4", "o6"]
x = 0
for pkg in filtered.groups[0].packages:
self.assertTrue(g1_pkgs[x] == pkg.name)
Expand All @@ -1048,12 +1048,21 @@ def test_arches(self):
for oid in filtered.environments[0].option_ids:
self.assertTrue(e1_oids[x] == oid.name)
x +=1
empty_comps = libcomps.Comps()
test_comps = libcomps.Comps()
env1 = libcomps.Environment(id='env4', name='env4')
env1.option_ids.append("o5")
group1 = libcomps.Group(id='group4', name='group4')
group1.biarchonly = False
group_id = libcomps.GroupId(name='g1')
c1 = libcomps.Category(id='cat4', name='cat4')
c1.group_ids.append(group_id)
test_comps.environments.append(env1)
test_comps.groups.append(group1)
test_comps.categories.append(c1)
comps3 = comps.arch_filter(["unknown"])
self.assertTrue(empty_comps == comps3)
self.assertTrue(test_comps == comps3)

comps4 = comps.arch_filter(["x86", "x86_64", "s390"])
comps4.environments[2].option_ids.append("o5")
self.assertTrue(comps == comps4)

s = comps.toxml_str(xml_options = {"arch_output":True})
Expand Down
39 changes: 33 additions & 6 deletions libcomps/src/python/tests/comps/main_arches.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group arch="x86_64 x86 s390">
<group arch="x86_64,x86,s390">
<id>group1</id>
<name>group1</name>
<packagelist>
Expand All @@ -11,7 +11,7 @@
<packagereq arch="x86 s390">pkg4</packagereq>
<packagereq arch="x86_64 x86">pkg5</packagereq>
<packagereq arch="x86_64 x86">pkg6</packagereq>
<packagereq arch="x86_64 x86">pkg7</packagereq>
<packagereq>pkg7</packagereq>
</packagelist>
</group>
<group arch="x86_64">
Expand All @@ -28,7 +28,14 @@
<packagereq arch="x86_64 x86">pkg7</packagereq>
</packagelist>
</group>
<category arch="x86_64 x86 s390">
<group>
<id>group4</id>
<name>group4</name>
<packagelist>
<packagereq arch="x86_64 x86">pkg1</packagereq>
</packagelist>
</group>
<category arch="x86_64,x86 s390">
<id>cat1</id>
<name>cat1</name>
<grouplist>
Expand All @@ -38,6 +45,7 @@
<groupid arch="x86_64 x86 s390">g4</groupid>
<groupid arch="x86_64 s390">g5</groupid>
<groupid arch="x86 s390">g6</groupid>
<groupid>g7</groupid>
</grouplist>
</category>
<category arch="x86_64">
Expand All @@ -54,22 +62,31 @@
<groupid arch="x86_64 x86">g1</groupid>
</grouplist>
</category>
<environment arch="x86_64 x86 s390">
<category>
<id>cat4</id>
<name>cat4</name>
<grouplist>
<groupid>g1</groupid>
</grouplist>
</category>
<environment arch="x86_64,x86,s390">
<id>env1</id>
<name>env1</name>
<grouplist>
<groupid arch="x86_64 x86">g1</groupid>
<groupid arch="x86_64,x86">g1</groupid>
<groupid arch="x86_64 s390">g2</groupid>
<groupid arch="x86">g3</groupid>
<groupid arch="x86 s390">g4</groupid>
<groupid arch="x86_64">g5</groupid>
<groupid>g6</groupid>
</grouplist>
<optionlist>
<groupid arch="x86_64 x86 s390">o1</groupid>
<groupid arch="x86_64,x86 s390">o1</groupid>
<groupid arch="s390">o2</groupid>
<groupid arch="x86 x86_64">o3</groupid>
<groupid arch="x86 s390">o4</groupid>
<groupid arch="x86_64">o5</groupid>
<groupid>o6</groupid>
</optionlist>
</environment>
<environment arch="x86_64">
Expand All @@ -85,6 +102,16 @@
<environment arch="x86_64 s390">
<id>env3</id>
<name>env3</name>
<grouplist>
<groupid arch="x86_64 s390">g1</groupid>
</grouplist>
<optionlist>
<groupid arch="x86_64">o5</groupid>
</optionlist>
</environment>
<environment>
<id>env4</id>
<name>env4</name>
<grouplist>
<groupid arch="x86_64 s390">g1</groupid>
</grouplist>
Expand Down
32 changes: 16 additions & 16 deletions libcomps/tests/check_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,24 +529,24 @@ START_TEST(test_arch)
COMPS_Str *str;
int x;
COMPS_ObjListIt *it;
char *grps[3][4] = {{"group1", "group3", NULL, NULL},
{"group1", "group2", "group3", NULL},
{"group3", NULL, NULL, NULL}};
char *grps[3][5] = {{"group1", "group3", "group4", NULL, NULL},
{"group1", "group2", "group3", "group4", NULL},
{"group3", "group4", NULL, NULL, NULL}};
char *g1_pkgs[3][8] = {{"pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL, NULL, NULL},
{"pkg3", "pkg4", NULL, NULL, NULL, NULL, NULL, NULL},
{"pkg3", "pkg4", "pkg7", NULL, NULL, NULL, NULL, NULL},
{"pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7",
NULL}};

char *cats[3][4] = {{"cat1", NULL, NULL, NULL},
{"cat1", "cat2", NULL, NULL},
{"cat3", NULL, NULL, NULL}};
char *c1_gids[3][8] = {{"g1", "g3", "g4", "g6", NULL, NULL, NULL, NULL},
{"g1", "g2", "g4", "g5", NULL, NULL, NULL, NULL},
{"g4", "g5", "g6", NULL, NULL, NULL, NULL, NULL}};
char *cats[3][5] = {{"cat1", "cat4", NULL, NULL, NULL},
{"cat1", "cat2", "cat4", NULL, NULL},
{"cat3", "cat4", NULL, NULL, NULL}};
char *c1_gids[3][9] = {{"g1", "g3", "g4", "g6", "g7", NULL, NULL, NULL, NULL},
{"g1", "g2", "g4", "g5", "g7", NULL, NULL, NULL, NULL},
{"g4", "g5", "g6", "g7", NULL, NULL, NULL, NULL, NULL}};

char *envs[3][4] = {{"env1", NULL, NULL, NULL},
{"env1", "env2", "env3", NULL},
{"env1", "env2", NULL, NULL}};
char *envs[3][5] = {{"env1", "env4", NULL, NULL, NULL},
{"env1", "env2", "env3", "env4", NULL},
{"env1", "env2", "env4", NULL, NULL}};
char *e1_gids[3][8] = {{"g1", "g3", "g4", NULL, NULL, NULL, NULL, NULL},
{"g1", "g2", "g5", NULL, NULL, NULL, NULL, NULL},
{"g2", "g4", NULL, NULL, NULL,NULL, NULL, NULL}};
Expand All @@ -571,7 +571,7 @@ START_TEST(test_arch)
COMPS_OBJECT_DESTROY(arches);

list = comps_doc_groups(doc2);
ck_assert(list->len == 2);
ck_assert(list->len == 3);
for (it = list->first, x=0; it != NULL; it = it->next, x++) {
g = (COMPS_DocGroup*)it->comps_obj;
str = (COMPS_Str*)comps_docgroup_get_id(g);
Expand All @@ -591,7 +591,7 @@ START_TEST(test_arch)
COMPS_OBJECT_DESTROY(list);

list = comps_doc_categories(doc2);
ck_assert(list->len == 1);
ck_assert(list->len == 2);
for (it = list->first, x=0; it != NULL; it = it->next, x++) {
g = (COMPS_DocCategory*)it->comps_obj;
str = (COMPS_Str*)comps_doccategory_get_id(g);
Expand All @@ -611,7 +611,7 @@ START_TEST(test_arch)
COMPS_OBJECT_DESTROY(list);

list = comps_doc_environments(doc2);
ck_assert(list->len == 1);
ck_assert(list->len == 2);
for (it = list->first, x=0; it != NULL; it = it->next, x++) {
g = (COMPS_DocEnv*)it->comps_obj;
str = (COMPS_Str*)comps_docenv_get_id(g);
Expand Down
39 changes: 33 additions & 6 deletions libcomps/tests/main_arches.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group arch="x86_64 x86 s390">
<group arch="x86_64,x86,s390">
<id>group1</id>
<name>group1</name>
<packagelist>
Expand All @@ -11,7 +11,7 @@
<packagereq arch="x86 s390">pkg4</packagereq>
<packagereq arch="x86_64 x86">pkg5</packagereq>
<packagereq arch="x86_64 x86">pkg6</packagereq>
<packagereq arch="x86_64 x86">pkg7</packagereq>
<packagereq>pkg7</packagereq>
</packagelist>
</group>
<group arch="x86_64">
Expand All @@ -28,7 +28,14 @@
<packagereq arch="x86_64 x86">pkg7</packagereq>
</packagelist>
</group>
<category arch="x86_64 x86 s390">
<group>
<id>group4</id>
<name>group4</name>
<packagelist>
<packagereq arch="x86_64 x86">pkg1</packagereq>
</packagelist>
</group>
<category arch="x86_64,x86 s390">
<id>cat1</id>
<name>cat1</name>
<grouplist>
Expand All @@ -38,6 +45,7 @@
<groupid arch="x86_64 x86 s390">g4</groupid>
<groupid arch="x86_64 s390">g5</groupid>
<groupid arch="x86 s390">g6</groupid>
<groupid>g7</groupid>
</grouplist>
</category>
<category arch="x86_64">
Expand All @@ -54,22 +62,31 @@
<groupid arch="x86_64 x86">g1</groupid>
</grouplist>
</category>
<environment arch="x86_64 x86 s390">
<category>
<id>cat4</id>
<name>cat4</name>
<grouplist>
<groupid>g1</groupid>
</grouplist>
</category>
<environment arch="x86_64,x86,s390">
<id>env1</id>
<name>env1</name>
<grouplist>
<groupid arch="x86_64 x86">g1</groupid>
<groupid arch="x86_64,x86">g1</groupid>
<groupid arch="x86_64 s390">g2</groupid>
<groupid arch="x86">g3</groupid>
<groupid arch="x86 s390">g4</groupid>
<groupid arch="x86_64">g5</groupid>
<groupid>g6</groupid>
</grouplist>
<optionlist>
<groupid arch="x86_64 x86 s390">o1</groupid>
<groupid arch="x86_64,x86 s390">o1</groupid>
<groupid arch="s390">o2</groupid>
<groupid arch="x86 x86_64">o3</groupid>
<groupid arch="x86 s390">o4</groupid>
<groupid arch="x86_64">o5</groupid>
<groupid>o6</groupid>
</optionlist>
</environment>
<environment arch="x86_64">
Expand All @@ -92,4 +109,14 @@
<groupid arch="x86_64">o5</groupid>
</optionlist>
</environment>
<environment>
<id>env4</id>
<name>env4</name>
<grouplist>
<groupid arch="x86_64 s390">g1</groupid>
</grouplist>
<optionlist>
<groupid>o5</groupid>
</optionlist>
</environment>
</comps>

0 comments on commit f46fe76

Please sign in to comment.