From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org)
	by nuthatch.gentoo.org with esmtp (Exim 4.54)
	id 1FJeEi-000491-OC
	for garchives@archives.gentoo.org; Wed, 15 Mar 2006 22:12:57 +0000
Received: from robin.gentoo.org (localhost [127.0.0.1])
	by robin.gentoo.org (8.13.5.20060308/8.13.5) with SMTP id k2FMCHU5029695;
	Wed, 15 Mar 2006 22:12:17 GMT
Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.193])
	by robin.gentoo.org (8.13.5.20060308/8.13.5) with ESMTP id k2FMCGYC030509
	for <gentoo-portage-dev@lists.gentoo.org>; Wed, 15 Mar 2006 22:12:17 GMT
Received: by nproxy.gmail.com with SMTP id a25so160240nfc
        for <gentoo-portage-dev@lists.gentoo.org>; Wed, 15 Mar 2006 14:12:16 -0800 (PST)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
        s=beta; d=gmail.com;
        h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
        b=cKwGXLjvB+t19ynUkqY27mmrcMvRJjMu1QKC7c1ynLilFa4PYA7tVuhKiTtXMQuJWa11w5XlNn9iTn3D56sQsQqHkdFsu1ov9PFovbVyZ1WTrDvmdgG9A/oqU+fw4aeDbGQNpYsFbQkBawJGNadfumA/Y6RBkvzi04GItq8lLf8=
Received: by 10.48.108.20 with SMTP id g20mr497435nfc;
        Wed, 15 Mar 2006 14:12:16 -0800 (PST)
Received: by 10.49.29.4 with HTTP; Wed, 15 Mar 2006 14:12:16 -0800 (PST)
Message-ID: <cea53e3c0603151412x4dd0f1bbr@mail.gmail.com>
Date: Thu, 16 Mar 2006 00:12:16 +0200
From: tvali <qtvali@gmail.com>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: portage from C (was Re: [gentoo-portage-dev] Hello! && portage UI)
In-Reply-To: <1142458625.10619.131.camel@onyx>
Precedence: bulk
List-Post: <mailto:gentoo-portage-dev@lists.gentoo.org>
List-Help: <mailto:gentoo-portage-dev+help@gentoo.org>
List-Unsubscribe: <mailto:gentoo-portage-dev+unsubscribe@gentoo.org>
List-Subscribe: <mailto:gentoo-portage-dev+subscribe@gentoo.org>
List-Id: Gentoo Linux mail <gentoo-portage-dev.gentoo.org>
X-BeenThere: gentoo-portage-dev@gentoo.org
Reply-to: gentoo-portage-dev@lists.gentoo.org
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_6992_3373230.1142460736367"
References: <cea53e3c0603131439y2b80d08du@mail.gmail.com>
	 <4416DEAF.30008@gentoo.org>
	 <cea53e3c0603140848r44108b8di@mail.gmail.com>
	 <200603151051.32777.pauldv@gentoo.org>
	 <1142434334.25069.110.camel@onyx>
	 <20060315214248.5ef51202@c1358217.kevquinn.com>
	 <1142458625.10619.131.camel@onyx>
X-Archives-Salt: c7c14126-6728-4431-8cf6-d42869361262
X-Archives-Hash: 4f39a842674590199fbfe26fac527d30

------=_Part_6992_3373230.1142460736367
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

So I was the last one :)

My example is using python interpreter -- it's maybe simpler to use in
many cases, but theoretically slower.

It is, anyway, not so advanced to import portage, but you can add that line=
 ;)

2006/3/15, solar <solar@gentoo.org>:
> On Wed, 2006-03-15 at 21:42 +0100, Kevin F. Quinn (Gentoo) wrote:
> > On Wed, 15 Mar 2006 09:52:13 -0500
> > solar <solar@gentoo.org> wrote:
> >
> > > On Wed, 2006-03-15 at 10:51 +0100, Paul de Vrieze wrote:
> > >
> > > [snip]
> > >
> > > > Actually, C++ being strongly related to C, can just use the C
> > > > python api's. As such it could directly interface with python, and
> > > > use the python portage api.
> > >
> > > If you could demonstrate an 'import portage' and a simple
> > > printf("PORTDIR=3D%s\n", PORTDIR); in C I'd be highly interested.
> >
> > Try attached :)  Had a go 'coz I was curious.  Compile with:
> >
> > gcc -o getportdir getportdir.c -lpython2.4
> >
> > Does the equivalent of:
> >
> > #!/usr/bin/portage
> > import portage;
> > print portage.settings["PORTDIR"];
> >
> > (more or less).  Docs on the API itself (which comes with Python) are a=
t
> > http://docs.python.org/api/api.html
>
> thanks Kevin,
>  marienz also put 3 examples together to demonstrate it.
>
> /me feels like a kid in a candy store.
>
> thanks guys.
>
>
> --
> solar <solar@gentoo.org>
> Gentoo Linux
>
> --
> gentoo-portage-dev@gentoo.org mailing list
>
>


--
tvali
(e-mail: "qtvali@gmail.com"; msn: "qtvali@gmail.com";
icq: "317-492-912")

=DChe eesti internetifirma lehel kohtasin tsitaati:
If you don't do it excellently, dont do it at all. Because if it's not
excellent, it won't be profitable or fun, and if you're not in
business for fun or profit, what the hell are you doing here?
Robert Townsend

------=_Part_6992_3373230.1142460736367
Content-Type: text/x-csrc; name=pipe.c; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Attachment-Id: f_eku7keoa
Content-Disposition: attachment; filename="pipe.c"


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>

void python(int input[2], int output[2]) {
        dup2(output[1], STDOUT_FILENO);
        dup2(input[0], STDIN_FILENO);
        close(output[0]);
        close(output[1]);
        close(input[0]);
        close(input[1]);
        char *const args[] = { "/usr/bin/python", NULL };
        execv(args[0], args);
        _exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
    int input[2];
    pipe(input);
    int output[2];
    pipe(output);

    if (fork() == 0) python(input, output);

    FILE *inputf, *outputf;

    close(output[1]);
    close(input[0]);
    outputf = fdopen(output[0], "r");
    inputf = fdopen(input[1], "w");

    fputs("print 123\n", inputf);
    fclose(inputf);

    char tt;
    for (tt=0; tt<40; tt++)
      fputc(tt, inputf);

    int c;
    while ((c = fgetc(outputf)) != EOF)
	  fputc(c, stdout);

    fputc(EOF, inputf);

    wait(NULL);
    return 0;
}




------=_Part_6992_3373230.1142460736367--
-- 
gentoo-portage-dev@gentoo.org mailing list