Beispiel #1
0
signed char comps_doccategory_xml(COMPS_DocCategory *category,
                                  xmlTextWriterPtr writer, COMPS_Log *log,
                                  COMPS_XMLOptions *xml_options,
                                  COMPS_DefaultsOptions *def_options) {
    COMPS_ObjListIt *it;
    COMPS_Object *obj;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;

    static char* props[] = {"id", "name", "name", "desc", "desc", "display_order"};
    static size_t type[] =   {0, 0, offsetof(COMPS_DocCategory, name_by_lang),
                           0, offsetof(COMPS_DocCategory, desc_by_lang), 0};
    static char* aliases[] = {NULL, NULL, NULL, "description", "description", NULL};
    char *str;
    int ret;

    if (category->group_ids->len == 0 && !xml_options->empty_categories) {
        obj = comps_doccategory_get_id(category);
        comps_log_error(log, COMPS_ERR_PKGLIST_EMPTY, 1, obj);
        COMPS_OBJECT_DESTROY(obj);
        return 1;
    }
    ret = xmlTextWriterStartElement(writer, BAD_CAST "category");
    COMPS_XMLRET_CHECK
    if (xml_options->arch_output) {
        obj = (COMPS_Object*)comps_doccategory_arches(category);
        ret = __comps_xml_arch(obj, writer);
        COMPS_OBJECT_DESTROY(obj);
        COMPS_XMLRET_CHECK
    }
static void comps_docgroup_destroy(COMPS_DocGroup *group) {
    
    COMPS_OBJECT_DESTROY(group->properties);
    COMPS_OBJECT_DESTROY(group->name_by_lang);
    COMPS_OBJECT_DESTROY(group->desc_by_lang);
    COMPS_OBJECT_DESTROY(group->packages);
}
Beispiel #3
0
END_TEST

START_TEST(test_comps_parse3)
{
    FILE *fp;
    //char *err_log,
    char *tmp_ch;
    COMPS_Parsed *parsed;
    COMPS_ObjListIt *it;
    int i;
    COMPS_ObjList *tmplist;
    COMPS_LogEntry* known_errors[3];
    char *str;
    COMPS_Object *tmpobj;

    fprintf(stderr, "## Running test_parse3\n\n");

    known_errors[0] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                             comps_str("id"), comps_num(188),
                                             comps_num(2));
    known_errors[1] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                            comps_str("name"), comps_num(188),
                                            comps_num(2));
    known_errors[2] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3,
                                             comps_str("description"),
                                             comps_num(188), comps_num(2));

    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 1);
    fp = fopen("sample_comps_bad1.xml", "r");
    comps_parse_file(parsed, fp, NULL);

    fail_if(parsed->log->entries->first == NULL);
    check_errors(parsed->log, known_errors, 3);

    for (i = 0; i < 3; i++) {
        comps_log_entry_destroy(known_errors[i]);
    }
    tmplist = comps_doc_groups(parsed->comps_doc);
    it = tmplist->first;

    /*pairlist = comps_rtree_pairs(((COMPS_DocCategory*)it->data)->properties);
    for (hsit = pairlist->first; hsit != NULL; hsit = hsit->next){
        printf("%s = %s\n", ((COMPS_RTreePair*)hsit->data)->key,
                          ((COMPS_RTreePair*)hsit->data)->data);
    }*/
    COMPS_OBJECT_DESTROY(tmplist);

    tmpobj = comps_docgroup_get_id((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL id\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    tmpobj = comps_docgroup_get_name((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL name\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    tmpobj = comps_docgroup_get_desc((COMPS_DocGroup*)it->comps_obj);
    fail_if(tmpobj, "%d. category should have NULL description\n");
    COMPS_OBJECT_DESTROY(tmpobj);
    comps_parse_parsed_destroy(parsed);
}
Beispiel #4
0
char __comps_doccategory_idcmp(void *c1, void *c2) {
    COMPS_Object *obj1, *obj2;
    char ret;
    obj1 = comps_objdict_get(((COMPS_DocCategory*)c1)->properties, "id");
    obj2 = comps_objdict_get(((COMPS_DocCategory*)c2)->properties, "id");
    ret = comps_object_cmp(obj1, obj2);
    COMPS_OBJECT_DESTROY(obj1);
    COMPS_OBJECT_DESTROY(obj2);
    return ret;
}
char __comps_docgroup_idcmp(void *g1, void *g2) {
    COMPS_Object *obj1, *obj2;
    char ret;
    obj1 = comps_objdict_get(((COMPS_DocGroup*)g1)->properties, "id");
    obj2 = comps_objdict_get(((COMPS_DocGroup*)g2)->properties, "id");
    ret = comps_object_cmp(obj1, obj2);
    COMPS_OBJECT_DESTROY(obj1);
    COMPS_OBJECT_DESTROY(obj2);
    return ret;
}
Beispiel #6
0
COMPS_ObjMRTree * comps_objmrtree_clone(COMPS_ObjMRTree * rt) {
    COMPS_HSList * to_clone, *tmplist, *new_subnodes;
    COMPS_ObjMRTree * ret;
    COMPS_HSListItem *it, *it2;
    COMPS_ObjMRTreeData *rtdata;
    COMPS_ObjList *new_data_list;

    to_clone = comps_hslist_create();
    comps_hslist_init(to_clone, NULL, NULL, NULL);
    ret = (COMPS_ObjMRTree*)comps_object_create(&COMPS_ObjMRTree_ObjInfo, NULL);

    for (it = rt->subnodes->first; it != NULL; it = it->next) {
        rtdata = comps_objmrtree_data_create(
                                       ((COMPS_ObjMRTreeData*)it->data)->key,
                                       NULL);
        new_data_list = (COMPS_ObjList*)
                        COMPS_OBJECT_COPY(((COMPS_ObjMRTreeData*)it->data)->data);
        COMPS_OBJECT_DESTROY(&rtdata->data);
        comps_hslist_destroy(&rtdata->subnodes);
        rtdata->subnodes = ((COMPS_ObjMRTreeData*)it->data)->subnodes;
        rtdata->data = new_data_list;
        comps_hslist_append(ret->subnodes, rtdata, 0);

        comps_hslist_append(to_clone, rtdata, 0);
    }

    while (to_clone->first) {
        it2 = to_clone->first;
        tmplist = ((COMPS_ObjMRTreeData*)it2->data)->subnodes;
        comps_hslist_remove(to_clone, to_clone->first);

        new_subnodes = comps_hslist_create();
        comps_hslist_init(new_subnodes, NULL, NULL, &comps_objmrtree_data_destroy_v);
        for (it = tmplist->first; it != NULL; it = it->next) {
            rtdata = comps_objmrtree_data_create(
                                          ((COMPS_ObjMRTreeData*)it->data)->key,
                                          NULL);
            new_data_list = (COMPS_ObjList*)
                            COMPS_OBJECT_COPY(((COMPS_ObjMRTreeData*)it->data)->data);

            comps_hslist_destroy(&rtdata->subnodes);
            COMPS_OBJECT_DESTROY(rtdata->data);
            rtdata->subnodes = ((COMPS_ObjMRTreeData*)it->data)->subnodes;
            rtdata->data = new_data_list;
            comps_hslist_append(new_subnodes, rtdata, 0);

            comps_hslist_append(to_clone, rtdata, 0);
        }
        ((COMPS_ObjMRTreeData*)it2->data)->subnodes = new_subnodes;
        free(it2);
    }
    ret->len = rt->len;
    comps_hslist_destroy(&to_clone);
    return ret;
}
Beispiel #7
0
PyObject* PyCOMPS_fromxml_f(PyObject *self, PyObject *args, PyObject* kwds) {
    FILE *f;
    COMPS_Parsed *parsed;
    char *fname = NULL;
    signed char parsed_ret;
    PyCOMPS *self_comps = (PyCOMPS*)self;
    COMPS_Object *tmpstr;
    COMPS_DefaultsOptions *options = NULL;

    char* keywords[] = {"fname", "options", NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&", keywords, &fname,
                                     __pycomps_dict_to_def_opts, &options)) {
        PyErr_SetString(PyExc_TypeError,
                        "function accept string and optional xml_options dict");
        return NULL;
    }

    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 0);
    f =  fopen(fname, "r");
    if (!f) {
        PyErr_Format(PyExc_IOError, "Cannot open %s for reading", fname);
        //free(fname);
        comps_parse_parsed_destroy(parsed);
        if (options)
            free(options);
        return NULL;
    }
    parsed_ret = comps_parse_file(parsed, f, options);
    Py_CLEAR(self_comps->p_groups);
    Py_CLEAR(self_comps->p_categories);
    Py_CLEAR(self_comps->p_environments);
    Py_CLEAR(self_comps->p_langpacks);
    Py_CLEAR(self_comps->p_blacklist);
    Py_CLEAR(self_comps->p_whiteout);


    COMPS_OBJECT_DESTROY(self_comps->comps_doc);
    if (options)
        free(options);

    if (parsed->comps_doc) {
        self_comps->comps_doc = parsed->comps_doc;
    } else {
        tmpstr = (COMPS_Object*)comps_str("UTF-8");
        self_comps->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc,
        (COMPS_Object*[]) {
            tmpstr
        });
        COMPS_OBJECT_DESTROY(tmpstr);
    }
Beispiel #8
0
int pycomps_env_validate(COMPS_Object *obj) {
    COMPS_ValGenResult *result = comps_validate_execute(obj,
                                        COMPS_DocEnv_ValidateRules);
    int ret = __pycomps_validate_process(result);
    COMPS_OBJECT_DESTROY(result);
    return ret;
}
COMPS_ObjList* comps_docgroup_get_packages(COMPS_DocGroup *group, char *name,
                                       COMPS_PackageType type) {
    COMPS_ObjListIt *it;
    COMPS_ObjList *ret;
    unsigned int matched, matched_max;
    matched_max = 0;
    #define package ((COMPS_DocGroupPackage*)it->comps_obj)
    COMPS_Str *objname = comps_str(name);
    if (!group) return NULL;

    ret = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL);

    if (name != NULL) matched_max++;
    if (type != COMPS_PACKAGE_UNKNOWN) matched_max++;

    for (it = (group->packages)?group->packages->first:NULL;
         it != NULL; it = it->next) {
        matched = 0;
        if ((name != NULL) && COMPS_OBJECT_CMP(package->name, objname))
            matched++;
        if ((type != COMPS_PACKAGE_UNKNOWN) && package->type  == type)
            matched++;
        if (matched == matched_max) {
            comps_objlist_append(ret, (COMPS_Object*)package);
        }
    }
    COMPS_OBJECT_DESTROY(objname);
    return ret;
}
Beispiel #10
0
PyObject* comps_groups_out(COMPS_Object *cobj) {
    PyCOMPS_Group *ret;
    ret = (PyCOMPS_Group*)PyCOMPSGroup_new(&PyCOMPS_GroupType, NULL, NULL);
    PyCOMPSGroup_init(ret, NULL, NULL);
    COMPS_OBJECT_DESTROY(ret->group);
    ret->group = (COMPS_DocGroup*)cobj;
    return (PyObject*)ret;
}
Beispiel #11
0
PyObject* comps_pkgs_out(COMPS_Object *cobj) {
    PyCOMPS_Package *ret;
    ret = (PyCOMPS_Package*)PyCOMPSPack_new(&PyCOMPS_PackType, NULL, NULL);
    PyCOMPSPack_init(ret, NULL, NULL);
    COMPS_OBJECT_DESTROY(ret->package);
    ret->package = (COMPS_DocGroupPackage*)cobj;
    return (PyObject*)ret;
}
Beispiel #12
0
PyObject* comps_envs_out(COMPS_Object *cobj) {
    PyCOMPS_Env *ret;
    ret = (PyCOMPS_Env*)PyCOMPSEnv_new(&PyCOMPS_EnvType, NULL, NULL);
    PyCOMPSEnv_init(ret, NULL, NULL);
    COMPS_OBJECT_DESTROY(ret->c_obj);
    ret->c_obj = (COMPS_DocEnv*)cobj;
    return (PyObject*)ret;
}
Beispiel #13
0
void comps_docpackage_set_basearchonly(COMPS_DocGroupPackage *pkg,
                                       int basearchonly, bool unset) {
    (void)unset;
    if (pkg->basearchonly) {
        COMPS_OBJECT_DESTROY(pkg->basearchonly);
    }
    pkg->basearchonly = comps_num(basearchonly);
}
Beispiel #14
0
void comps_objrtree_copy(COMPS_ObjRTree *rt1, COMPS_ObjRTree *rt2) {
    COMPS_HSList *to_clone, *tmplist, *new_subnodes;
    COMPS_HSListItem *it, *it2;
    COMPS_ObjRTreeData *rtdata;
    COMPS_Object *new_data;

    rt1->subnodes = comps_hslist_create();
    comps_hslist_init(rt1->subnodes, NULL, NULL, &comps_objrtree_data_destroy_v);
    if (rt1->subnodes == NULL) {
        COMPS_OBJECT_DESTROY(rt1);
        return;
    }
    rt1->len = 0;

    to_clone = comps_hslist_create();
    comps_hslist_init(to_clone, NULL, NULL, NULL);

    for (it = rt2->subnodes->first; it != NULL; it = it->next) {
        rtdata = comps_objrtree_data_create(
                     ((COMPS_ObjRTreeData*)it->data)->key, NULL);
        if (((COMPS_ObjRTreeData*)it->data)->data != NULL)
            new_data = comps_object_copy(((COMPS_ObjRTreeData*)it->data)->data);
        else
            new_data = NULL;
        comps_hslist_destroy(&rtdata->subnodes);
        rtdata->subnodes = ((COMPS_ObjRTreeData*)it->data)->subnodes;
        rtdata->data = new_data;
        comps_hslist_append(rt1->subnodes, rtdata, 0);
        comps_hslist_append(to_clone, rtdata, 0);
    }

    while (to_clone->first) {
        it2 = to_clone->first;
        tmplist = ((COMPS_ObjRTreeData*)it2->data)->subnodes;
        comps_hslist_remove(to_clone, to_clone->first);

        new_subnodes = comps_hslist_create();
        comps_hslist_init(new_subnodes, NULL, NULL, &comps_objrtree_data_destroy_v);
        for (it = tmplist->first; it != NULL; it = it->next) {
            rtdata = comps_objrtree_data_create(
                         ((COMPS_ObjRTreeData*)it->data)->key, NULL);
            if (((COMPS_ObjRTreeData*)it->data)->data != NULL)
                new_data = comps_object_copy(((COMPS_ObjRTreeData*)it->data)->data);
            else
                new_data = NULL;
            comps_hslist_destroy(&rtdata->subnodes);
            rtdata->subnodes = ((COMPS_ObjRTreeData*)it->data)->subnodes;
            rtdata->data = new_data;
            comps_hslist_append(new_subnodes, rtdata, 0);
            comps_hslist_append(to_clone, rtdata, 0);
        }
        ((COMPS_ObjRTreeData*)it2->data)->subnodes = new_subnodes;
        free(it2);
    }
    comps_hslist_destroy(&to_clone);

}
void __comps_check_allready_set(COMPS_Object *param, char *param_name,
                                COMPS_Parsed *parsed) {
    if (param) {
        comps_log_error_x(parsed->log, COMPS_ERR_ELEM_ALREADYSET, 3,
                          comps_str(param_name),
                          comps_num(parser_line), comps_num(parser_col));
    }
    COMPS_OBJECT_DESTROY(param);
}
void __comps_check_required_param(COMPS_Object *param, char *param_name,
                                  COMPS_Parsed *parsed) {
    if (!param) {
        comps_log_error_x(parsed->log, COMPS_ERR_ELEM_REQUIRED, 3,
                          comps_str(param_name),
                          comps_num(parser_line), comps_num(parser_col));
    }
    COMPS_OBJECT_DESTROY(param);
}
Beispiel #17
0
static void comps_objrtree_create(COMPS_ObjRTree *rtree, COMPS_Object **args) {
    (void)args;
    rtree->subnodes = comps_hslist_create();
    comps_hslist_init(rtree->subnodes, NULL, NULL, &comps_objrtree_data_destroy_v);
    if (rtree->subnodes == NULL) {
        COMPS_OBJECT_DESTROY(rtree);
        return;
    }
    rtree->len = 0;
}
Beispiel #18
0
void PyCOMPSGroup_dealloc(PyObject *self)
{
    #define _group_ ((PyCOMPS_Group*)self)
    Py_XDECREF(_group_->p_packages);
    Py_XDECREF(_group_->p_name_by_lang);
    Py_XDECREF(_group_->p_desc_by_lang);
    COMPS_OBJECT_DESTROY(_group_->group);
    Py_TYPE(self)->tp_free((PyObject*)self);
    #undef _group_
}
Beispiel #19
0
PyObject* PyCOMPS_clear(PyObject *self) {

    COMPS_Str *enc;
    enc = (COMPS_Str*)
          comps_object_incref((COMPS_Object*)((PyCOMPS*)self)->comps_doc->encoding);

    COMPS_OBJECT_DESTROY(((PyCOMPS*)self)->comps_doc);
    ((PyCOMPS*)self)->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc, NULL);
    ((PyCOMPS*)self)->comps_doc->encoding = enc;
    Py_RETURN_NONE;
}
Beispiel #20
0
void PyCOMPSEnv_dealloc(PyObject *self)
{
    #define _env_ ((PyCOMPS_Env*)self)
    Py_XDECREF(_env_->p_group_list);
    Py_XDECREF(_env_->p_option_list);
    Py_XDECREF(_env_->p_name_by_lang);
    Py_XDECREF(_env_->p_desc_by_lang);
    COMPS_OBJECT_DESTROY(_env_->c_obj);
    Py_TYPE(self)->tp_free((PyObject*)self);
    #undef _env_
}
Beispiel #21
0
COMPS_DocCategory* comps_doccategory_union(COMPS_DocCategory *c1,
                                           COMPS_DocCategory *c2) {
    COMPS_DocCategory *res;
    COMPS_ObjListIt *it;
    COMPS_Set *set;
    COMPS_Object *obj;
    void *data;
    int index;

    res = COMPS_OBJECT_CREATE(COMPS_DocCategory,NULL);
    COMPS_OBJECT_DESTROY(res->properties);

    res->properties = comps_objdict_union(c1->properties, c2->properties);
    set = comps_set_create();
    comps_set_init(set, NULL, NULL, &comps_object_destroy_v,
                                    &__comps_docgroupid_cmp_set);
    it = c1->group_ids?c1->group_ids->first:NULL;
    for (; it != NULL; it = it->next) {
        obj = comps_object_copy(it->comps_obj);
        comps_set_add(set, (void*)comps_object_incref(obj));
        comps_doccategory_add_groupid(res, (COMPS_DocGroupId*)obj);
    }
    it = c2->group_ids ? c2->group_ids->first : NULL;
    for (; it != NULL; it = it->next) {
        if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) {
            index = comps_objlist_index(res->group_ids, (COMPS_Object*)data);
            comps_objlist_remove_at(res->group_ids, index);
            comps_objlist_insert_at_x(res->group_ids, index,
                                      comps_object_copy(it->comps_obj));
        } else {
            comps_doccategory_add_groupid(res, (COMPS_DocGroupId*)
                                            comps_object_copy(it->comps_obj));
        }
    }
    comps_set_destroy(&set);
    COMPS_OBJECT_DESTROY(res->name_by_lang);
    COMPS_OBJECT_DESTROY(res->desc_by_lang);
    res->name_by_lang = comps_objdict_union(c1->name_by_lang, c2->name_by_lang);
    res->desc_by_lang = comps_objdict_union(c1->desc_by_lang, c2->desc_by_lang);
    return res;
}
Beispiel #22
0
PyObject* pycomps_group_boolattr_getter(PyObject *self, void *closure) {

    COMPS_Object *tmp_prop;
    PyObject *ret;
    tmp_prop = comps_objdict_get(((PyCOMPS_Group*)self)->group->properties,
                                 (char*)closure);
    if (tmp_prop) {
        ret = PyBool_FromLong(((COMPS_Num*)tmp_prop)->val);
        COMPS_OBJECT_DESTROY(tmp_prop);
        return ret;
    } else
        Py_RETURN_NONE;
}
Beispiel #23
0
PyObject* PyCOMPSGroup_union(PyObject *self, PyObject *other) {
    COMPS_DocGroup *g;
    PyObject *res;

    if (other->ob_type != &PyCOMPS_GroupType) {
        PyErr_SetString(PyExc_TypeError, "Not Group instance");
        return NULL;
    }
    g = comps_docgroup_union(((PyCOMPS_Group*)self)->group,
                             ((PyCOMPS_Group*)other)->group);
    res = PyCOMPSGroup_new(&PyCOMPS_GroupType, NULL, NULL);
    PyCOMPSGroup_init((PyCOMPS_Group*)res, NULL, NULL);
    COMPS_OBJECT_DESTROY(((PyCOMPS_Group*)res)->group);
    ((PyCOMPS_Group*)res)->group = g;
    return res;
}
Beispiel #24
0
PyObject* PyCOMPSEnv_union(PyObject *self, PyObject *other) {
    COMPS_DocEnv *e;
    PyObject *res;

    if (Py_TYPE(other) != &PyCOMPS_EnvType) {
        PyErr_SetString(PyExc_TypeError, "Not Environment instance");
        return NULL;
    }
    e = comps_docenv_union(((PyCOMPS_Env*)self)->c_obj,
                           ((PyCOMPS_Env*)other)->c_obj);

    res = PyCOMPSEnv_new(&PyCOMPS_EnvType, NULL, NULL);
    PyCOMPSEnv_init((PyCOMPS_Env*)res, NULL, NULL);
    COMPS_OBJECT_DESTROY(((PyCOMPS_Env*)res)->c_obj);
    ((PyCOMPS_Env*)res)->c_obj = e;
    return res;
}
Beispiel #25
0
PyObject* PyCOMPSGroups_union(PyObject *self, PyObject *other) {
    PyCOMPS_Sequence *res;
    COMPS_ObjList *res_list;

    if (other == NULL || Py_TYPE(other) != &PyCOMPS_GroupsType) {
        PyErr_SetString(PyExc_TypeError, "Not GroupList instance");
        return NULL;
    }

    res = (PyCOMPS_Sequence*) Py_TYPE(self)->tp_new(Py_TYPE(self), NULL, NULL);
    PyCOMPSGroups_init(res, NULL, NULL);

    res_list = comps_groups_union(((PyCOMPS_Sequence*)self)->list,
                                ((PyCOMPS_Sequence*)other)->list);
    COMPS_OBJECT_DESTROY(((PyCOMPS_Sequence*)res)->list);
    res->list = res_list;
    return (PyObject*)res;
}
PyObject* PyCOMPSDict_get(PyObject *self, PyObject *key) {
    char *ckey;
    COMPS_Object* val;
    PyObject *ret = NULL;

    if (__pycomps_stringable_to_char(key, &ckey)) {
        return NULL;
    }
    val = comps_objdict_get(((PyCOMPS_Dict*)self)->dict, ckey);
    if (!val) {
        PyErr_Format(PyExc_KeyError, "KeyError: '%s'", ckey);
    }
    else {
        ret = ((PyCOMPS_Dict*)self)->it_info->out_convert_func(val);
        COMPS_OBJECT_DESTROY(val);
    }
    free(ckey);
    return ret;
}
COMPS_DocGroup* comps_docgroup_union(COMPS_DocGroup *g1, COMPS_DocGroup *g2) {
    COMPS_DocGroup *res;
    COMPS_ObjListIt *it;
    COMPS_Set *set;
    COMPS_DocGroupPackage *pkg;

    res = COMPS_OBJECT_CREATE(COMPS_DocGroup, NULL);
    COMPS_OBJECT_DESTROY(res->properties);

    res->properties = comps_objdict_union(g1->properties, g2->properties);
    set = comps_set_create();
    comps_set_init(set, NULL, NULL, (void(*)(void*))&comps_object_destroy,
                                    &comps_docpackage_cmp_set);
    it = g1->packages?g1->packages->first:NULL;
    for (; it != NULL; it = it->next) {
        pkg = (COMPS_DocGroupPackage*) comps_object_copy(it->comps_obj);
        comps_set_add(set, (void*)comps_object_incref((COMPS_Object*)pkg));
        comps_docgroup_add_package(res, pkg);
    }
    void *data;
    int index;
    it = g2->packages?g2->packages->first:NULL;
    for (; it != NULL; it = it->next) {
        if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) {
            index = comps_objlist_index(res->packages, (COMPS_Object*)data);
            comps_objlist_remove_at(res->packages, index);
            comps_objlist_insert_at_x(res->packages, index,
                                      comps_object_copy(it->comps_obj));
        } else {
            comps_docgroup_add_package(res, (COMPS_DocGroupPackage*)
                                            comps_object_copy(it->comps_obj));
        }
    }
    comps_set_destroy(&set);
    comps_object_destroy((COMPS_Object*)res->name_by_lang);
    comps_object_destroy((COMPS_Object*)res->desc_by_lang);
    res->name_by_lang = comps_objdict_union(g1->name_by_lang, g2->name_by_lang);
    res->desc_by_lang = comps_objdict_union(g1->desc_by_lang, g2->desc_by_lang);
    return res;
}
PyObject* PyCOMPSDict_get_(PyObject *self, PyObject *key) {
    char *ckey;
    COMPS_Object* val;
    PyObject *ret;

    if (__pycomps_stringable_to_char(key, &ckey))
        return NULL;

    val = comps_objdict_get(((PyCOMPS_Dict*)self)->dict, ckey);
    if (!val) {
        free(ckey);
        Py_RETURN_NONE;
    }
    else {
        free(ckey);
        ckey = comps_object_tostr(val);
        COMPS_OBJECT_DESTROY(val);
        ret = PyUnicode_FromString(ckey);
        free(ckey);
        return ret;
    }
}
Beispiel #29
0
void pycomps_clear(PyObject *self) {
    COMPS_OBJECT_DESTROY(((PyCOMPS*)self)->comps_doc);
}
Beispiel #30
0
END_TEST

