Ejemplo n.º 1
0
static PyObject * getSection(rpmSpec spec, int section)
{
    const char *sect = rpmSpecGetSection(spec, section);
    if (sect) {
	return Py_BuildValue("s", sect);
    }
    Py_RETURN_NONE;
}
Ejemplo n.º 2
0
Archivo: rpmspec.c Proyecto: soig/rpm
int main(int argc, char *argv[])
{
    rpmts ts = NULL;
    QVA_t qva = &rpmQVKArgs;

    poptContext optCon;
    int ec = 0;

    xsetprogname(argv[0]); /* Portability call -- see system.h */

    optCon = rpmcliInit(argc, argv, optionsTable);

    if (rpmcliPipeOutput && initPipe())
	exit(EXIT_FAILURE);

    if (target) {
	rpmFreeMacros(NULL);
	rpmFreeRpmrc();
	rpmReadConfigFiles(rpmcliRcfile, target);
    }
	
    ts = rpmtsCreate();
    switch (mode) {

    case MODE_QUERY:
	if (!poptPeekArg(optCon))
	    argerror(_("no arguments given for query"));

	qva->qva_queryFormat = queryformat;
	qva->qva_source = source;
	qva->qva_specQuery = rpmspecQuery;
	ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
	break;

    case MODE_PARSE: {
	const char * spath;
	if (!poptPeekArg(optCon))
	    argerror(_("no arguments given for parse"));

	while ((spath = poptGetArg(optCon)) != NULL) {
	    rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
	    if (spec == NULL) {
		ec++;
		continue;
	    }
	    fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
	    rpmSpecFree(spec);
	}
	break;
    }

    case MODE_UNKNOWN:
	if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
	    printUsage(optCon, stderr, 0);
	    ec = argc;
	}
	break;
    }

    rpmtsFree(ts);
    if (finishPipe())
	ec = EXIT_FAILURE;

    free(qva->qva_queryFormat);

    rpmcliFini(optCon);

    return RETVAL(ec);
}