Fedora-App-MaintainerTools
view release on metacpan or search on metacpan
lib/Fedora/App/MaintainerTools/LocalRepo.pm view on Meta::CPAN
#############################################################################
#
# Author: Chris Weyl (cpan:RSRCHBOY), <cweyl@alumni.drew.edu>
# Company: No company, personal work
#
# Copyright (c) 2010 Chris Weyl <cweyl@alumni.drew.edu>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#############################################################################
package Fedora::App::MaintainerTools::LocalRepo;
use 5.010;
use Moose;
use MooseX::Types::Moose ':all';
use MooseX::Types::Path::Class ':all';
use MooseX::Types::URI ':all';
use autodie 'system';
use namespace::autoclean;
#use Fedora::App::MaintainerTools::Types ':all';
with 'MooseX::Log::Log4perl';
with 'MooseX::Traits';
use File::Copy 'cp';
use Path::Class;
our $VERSION = '0.006';
# debugging
use Smart::Comments '###', '####';
#############################################################################
# required
has name => (is => 'ro', required => 1, isa => Str);
has comment => (is => 'ro', required => 0, isa => Str);
has url => (is => 'ro', required => 1, isa => Uri, coerce => 1);
has remote_target => (is => 'ro', required => 1, isa => Str);
has local_dir => (is => 'ro', required => 1, isa => Dir, coerce => 1);
#############################################################################
# File (and old and new) tracking
# hmm.
my $arrayref_files_type = 'ArrayRef[' . File . ']';
has _files => (
#traits => [ 'Array' ], is => 'ro', isa => 'ArrayRef[File]', lazy_build => 1,
traits => [ 'Array' ], is => 'ro', isa => $arrayref_files_type, lazy_build => 1,
handles => {
files => 'elements',
has_files => 'is_empty',
file_count => 'count',
srpm_files => [ grep => sub { /\.src\.rpm$/ } ],
rpm_files => [ grep => sub { !/\.src\.rpm$/ } ],
},
);
has _new_files => (
#traits => [ 'Array' ], is => 'ro', isa => 'ArrayRef[File]', lazy_build => 1,
traits => [ 'Array' ], is => 'ro', isa => $arrayref_files_type, lazy_build => 1,
handles => {
new_files => 'elements',
has_new_files => 'count',
no_new_files => 'is_empty',
add_files => 'push',
},
);
has is_local_updated => (
traits => ['Bool'], is => 'ro', isa => Bool, lazy_build => 1,
handles => { _local_is_updated => 'set' },
);
has is_remote_updated => (
traits => ['Bool'], is => 'ro', isa => Bool, lazy_build => 1,
handles => { _remote_is_updated => 'set' },
);
sub _build__files { grep { !$_->is_dir && /\.rpm$/ } shift->local_dir->children }
sub _build__new_files { [ ] }
sub _build_is_local_updated { 0 }
sub _build_is_remote_updated { 0 }
#############################################################################
#
sub update_local {
my $self = shift @_;
my %opts = @_;
my $x = $self->_new_files;
### $x
return unless $self->has_new_files;
$self->log->info('Regenerating local metadata');
# get our dir, creating if needed
my $dir = $self->local_dir;
$dir->mkpath unless $dir->stat;
# copy files over...
cp "$_" => "$dir" for $self->new_files;
# regenerate local metadata
my $cmd = "cd $dir && createrepo --update .";
$self->log->debug("Executing: $cmd");
system $cmd;
return;
}
sub update_remote {
my $self = shift @_;
my %opts = @_;
$self->log->info('Updating local repo and pushing...');
( run in 2.470 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )