From 3d1a4c165264b3d9876fb84cca2ce6335c264b97 Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Wed, 4 Jul 2007 15:53:30 +0000 Subject: - add Pkg_is_platform_compat() and Urpm_platformscore() coming with rpm 4.4.8 --- URPM.pm | 11 +++++++++++ URPM.xs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- t/parse.t | 3 ++- 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') ] }; -- cgit v1.2.1