App-Magpie

 view release on metacpan or  search on metacpan

lib/App/Magpie/Action/WebStatic.pm  view on Meta::CPAN

        start => DateTime->new(year=>2012)->epoch,
        draw  => {
            thickness => 2,
            color     => '0000FF',
        },
        units_exponent => 0,
    );

    # template toolkit
    $self->log_debug( "template toolkit processing" );
    my $tt = Template->new({
        INCLUDE_PATH => $SHAREDIR->child("webstatic"),
        INTERPOLATE  => 1,
    }) or die "$Template::ERROR\n";

    my $vars = {
        mgamods  => $mgamods,
        mgadists => $nbmgadists,
        date     => scalar localtime,
    };
    $tt->process('index.tt2', $vars, $dir->child("index.html")->stringify)
        or die $tt->error(), "\n";

    # rrd files
    $self->log_debug( "copying rrd files" );
    my $rrdsubdir = $dir->child( "rrds" );
    $rrdsubdir->mkpath;
    foreach my $f ( keys %rrdfile ) {
        copy( $rrdfile{$f}->stringify, $rrdsubdir->stringify );
    }

    # update website in one pass: remove previous version, replace it by new one
    $self->log( "** updating web site" );
    my $olddir = path( $opts->{directory} );
    $olddir->remove_tree( { safe => 0 } );
    move( $dir->stringify, $olddir->stringify );
}


# -- private methods

sub _migrate_and_create_rrds_if_needed {
    my $self = shift;
    $rrdsdir->mkpath;

    # v0 - too bad, drop existing files
    my $rrdfile = $datadir->child( "modules.rrd" );
    if ( -e $rrdfile ) {
        $self->log( "converting from v0" );
        $self->log_debug( "removing $rrdfile" );
        $rrdfile->remove
    }

    # create rrds
    $self->log("creating rrd files");
    foreach my $f ( keys %rrdfile ) {
        $rrd{$f} = RRDTool::OO->new( file=>$rrdfile{$f} );
        next if -f $rrdfile{$f};
        $self->log_debug( "creating $rrdfile{$f}" );
        $rrd{$f}->create(
            step        => 60*60*24,            # 1 measure per day
            data_source => {
                name => "nb",
                type => "GAUGE",
            },
            archive => { rows => 365 * 100 },   # data kept for 100 years (!)
        );
    }

    # saving rrd schema version
    $self->log_debug( "saving schema version" );
    my $fh = $rrdvers->openw;
    $fh->print( "1" );
    $fh->close;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::Magpie::Action::WebStatic - webstatic command implementation

=head1 VERSION

version 2.010

=head1 SYNOPSIS

    my $webstatic = App::Magpie::Action::WebStatic->new;
    $webstatic->run;

=head1 DESCRIPTION

This module implements the C<webstatic> action. It's in a module of its
own to be able to be C<require>-d without loading all other actions.

=head1 METHODS

=head2 run

    App::Magpie::Action::WebStatic->new->run( $opts );

Update the count of available modules in Mageia, and create a static
website with some information on them.

=head1 AUTHOR

Jerome Quelin <jquelin@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Jerome Quelin.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.



( run in 2.028 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )