RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Olivier Thauvin
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   15-Aug-2007 04:59:59
  Branch: HEAD                             Handle: 2007081503595900

  Modified files:
    rpm/perl                RPM.pm RPM.xs
    rpm/perl/t              01.rpm.t

  Log:
    - clean a bit perl RPM module from old code

  Summary:
    Revision    Changes     Path
    1.6         +11 -2      rpm/perl/RPM.pm
    1.22        +42 -140    rpm/perl/RPM.xs
    1.2         +16 -1      rpm/perl/t/01.rpm.t
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/perl/RPM.pm
  ============================================================================
  $ cvs diff -u -r1.5 -r1.6 RPM.pm
  --- rpm/perl/RPM.pm   15 Aug 2007 00:46:07 -0000      1.5
  +++ rpm/perl/RPM.pm   15 Aug 2007 02:59:59 -0000      1.6
  @@ -3,15 +3,24 @@
   use 5.00503;
   use strict;
   use DynaLoader;
  +use Exporter;
   use Cwd qw/realpath/;
   use File::Basename qw/basename dirname/;
   use File::Spec ();
   
  -use vars qw/@ISA/;
  [EMAIL PROTECTED] = qw/DynaLoader/;
  +use vars qw/@ISA @EXPORT/;
  [EMAIL PROTECTED] = qw/DynaLoader Exporter/;
   
   bootstrap RPM;
   
  [EMAIL PROTECTED] = qw(
  +    rpmlog
  +    setlogcallback
  +    setlogfile
  +    lastlogmsg
  +    setverbosity
  +);
  +
   sub open_rpm_db {
     my $class = shift;
     my %params = @_;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/perl/RPM.xs
  ============================================================================
  $ cvs diff -u -r1.21 -r1.22 RPM.xs
  --- rpm/perl/RPM.xs   14 Aug 2007 17:25:10 -0000      1.21
  +++ rpm/perl/RPM.xs   15 Aug 2007 02:59:59 -0000      1.22
  @@ -22,16 +22,30 @@
   #include "rpmdb.h"
   #include "misc.h"
   
  -extern void _populate_header_tags(HV *href);
  +/* The perl callback placeholder for output err messages */
  +SV * log_callback_function = NULL;
   
  -static void
  -_populate_constant(HV *href, char *name, int val)
  -{
  -    hv_store(href, name, strlen(name), newSViv(val), 0);
  +/* This function is called by rpm if a callback
  + * is set for for the logging system.
  + * If the callback is set, rpm does not print any message,
  + * and let the callback to do it */
  +void logcallback(void) {
  +    dSP;
  +    if (log_callback_function) {
  +        int logcode = rpmlogCode();
  +        PUSHMARK(SP);
  +        XPUSHs(sv_2mortal(newSVpv("logcode", 0)));
  +        XPUSHs(sv_2mortal(newSViv(logcode)));
  +        XPUSHs(sv_2mortal(newSVpv("msg", 0)));
  +        XPUSHs(sv_2mortal(newSVpv(rpmlogMessage(), 0)));
  +        XPUSHs(sv_2mortal(newSVpv("priority", 0)));
  +        XPUSHs(sv_2mortal(newSViv(RPMLOG_PRI(logcode))));
  +        PUTBACK;
  +        call_sv(log_callback_function, G_DISCARD | G_SCALAR);
  +        SPAGAIN;
  +    }
   }
   
  -#define REGISTER_CONSTANT(name) _populate_constant(constants, #name, name)
  -
   MODULE = RPM         PACKAGE = RPM
   
   PROTOTYPES: ENABLE
  @@ -53,37 +67,7 @@
       crutch_stack_wrap(boot_RPM__Files(aTHX_ cv));
       crutch_stack_wrap(boot_RPM__Dependencies(aTHX_ cv)); 
       crutch_stack_wrap(boot_RPM__Spec(aTHX_ cv));
  -#if DYING
  -    {
  -     HV *header_tags, *constants; */
  -#endif
        rpmReadConfigFiles(NULL, NULL);
  -#if DYING
  -     header_tags = perl_get_hv("RPM::header_tag_map", TRUE);
  -     _populate_header_tags(header_tags);
  -
  -     constants = perl_get_hv("RPM::constants", TRUE);
  -
  -     /* not the 'standard' way of doing perl constants, but a lot easier to 
maintain */
  -     REGISTER_CONSTANT(RPMVSF_DEFAULT);
  -     REGISTER_CONSTANT(RPMVSF_NOHDRCHK);
  -     REGISTER_CONSTANT(RPMVSF_NEEDPAYLOAD);
  -     REGISTER_CONSTANT(RPMVSF_NOSHA1HEADER);
  -     REGISTER_CONSTANT(RPMVSF_NOMD5HEADER);
  -     REGISTER_CONSTANT(RPMVSF_NODSAHEADER);
  -     REGISTER_CONSTANT(RPMVSF_NORSAHEADER);
  -     REGISTER_CONSTANT(RPMVSF_NOSHA1);
  -     REGISTER_CONSTANT(RPMVSF_NOMD5);
  -     REGISTER_CONSTANT(RPMVSF_NODSA);
  -     REGISTER_CONSTANT(RPMVSF_NORSA);
  -     REGISTER_CONSTANT(_RPMVSF_NODIGESTS);
  -     REGISTER_CONSTANT(_RPMVSF_NOSIGNATURES);
  -     REGISTER_CONSTANT(_RPMVSF_NOHEADER);
  -     REGISTER_CONSTANT(_RPMVSF_NOPAYLOAD);
  -     REGISTER_CONSTANT(TR_ADDED);
  -     REGISTER_CONSTANT(TR_REMOVED);
  -    }
  -#endif
   
   #
   # Macro functions
  @@ -189,112 +173,30 @@
       RETVAL
   
   void
  +setlogcallback(function = NULL)
  +    SV * function
  +    CODE:
  +    if (function == NULL || !SvOK(function)) {
  +        if (log_callback_function) {
  +            SvREFCNT_dec(log_callback_function);
  +            log_callback_function = NULL;
  +        }
  +        rpmlogSetCallback(NULL);
  +    } else if (SvTYPE(SvRV(function)) == SVt_PVCV) {
  +        if (log_callback_function) {
  +            SvREFCNT_dec(log_callback_function);
  +            log_callback_function = NULL;
  +        }
  +        SvREFCNT_inc(function);
  +        log_callback_function = newSVsv(function);
  +        rpmlogSetCallback(logcallback);
  +    } else
  +        croak("First arg is not a code reference");
  +
  +void
   rpmlog(svcode, msg)
       SV * svcode
       char * msg
       CODE:
       rpmlog(sv2constant(svcode, "rpmlog"), "%s", msg);
   
  -#
  -# #
  -#
  -
  -void
  -_read_package_info(fp, vsflags)
  -     FILE *fp
  -     int vsflags
  -    PREINIT:
  -     rpmts ts;
  -     Header ret;
  -     rpmRC rc;
  -     FD_t fd;
  -    PPCODE:
  -     ts = rpmtsCreate();
  -
  -        /* XXX Determine type of signature verification when reading
  -     vsflags |= _RPMTS_VSF_NOLEGACY;
  -     vsflags |= _RPMTS_VSF_NODIGESTS;
  -     vsflags |= _RPMTS_VSF_NOSIGNATURES;
  -     xx = rpmtsSetVerifySigFlags(ts, vsflags);
  -        */ 
  -
  -     fd = fdDup(fileno(fp));
  -     rpmtsSetVSFlags(ts, vsflags);
  -     rc = rpmReadPackageFile(ts, fd, "filename or other identifier", &ret);
  -
  -     Fclose(fd);
  -
  -     if (rc == RPMRC_OK) {
  -         SV *h_sv;
  -
  -         EXTEND(SP, 1);
  -
  -         h_sv = sv_newmortal();
  -            sv_setref_pv(h_sv, "RPM::C::Header", (void *)ret);
  -
  -         PUSHs(h_sv);
  -     }
  -     else {
  -         croak("error reading package");
  -     }
  -     ts = rpmtsFree(ts);
  -
  -void
  -_create_transaction(vsflags)
  -     int vsflags
  -    PREINIT:
  -     rpmts ret;
  -     SV *h_sv;
  -    PPCODE:
  -     /* Looking at librpm, it does not look like this ever
  -        returns error (though maybe it should).
  -     */
  -     ret = rpmtsCreate();
  -
  -     /* Should I save the old vsflags aside? */
  -     rpmtsSetVSFlags(ret, vsflags);
  -
  -     /* Convert and throw the results on the stack */        
  -     EXTEND(SP, 1);
  -
  -     h_sv = sv_newmortal();
  -     sv_setref_pv(h_sv, "RPM::C::Transaction", (void *)ret);
  -
  -     PUSHs(h_sv);
  -
  -void
  -_read_from_file(fp)
  -     FILE *fp
  -PREINIT:
  -     SV *h_sv;
  -     FD_t fd;
  -     Header h;
  -PPCODE:
  -     fd = fdDup(fileno(fp));
  -     h = headerRead(fd);
  -
  -     if (h) {
  -         EXTEND(SP, 1);
  -
  -         h_sv = sv_newmortal();
  -         sv_setref_pv(h_sv, "RPM::C::Header", (void *)h);
  -
  -         PUSHs(h_sv);
  -     }
  -     Fclose(fd);
  -
  -
  -rpmdb
  -_open_rpm_db(for_write)
  -     int   for_write
  -    PREINIT:
  -      rpmdb db;
  -    CODE:
  -     if (rpmdbOpen(NULL, &db, for_write ? O_RDWR | O_CREAT : O_RDONLY, 
0644)) {
  -             croak("rpmdbOpen failed");
  -             RETVAL = NULL;
  -     }
  -     RETVAL = db;            
  -    OUTPUT:
  -     RETVAL
  -
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/perl/t/01.rpm.t
  ============================================================================
  $ cvs diff -u -r1.1 -r1.2 01.rpm.t
  --- rpm/perl/t/01.rpm.t       4 Aug 2007 02:19:56 -0000       1.1
  +++ rpm/perl/t/01.rpm.t       15 Aug 2007 02:59:59 -0000      1.2
  @@ -2,9 +2,24 @@
   
   use strict;
   
  -use Test::More tests => 3;
  +use Test::More tests => 11;
   
   use_ok('RPM');
   like(RPM::expand_macro('%{?_rpmversion}%{?!_rpmversion:ver}'), '/^[^%]/', 
"can expand %_rpmversion macro");
   RPM::add_macro('_test_macro I_am_set');
   is(RPM::expand_macro('%_test_macro'), 'I_am_set', 'setting a marco works');
  +
  +can_ok('RPM', qw(rpmlog setlogcallback setlogfile lastlogmsg setverbosity));
  +ok(!rpmlog('DEBUG', 'test message'), "can rpmlog()");
  +
  +{
  +ok(!setverbosity('debug'), "can set verbosity");
  +my $logcall = 0;
  +ok(!setlogcallback(sub { $logcall++ }), "can set log callback");
  +rpmlog('WARNING', 'test message');
  +is($logcall, 1, "log callback is really call");
  +ok(!setlogcallback(), "can reset logcallback");
  +ok(!setverbosity('WARNING'), "can set verbosity");
  +is($logcall, 1, "log callback is no longer call");
  +}
  +
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to