How to handle remote rpm package file ?

Nicolas Pinto <[email protected]> Wed, 20 Jul 2005 16:25:45 +0200
Newsgroups gmane.linux.redhat.rpm.python
Message-ID <[email protected]>
--===============0771714977==
Content-Type: multipart/alternative; 
	boundary="----=_Part_9640_6516854.1121869545475"

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

Hi all,

I'm trying to handle the installation/upgrade of a remote rpm file (by http=
=20
or ftp) with the rpm-python binding library.

I know that the rpmlib provides a Fopen() function which retrieves the file=
=20
and give you the file descriptor; then you can call the rpmReadPackageFile(=
)=20
function and get the header of the package (this header is required to add=
=20
the package to the transaction set).

You can find a working C implementation at the end of this message.

I tried to use the rpm.fd() function from rpm-python but I always have this=
=20
error :

# python
Python 2.2.3 (#1, Feb 14 2005, 14:38:30)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpm,urllib
>>> url =3D "
ftp://sunsite.auc.dk/projects/newrpms/www/htdocs/apt/redhat/en/i386/9.0/RPM=
S.newrpms/eboard-0.9.0-1.i386.rpm
"
>>> f =3D urllib.urlopen(url)
>>> f =3D rpm.fd(url, "u.ufdio")
*** rpmfd_init(0xa0ed130,0xa0ed81c,(nil))
0xa0ed130 -- fd (nil)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
rpm.error: (2, 'No such file or directory')
>>>

Moreover, rpm-python doesn't provide the rpmReadPackageFile() function but=
=20
only hdrFromFdno() which needs a file descriptor number...

So my question is : how to handle remote package with rpm-python ? Do I hav=
e=20
to retrieve the file using urllib and use it as a local package ?

Thanks in advance.

Nicolas Pinto



A working C implementation (taken from rpmt-4.2.1:=20
http://isscvs.cern.ch:8180/cgi-bin/cvsweb.cgi/elfms/quattor/rpmt-4.2.1/?cvs=
root=3Delfms)
:
/*
* Install or Upgrade a new package
*
* - ts transaction set
* - package package file name
* - upgrade 0 installation, 1 upgrading
*
*/
void rpmEts_AddInstallElement(rpmts ts, const char *package, int upgrade) {

Header hdr;
FD_t fd;
int err;

/* read package header from file */
printf("%s\n", package);
fd =3D Fopen(package, "r.ufdio");


if (fd =3D=3D NULL || Ferror(fd)) {
printf("error: cannot open file %s\n", package);
rpmEtsExit(ts, 1);
}

rpmReadPackageFile(ts, fd, package, &hdr);

if (hdr =3D=3D NULL) {
printf("failed to read header from package %s\n", package);
rpmEtsExit(ts, 1);
}

Fclose(fd);

/* add package to transaction set */

err =3D rpmtsAddInstallElement(ts, hdr, strdup(package), upgrade, NULL);

switch(err) {
case 0: break;
case 1: printf("I/O error reading file %s\n", package);
rpmEtsExit(ts, 1);
case 2: printf("needs capabilities to isntall package %s\n", package);
rpmEtsExit(ts, 1);
}

headerFree(hdr);

return;
}

------=_Part_9640_6516854.1121869545475
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi all,<br>
<br>
I'm trying to handle the installation/upgrade of a remote rpm file (by http=
 or ftp) with the rpm-python binding library.<br>
<br>
I know that the rpmlib provides a Fopen() function which retrieves the
file and give you the file descriptor; then you can call the
rpmReadPackageFile() function and get the header of the package (this
header is required to add the package to the transaction set).<br>
<br>
You can find a working C implementation at the end of this message.<br>
<br>
I tried to use the rpm.fd() function from rpm-python but I always have this=
 error :<br>
