ALPM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

   |----------------+--------------|
   | Removed Method | "New" Method |
   |----------------+--------------|
   | register_db    | register     |
   | transaction    | trans        |
   | action         | trans        |
   | databases      | dbs          |
   | repodb         | db           |
   |----------------+--------------|

** New Changelog Format
   Ditched the old GNU-style ChangeLog format for an org-mode file. Old
   ChangeLog entries are at the end of the file...

* Previous Releases

2011-03-05  Justin Davis  <juster@cpan.org>

	* RELEASE (1.03)

	* t: Fix many tests that rely on English language error messages.

README  view on Meta::CPAN

ALPM 3.06

INTRODUCTION

This is a perl XS module which provides an interface to the libalpm C library.
libalpm is used by Archlinux (and other distributions) who use pacman as the
package managing program.

Read-only access is provided to the database. All transaction creation logic
was removed from this module. After each major pacman upgrade, and sub-
sequent libalpm API change, I would be forced to rewrite a majority of this
module. After the third or fourth time I decided it was not worth the effort
for a feature possibly no one uses in an obscure perl module no one knows
about.

If you really need transactions why not call pacman with "system" or
backticks? In contrast, complicated queries becomes ugly and convoluted
when calling pacman in shell scripts. With the aid of this module, queries
should instead be possible in the quintessential ugly and succinct perl form.

alpm_xs.h  view on Meta::CPAN

#ifndef ALPM_XS_H
#define ALPM_XS_H

/* Code references to use as callbacks. */
extern SV *cb_log_sub;
extern SV *cb_dl_sub;
extern SV *cb_totaldl_sub;
extern SV *cb_fetch_sub;

/* transactions */
extern SV *cb_trans_event_sub;
extern SV *cb_trans_conv_sub;
extern SV *cb_trans_progress_sub;

/* String constants to use for log levels (instead of bitflags) */
extern const char * log_lvl_error;
extern const char * log_lvl_warning;
extern const char * log_lvl_debug;
extern const char * log_lvl_function;
extern const char * log_lvl_unknown;

/* CALLBACKS ****************************************************************/

#define DEF_SET_CALLBACK( CBTYPE )                                  \
    if ( ! SvOK(callback) && cb_ ## CBTYPE ## _sub != NULL ) {      \
        SvREFCNT_dec( cb_ ## CBTYPE ## _sub );                      \
        alpm_option_set_ ## CBTYPE ## cb( NULL );                   \
        cb_ ## CBTYPE ## _sub = NULL;                               \
    }                                                               \
    else {                                                          \

alpm_xs.h  view on Meta::CPAN

            cb_ ## CBTYPE ## _sub = newSVsv(callback);              \
            alpm_option_set_ ## CBTYPE ## cb                        \
                ( cb_ ## CBTYPE ## _wrapper );                      \
        }                                                           \
    }

#define DEF_GET_CALLBACK( CBTYPE )                          \
    RETVAL = ( cb_ ## CBTYPE ## _sub == NULL                \
               ? &PL_sv_undef : cb_ ## CBTYPE ## _sub );

void cb_log_wrapper ( alpm_loglevel_t level, const char * format, va_list args );
void cb_dl_wrapper ( const char *filename, off_t xfered, off_t total );
void cb_totaldl_wrapper ( off_t total );
int  cb_fetch_wrapper ( const char *url, const char *localpath, int force );

/* TRANSACTIONS ************************************************************/

/* This macro is used inside alpm_trans_init.
   CB_NAME is one of the transaction callback types (event, conv, progress).

   * [CB_NAME]_sub is the argument to the trans_init XSUB.

cb.c  view on Meta::CPAN

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"

#include <alpm.h>
#include "cb.h"

SV * logcb_ref, * dlcb_ref, * totaldlcb_ref, * fetchcb_ref;

void c2p_logcb(alpm_loglevel_t lvl, const char * fmt, va_list args)
{
	SV * svlvl, * svmsg;
	const char *str;
	char buf[256];
	dSP;

	if(!logcb_ref) return;

	/* convert log level bitflag to a string */
	switch(lvl){
	case ALPM_LOG_ERROR: str = "error"; break;
	case ALPM_LOG_WARNING: str = "warning"; break;
	case ALPM_LOG_DEBUG: str = "debug"; break;
	case ALPM_LOG_FUNCTION: str = "function"; break;
	default: str = "unknown"; break;
	}

	ENTER;
	SAVETMPS;

cb.c  view on Meta::CPAN

	/* We can't use sv_vsetpvfn because it doesn't like j's: %jd or %ji, etc... */
	svlvl = sv_2mortal(newSVpv(str, 0));
	vsnprintf(buf, 255, fmt, args);
	svmsg = sv_2mortal(newSVpv(buf, 0));
	
	PUSHMARK(SP);
	XPUSHs(svlvl);
	XPUSHs(svmsg);
	PUTBACK;

	call_sv(logcb_ref, G_DISCARD);

	FREETMPS;
	LEAVE;
	return;
}

void
c2p_dlcb(const char * name, off_t curr, off_t total)
{
	SV * svname, * svcurr, * svtotal;

cb.h  view on Meta::CPAN

		if(!SvROK(ARG) || SvTYPE(SvRV(ARG)) != SVt_PVCV){\
			croak("value for " #TYPE "cb option must be a code reference");\
		}else if(TYPE##cb_ref){\
			sv_setsv(TYPE##cb_ref, ARG);\
		}else{\
			TYPE##cb_ref = newSVsv(ARG);\
			alpm_option_set_##TYPE##cb(HND, c2p_##TYPE##cb);\
		}\
	}

extern SV * logcb_ref, * dlcb_ref, * totaldlcb_ref, * fetchcb_ref;

void c2p_logcb(alpm_loglevel_t, const char *, va_list);
void c2p_dlcb(const char *, off_t, off_t);
int c2p_fetchcb(const char *, const char *, int);
void c2p_totaldlcb(off_t);

#endif

lib/ALPM.pod  view on Meta::CPAN

3.06

This version of ALPM is compatible with pacman 4.

=head1 SYNOPSIS

  ## We can start by setting options all by ourselves.
  use ALPM;
  my $alpm = ALPM->new('/', '/var/lib/db'); # root and dbpath
  $alpm->set_cachedirs('/var/cache/pacman/pkg');
  $alpm->set_logfile('/var/log/pacman.log');
  
  ## Or use ALPM::Conf, a handy module for pacman.conf parsing.
  use ALPM::Conf qw(/etc/pacman.conf);
  ## ALPM::Conf loads an object into "our" package variable.
  our $alpm;
  
  ## Querying databases & packages
  my $localdb = $alpm->localdb;
  my $pkg = $localdb->find('perl') or die 'wtfbbq';
  printf "%s %s %s %d\n", $pkg->name, $pkg->version,

lib/ALPM.pod  view on Meta::CPAN

ALPM has a number of options corresponding to the
C<alpm_option_get_...> and C<alpm_option_set...> C functions in the
library.  Options which take multiple values (hint: they have a plural
name) accept multiple arguments in the corresponding methods.
Similarly the same options return a list.

=head2 Read-write options

=over

=item B<logfile> - path to the pacman logfile

=item B<arch> - the machine architecture to use

=item B<gpgdir> - path to gpg stuff

=item B<cachedirs>* - paths containing package caches

=item B<noupgrades>* - a list of package names to not upgrade

=item B<noextracts>* - a list of package names to not extract

=item B<assumeinstalled>* - a list of dependencies to assume are satisfied.
The setter methods take either a dependency hash or a string representing
a dependency.  The accessor returns a list of dependency hash references.

=item B<ignorepkgs>* - a list of package names to ignore for upgrade

=item B<ignoregroups>* - a list of groups to ignore for upgrade

=item B<usesyslog> - if true, log to the system log as well

=item B<deltaratio> - accepts a decimal from 0 to 1

=item B<checkspace> - check for available diskspace

=item B<defsiglvl> - the default signature level. See L</Signature Level>.
This name was shortened from I<alpm_option_set_default_signature_level>.
You're welcome.

=back

lib/ALPM.pod  view on Meta::CPAN

=item B<lockfile> - path to the lockfile

=back

  * = the option is set with (and gets you) a list

=head2 Callback options

Callbacks can only be set to code references.

=head3 logcb - Generic logging

The log level and message are passed to the provided code ref as
arguments.

=over 4

=item 1. level

This is one of the following strings: error, warning, debug, function, or unknown.

=item 2. message

lib/ALPM/Conf.pm  view on Meta::CPAN

			'Server' => sub { _addmirror($dbsref, shift, $$sectref) }
		},
	 };
}