START_TEST(test_arch)
{
    COMPS_Parsed *parsed;
    COMPS_Doc *doc2;
    COMPS_ObjList *arches, *list, *list2;
    COMPS_DocGroup *g;
    COMPS_DocCategory *c;
    COMPS_DocEnv *e;
    COMPS_DocGroupPackage *p;
    COMPS_Str *str;
    int x;
    COMPS_ObjListIt *it;
    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", "pkg7", NULL, NULL, NULL, NULL, NULL},
                        {"pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7",
                         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][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}};
    char *e1_oids[3][8] = {{"o1", "o3", "o4", NULL, NULL, NULL, NULL, NULL},
                           {"o1", "o2", "o5", NULL, NULL, NULL, NULL, NULL},
                           {"o2", "o4", NULL, NULL, NULL,NULL, NULL, NULL}};

    FILE *fp;
    //char *tmp;
    fprintf(stderr, "## Running test_parse arch\n");
    parsed = comps_parse_parsed_create();
    comps_parse_parsed_init(parsed, "UTF-8", 0);
    fp = fopen("main_arches.xml", "r");
    comps_parse_file(parsed, fp, NULL);
    //comps_log_print(parsed->log);
    fail_if(parsed->fatal_error != 0, "Some fatal errors found after parsing");
    //comps2xml_f(parsed->comps_doc, "fed2.xml", 0);
    arches = (COMPS_ObjList*)comps_object_create(&COMPS_ObjList_ObjInfo, NULL);
    comps_objlist_append_x(arches, (COMPS_Object*)comps_str("x86"));

    doc2 = comps_doc_arch_filter(parsed->comps_doc, arches);
    COMPS_OBJECT_DESTROY(arches);

    list = comps_doc_groups(doc2);
    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);
        ck_assert_msg(strcmp(str->val, grps[0][x]) == 0, "%s != %s",
                      str->val, grps[0][x]);
        COMPS_OBJECT_DESTROY(str);
    }
    g = (COMPS_DocGroup*)list->first->comps_obj;
    list2 = g->packages;
    for (x=0, it = list2->first; it != NULL; it = it->next, x++) {
        //printf("%s\n", ((COMPS_DocGroupPackage*)it->comps_obj)->name->val);
        if (g1_pkgs[0][x] == NULL)
            break;
        ck_assert(strcmp(((COMPS_DocGroupPackage*)it->comps_obj)->name->val,
                         g1_pkgs[0][x]) == 0);
    }
    COMPS_OBJECT_DESTROY(list);

    list = comps_doc_categories(doc2);
    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);
        ck_assert_msg(strcmp(str->val, cats[0][x]) == 0, "%s != %s",
                      str->val, cats[0][x]);
        COMPS_OBJECT_DESTROY(str);
    }
    c = (COMPS_DocCategory*)list->first->comps_obj;
    list2 = c->group_ids;
    for (x=0, it = list2->first; it != NULL; it = it->next, x++) {
        //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val);
        if (c1_gids[0][x] == NULL)
            break;
        ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val,
                         c1_gids[0][x]) == 0);
    }
    COMPS_OBJECT_DESTROY(list);

    list = comps_doc_environments(doc2);
    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);
        ck_assert_msg(strcmp(str->val, envs[0][x]) == 0, "%s != %s",
                      str->val, envs[0][x]);
        COMPS_OBJECT_DESTROY(str);
    }
    e = (COMPS_DocEnv*)list->first->comps_obj;
    list2 = e->group_list;
    for (x=0, it = list2->first; it != NULL; it = it->next, x++) {
        //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val);
        if (e1_gids[0][x] == NULL)
            break;
        ck_assert_msg(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val,
                         e1_gids[0][x]) == 0, "%s != %s",
                         ((COMPS_DocGroupId*)it->comps_obj)->name->val,
                         e1_gids[0][x]);
    }
    list2 = e->option_list;
    for (x=0, it = list2->first; it != NULL; it = it->next, x++) {
        if (e1_oids[0][x] == NULL)
            break;
        ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val,
                         e1_oids[0][x]) == 0);
    }
    COMPS_OBJECT_DESTROY(list);

    COMPS_OBJECT_DESTROY(doc2);
    comps_parse_parsed_destroy(parsed);
}