<br>
# python<br>
Python 2.2.3 (#1, Feb 14 2005, 14:38:30)<br>
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2<br>
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;=
license&quot; for more information.<br>
&gt;&gt;&gt; import rpm,urllib<br>
&gt;&gt;&gt; url =3D
&quot;<a href=3D"ftp://sunsite.auc.dk/projects/newrpms/www/htdocs/apt/redha=
t/en/i386/9.0/RPMS.newrpms/eboard-0.9.0-1.i386.rpm">ftp://sunsite.auc.dk/pr=
ojects/newrpms/www/htdocs/apt/redhat/en/i386/9.0/RPMS.newrpms/eboard-0.9.0-=
1.i386.rpm
</a>&quot;<br>
&gt;&gt;&gt; f =3D urllib.urlopen(url)<br>
&gt;&gt;&gt; f =3D rpm.fd(url, &quot;u.ufdio&quot;)<br>
*** rpmfd_init(0xa0ed130,0xa0ed81c,(nil))<br>
0xa0ed130 -- fd (nil)<br>
Traceback (most recent call last):<br>
&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in ?<br>
rpm.error: (2, 'No such file or directory')<br>
&gt;&gt;&gt;<br>
<br>
Moreover, rpm-python doesn't provide the rpmReadPackageFile() function
but only hdrFromFdno() which needs a file descriptor number...<br>
<br>
So my question is : how to handle remote package with rpm-python ? Do I
have to retrieve the file using urllib and use it as a local package ?<br>
<br>
Thanks in advance.<br>
<br>
Nicolas Pinto<br>
<br>
<br>
<br>
A working C implementation (taken from rpmt-4.2.1:
<a href=3D"http://isscvs.cern.ch:8180/cgi-bin/cvsweb.cgi/elfms/quattor/rpmt=
-4.2.1/?cvsroot=3Delfms">http://isscvs.cern.ch:8180/cgi-bin/cvsweb.cgi/elfm=
s/quattor/rpmt-4.2.1/?cvsroot=3Delfms</a>) :<br>
/*<br>

&nbsp;* Install or Upgrade a new package<br>

&nbsp;*<br>

&nbsp;* - ts&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; transaction set<br>

&nbsp;* - package&nbsp;&nbsp;&nbsp; package file name<br>

&nbsp;* - upgrade&nbsp;&nbsp;&nbsp; 0 installation, 1 upgrading<br>

&nbsp;*<br>

&nbsp;*/<br>

void rpmEts_AddInstallElement(rpmts ts, const char *package, int upgrade) {=
<br>

<br>

&nbsp;&nbsp;&nbsp; Header&nbsp;&nbsp;&nbsp; hdr;<br>

&nbsp;&nbsp;&nbsp; FD_t&nbsp;&nbsp;&nbsp; fd;<br>

&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; err;<br>

<br>

&nbsp;&nbsp;&nbsp; /* read package header from file */<br>

&nbsp;&nbsp;&nbsp; printf(&quot;%s\n&quot;, package);<br>

&nbsp;&nbsp;&nbsp; fd =3D Fopen(package, &quot;r.ufdio&quot;);<br>

<br>

<br>

&nbsp;&nbsp;&nbsp; if (fd =3D=3D NULL || Ferror(fd)) {<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;error: cannot open =
file %s\n&quot;, package);<br>

&nbsp;&nbsp;&nbsp; rpmEtsExit(ts, 1);<br>

&nbsp;&nbsp;&nbsp; }<br>

<br>

&nbsp;&nbsp;&nbsp; rpmReadPackageFile(ts, fd, package, &amp;hdr);<br>

<br>

&nbsp;&nbsp;&nbsp; if (hdr =3D=3D NULL) {<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;failed to read head=
er from package %s\n&quot;, package);<br>

&nbsp;&nbsp;&nbsp; rpmEtsExit(ts, 1);<br>

&nbsp;&nbsp;&nbsp; }<br>

<br>

&nbsp;&nbsp;&nbsp; Fclose(fd);<br>

<br>

&nbsp;&nbsp;&nbsp; /* add package to transaction set */<br>

<br>

&nbsp;&nbsp;&nbsp; err =3D rpmtsAddInstallElement(ts, hdr, strdup(package),=
 upgrade, NULL);<br>

<br>

&nbsp;&nbsp;&nbsp; switch(err) {<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0: break;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1: printf(&quot;I/O error r=
eading file %s\n&quot;, package);<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; rpmEtsExit(ts, 1);<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2: printf(&quot;needs capab=
ilities to isntall package %s\n&quot;, package);<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; rpmEtsExit(ts, 1);<br>

&nbsp;&nbsp;&nbsp; }<br>

<br>

&nbsp;&nbsp;&nbsp; headerFree(hdr);<br>

<br>

&nbsp;&nbsp;&nbsp; return;<br>

}<br>
<br>

------=_Part_9640_6516854.1121869545475--

--===============0771714977==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Rpm-python-list mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/rpm-python-list

--===============0771714977==--