aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thauvin <nanardon@mandriva.org>2007-07-04 15:53:30 +0000
committerOlivier Thauvin <nanardon@mandriva.org>2007-07-04 15:53:30 +0000
commit3d1a4c165264b3d9876fb84cca2ce6335c264b97 (patch)
tree4eb0b2b6087e1ee2eaf84c1a989064f9428d9005
parentca1219cb28ad7ef95073a654bb1b103c9e1b69b2 (diff)
downloadperl-URPM-3d1a4c165264b3d9876fb84cca2ce6335c264b97.tar
perl-URPM-3d1a4c165264b3d9876fb84cca2ce6335c264b97.tar.gz
perl-URPM-3d1a4c165264b3d9876fb84cca2ce6335c264b97.tar.bz2
perl-URPM-3d1a4c165264b3d9876fb84cca2ce6335c264b97.tar.xz
perl-URPM-3d1a4c165264b3d9876fb84cca2ce6335c264b97.zip
- add Pkg_is_platform_compat() and Urpm_platformscore() coming with rpm 4.4.8
-rw-r--r--URPM.pm11
-rw-r--r--URPM.xs49
-rw-r--r--t/parse.t3
3 files changed, 61 insertions, 2 deletions
diff --git a/URPM.pm b/URPM.pm
index 3292ea4..c88bf3c 100644
--- a/URPM.pm
+++ b/URPM.pm
@@ -562,6 +562,12 @@ Returns whether this package is compatible with the current machine's
architecture. 0 means not compatible. The lower the result is, the preferred
the package is.
+=item $package->is_platform_compat()
+
+Return whether this package is compatible with the current machine's
+platform configuration (/etc/rpm/platform). 0 mean not compatible.
+The lower the result is the preferred the package is.
+
=item $package->license()
=item $package->name()
@@ -751,6 +757,11 @@ Sets rpm verbosity level. $level is an integer between 2 (RPMMESS_CRIT) and 7
=item rpmErrorWriteTo($fd)
+=item platformscore($platform)
+
+Return the score of $platform according computer's configuration.
+0 mean not compatible, lower is prefered.
+
=back
=head1 COPYRIGHT
diff --git a/URPM.xs b/URPM.xs
index c7f22e4..31047f6 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -1352,7 +1352,7 @@ Pkg_is_arch_compat(pkg)
RETVAL = rpmMachineScore(RPM_MACHTABLE_INSTARCH, arch);
#endif
*eos = '@';
- free(platform);
+ _free(platform);
} else if (pkg->h && headerIsEntry(pkg->h, RPMTAG_SOURCERPM)) {
char *arch = get_name(pkg->h, RPMTAG_ARCH);
#ifdef RPM_448
@@ -1367,6 +1367,40 @@ Pkg_is_arch_compat(pkg)
OUTPUT:
RETVAL
+int
+Pkg_is_platform_compat(pkg)
+ URPM::Package pkg
+ INIT:
+ char * platform = NULL;
+ CODE:
+#ifdef RPM_448
+ read_config_files(0);
+ if (pkg->h && headerIsEntry(pkg->h, RPMTAG_PLATFORM)) {
+ int_32 count, type;
+ (void) headerGetEntry(pkg->h, RPMTAG_PLATFORM, &type, (void **) &platform, &count);
+ RETVAL = rpmPlatformScore(platform, NULL, 0);
+ platform = headerFreeData(platform, type);
+ } else if (pkg->info) {
+ char *arch;
+ char *eos;
+
+ get_fullname_parts(pkg, NULL, NULL, NULL, &arch, &eos);
+ *eos = 0;
+ platform = rpmExpand(arch, "-%{_real_vendor}-", eos, "%{?_gnu}", NULL);
+ RETVAL = rpmPlatformScore(platform, NULL, 0);
+ *eos = '@';
+ _free(platform);
+ } else {
+#else
+ croak("is_platform_compat() is availlable only since rpm 4.4.8");
+ { /* to match last } and avoid another #ifdef for it */
+#endif
+ RETVAL = 0;
+ }
+
+ OUTPUT:
+ RETVAL
+
void
Pkg_summary(pkg)
URPM::Package pkg
@@ -3636,6 +3670,19 @@ Urpm_import_pubkey(...)
OUTPUT:
RETVAL
+int
+Urpm_platformscore(platform)
+ const char * platform
+ CODE:
+#ifdef RPM_448
+ RETVAL=rpmPlatformScore(platform, NULL, 0);
+#else
+ croak("platformscore() is availlable only since rpm 4.4.8");
+ RETVAL=0
+#endif
+ OUTPUT:
+ RETVAL
+
void
Urpm_stream2header(fp)
FILE *fp
diff --git a/t/parse.t b/t/parse.t
index 2a3a8fd..f1788d2 100644
--- a/t/parse.t
+++ b/t/parse.t
@@ -4,7 +4,7 @@
use strict;
use warnings;
-use Test::More tests => 40;
+use Test::More tests => 41;
use MDV::Packdrakeng;
use URPM;
use URPM::Build;
@@ -72,6 +72,7 @@ is($pkg->get_tag(1001), '1.0', 'version');
is($pkg->get_tag(1002), '1mdk', 'release');
is($pkg->queryformat("%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}"), "test-rpm-1.0-1mdk.noarch",
q/get headers from hdlist/);
+ok($pkg->is_platform_compat() > 0, "can evaluate platform score");
my $headers = eval { [ $b->parse_rpms_build_headers(rpms => [ "RPMS/noarch/test-rpm-1.0-1mdk.noarch.rpm" ],
dir => 'headers') ] };