my %CFGOPTS = (
	'RootDir' => 'root',
	'DBPath' => 'dbpath',
	'CacheDir' => 'cachedirs',
	'GPGDir' => 'gpgdir',
	'LogFile' => 'logfile',
	'UseSyslog' => 'usesyslog',
	'UseDelta' => 'usedelta',
	'CheckSpace' => 'checkspace',
	'IgnorePkg' => 'ignorepkgs',
	'IgnoreGroup' => 'ignoregrps',
	'NoUpgrade' => 'noupgrades',
	'NoExtract' => 'noextracts',
	'NoPassiveFtp' => 'nopassiveftp',
	'Architecture' => 'arch',
);

lib/ALPM/Package.pod  view on Meta::CPAN

=item * replaces

=item * files

=item * backup

=item * has_scriptlet

=item * download_size

=item * changelog

=item * requiredby

=item * optionalfor

=item * db

=item * checkmd5sum

=item * origin

ppport.h  view on Meta::CPAN

=item 2.

This file.

=item 3.

The name and version of the module you were trying to build.

=item 4.

A full log of the build that failed.

=item 5.

Any other information that you think could be relevant.

=back

For the latest version of this code, please get the C<Devel::PPPort>
module from CPAN.

ppport.h  view on Meta::CPAN

make_trie|||
malloc_good_size|||n
malloced_size|||n
malloc||5.007002|n
markstack_grow|||
matcher_matches_sv|||
measure_struct|||
memEQ|5.004000||p
memNE|5.004000||p
mem_collxfrm|||
mem_log_common|||n
mess_alloc|||
mess_nocontext|||vn
mess||5.006000|v
method_common|||
mfree||5.007002|n
mg_clear|||
mg_copy|||
mg_dup|||
mg_find|||
mg_free|||

ppport.h  view on Meta::CPAN

newUNOP|||
newWHENOP||5.009003|
newWHILEOP||5.009003|
newXS_flags||5.009004|
newXSproto||5.006000|
newXS||5.006000|
new_collate||5.006000|
new_constant|||
new_ctype||5.006000|
new_he|||
new_logop|||
new_numeric||5.006000|
new_stackinfo||5.005000|
new_version||5.009000|
new_warnings_bitfield|||
next_symbol|||
nextargv|||
nextchar|||
ninstr|||
no_bareword_allowed|||
no_fh_allowed|||

t/00-ALPM.t  view on Meta::CPAN


$r = 't/root';
$alpm = ALPM->new($r, "$r/db");
ok $alpm;

ok $alpm->version; # just checks it works
@caps = $alpm->caps;

%opts = (
	'arch' => 'i686',
	'logfile' => "$r/log",
	'gpgdir' => "$r/gnupg",
	'cachedirs' => [ "$r/cache/" ], # needs trailing slash
	'noupgrades' => [ 'foo' ],
	'noextracts' => [ 'bar' ],
	'ignorepkgs' => [ 'baz' ],
	'ignoregroups' => [ 'core' ],
	'usesyslog' => 0,
	'deltaratio' => 0.5,
	'checkspace' => 1,
);

sub meth
{
	my $name = shift;
	my $m = *{"ALPM::$name"}{CODE} or die "missing $name method";
	my @ret = eval { $m->($alpm, @_) };
	if($@){ die "method call to $name failed: $@" }

t/03-Package.t  view on Meta::CPAN

                    conflicts provides deltas replaces
                    files backup };

for my $mname (@methnames) {
    my $method_ref = $ALPM::Package::{$mname};
    ok $method_ref, "$mname is a package method";
    my $result = $method_ref->($pkg);
    ok defined $result, "$mname has a defined value";
}

ok defined $pkg->changelog;

done_testing;

t/05-Callbacks.t  view on Meta::CPAN

use Test::More;
use ALPM::Conf 't/test.conf';

ok !defined $alpm->get_logcb;
$cb = sub { print "LOG: @_" };
die 'internal error' unless(ref($cb) eq 'CODE');
$alpm->set_logcb($cb);

$tmp = $alpm->get_logcb($cb);
is ref($tmp), 'CODE';
ok $tmp eq $cb;

$alpm->set_logcb(undef);
ok !defined $alpm->get_logcb;

done_testing;

t/preptests.pl  view on Meta::CPAN

sub createconf
{
	my($path, $root, $repos) = @_;
	open my $of, '>', $path
		or die "failed to open t/test.conf file: $!";
	print $of <<"END_CONF";
[options]
RootDir = $root
DBPath = $root/db
CacheDir = $root/cache
LogFile = $root/test.log
#GPGDir      = $root/gnupg/
HoldPkg     = pacman glibc
SyncFirst   = pacman
#XferCommand = /usr/bin/curl -C - -f %u > %o
#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
CleanMethod = KeepInstalled
Architecture = auto

# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
#IgnorePkg   =
#IgnoreGroup =

#NoUpgrade   =
#NoExtract   =

# Misc options
#UseSyslog
#UseDelta
#TotalDownload
CheckSpace
#VerbosePkgLists

# PGP signature checking
SigLevel = Optional

END_CONF

xs/Options.xs  view on Meta::CPAN

MODULE = ALPM	PACKAGE = ALPM

## CALLBACKS

SV*
get_logcb(...)
 CODE:
	RETVAL = (logcb_ref ? newSVsv(logcb_ref) : &PL_sv_undef);
 OUTPUT:
	RETVAL

SV*
get_dlcb(...)
 CODE:
	RETVAL = (dlcb_ref ? newSVsv(dlcb_ref) : &PL_sv_undef);
 OUTPUT:
	RETVAL

xs/Options.xs  view on Meta::CPAN

SV*
get_totaldlcb(...)
 CODE:
	RETVAL = (totaldlcb_ref ? newSVsv(totaldlcb_ref) : &PL_sv_undef);
 OUTPUT:
	RETVAL

MODULE = ALPM	PACKAGE = ALPM	PREFIX = alpm_option_

void
alpm_option_set_logcb(self, cb)
	ALPM_Handle self
	SV * cb
 CODE:
	DEFSETCB(log, self, cb)

void
alpm_option_set_dlcb(self, cb)
	ALPM_Handle self
	SV * cb
 CODE:
	DEFSETCB(dl, self, cb)

void
alpm_option_set_fetchcb(self, cb)

xs/Options.xs  view on Meta::CPAN

	SV * cb
 CODE:
	DEFSETCB(totaldl, self, cb)

## REGULAR OPTIONS

StringOption
option_string_get(self)
	ALPM_Handle self
 INTERFACE:
	alpm_option_get_logfile
	alpm_option_get_lockfile
	alpm_option_get_arch
	alpm_option_get_gpgdir
	alpm_option_get_root
	alpm_option_get_dbpath

SetOption
option_string_set(self, string)
	ALPM_Handle self
	const char * string
 INTERFACE:
	alpm_option_set_logfile
	alpm_option_set_arch
	alpm_option_set_gpgdir

# String List Options

void
alpm_option_get_cachedirs(self)
	ALPM_Handle self
 PREINIT:
	alpm_list_t *lst;

xs/Options.xs  view on Meta::CPAN

	alpm_option_remove_cachedir
	alpm_option_remove_noupgrade
	alpm_option_remove_noextract
	alpm_option_remove_ignorepkg
	alpm_option_remove_ignoregroup

IntOption
option_int_get(self)
	ALPM_Handle self
INTERFACE:
	alpm_option_get_usesyslog
	alpm_option_get_checkspace

SetOption
option_int_set(self, new_int)
	ALPM_Handle self
	int new_int
INTERFACE:
	alpm_option_set_usesyslog
	alpm_option_set_checkspace

double
alpm_option_get_deltaratio(self)
	ALPM_Handle self

SetOption
alpm_option_set_deltaratio(self, ratio)
	ALPM_Handle self
	double ratio

xs/Package.xs  view on Meta::CPAN


const char *
signature(pkg)
	ALPM_Package pkg
 CODE:
	RETVAL = alpm_pkg_get_base64_sig(pkg);
 OUTPUT:
	RETVAL

SV *
changelog(pkg)
	ALPM_Package pkg
 PREINIT:
	void *fp;
	char buffer[128];
	size_t bytes_read;
	SV *changelog_txt;
 CODE:
	changelog_txt = newSVpv("", 0);
	RETVAL = changelog_txt;

	fp = alpm_pkg_changelog_open(pkg);
	if(fp){
		while(1){
			bytes_read = alpm_pkg_changelog_read((void *)buffer, 128,
												  pkg, fp);
			/*fprintf(stderr,"DEBUG: read %d bytes of changelog\n", */
			/*		  bytes_read); */
			if(bytes_read == 0) break;
			sv_catpvn(changelog_txt, buffer, bytes_read);
		}
		alpm_pkg_changelog_close(pkg, fp);
	}
 OUTPUT:
	RETVAL

MODULE=ALPM    PACKAGE=ALPM::Package    PREFIX=alpm_pkg_compute_

StringListFree
pkg_compute(pkg)
	ALPM_Package pkg
 INTERFACE:



( run in 1.935 second using v1.01-cache-2.11-cpan-49f99fa48dc )