Fedora-App-MaintainerTools

 view release on metacpan or  search on metacpan

lib/Fedora/App/MaintainerTools/LocalRepo.pm  view on Meta::CPAN

# 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...');

	$self->update_local;
	$self->_push_new_files;
	$self->_push_new_metadata;

	# now, reset ourself...
	$self->_clear_files;
	$self->_clear_new_files;

	my $dir = $self->local_dir;
	return;
}

sub _push_new_files {
    my $self = shift @_;

    # push to reviewspace...
    #my $cmd = 'scp ' . join(q{ }, $self->files) . ' ' . $self->hostname . ":public_html/repo"; # $self->remote_loc;
    my $cmd = 'scp ' . join(q{ }, $self->new_files) . ' ' . $self->remote_target;

    say $cmd;
	$self->log->debug("Executing: $cmd");
    system $cmd;

	return;
}

__PACKAGE__->meta->make_immutable;

__END__

=head1 NAME

Fedora::App::MaintainerTools::LocalRepo - Maintain and work with a local YUM repo

=head1 DESCRIPTION



=head1 ATTRIBUTES

...

=head1 SEE ALSO

L<Fedora::App::MaintainerTools>

=head1 AUTHOR

Chris Weyl  <cweyl@alumni.drew.edu>

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2010 Chris Weyl <cweyl@alumni.drew.edu>

This library is free software; you can redistribute it and/or



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