---------- Forwarded message ---------- From: Nicolas Pinto <nicolas.pinto@xxxxxxxxx> Date: Jul 20, 2005 4:25 PM Subject: How to handle remote rpm package file ? To: rpm-python-list@xxxxxxxxxxxxxx Hi all, I'm trying to handle the installation/upgrade of a remote rpm file (by http or ftp) with the rpm-python binding library. 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). 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 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 = "ftp://sunsite.auc.dk/projects/newrpms/www/htdocs/apt/redhat/en/i386/9.0/RPMS.newrpms/eboard-0.9.0-1.i386.rpm " >>> f = urllib.urlopen(url) >>> f = 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 only hdrFromFdno() which needs a file descriptor number... 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 ? Thanks in advance. Nicolas Pinto A working C implementation (taken from rpmt-4.2.1: http://isscvs.cern.ch:8180/cgi-bin/cvsweb.cgi/elfms/quattor/rpmt-4.2.1/?cvsroot=elfms) : /* * 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 = Fopen(package, "r.ufdio"); if (fd == NULL || Ferror(fd)) { printf("error: cannot open file %s\n", package); rpmEtsExit(ts, 1); } rpmReadPackageFile(ts, fd, package, &hdr); if (hdr == NULL) { printf("failed to read header from package %s\n", package); rpmEtsExit(ts, 1); } Fclose(fd); /* add package to transaction set */ err = 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; }