Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 17, 2012
Jeffrey Ryan Thalhammer You can now import a particular distribution. 76a04ff
Jeffrey Ryan Thalhammer Scratch one from the TODO. be83a16
Jeffrey Ryan Thalhammer Update change log. f6ff71c
View
11 Changes
@@ -1,5 +1,16 @@
{{$NEXT}}
+ New Features:
+
+ The "import" command will now import a particular distribution
+ if you specify it using the right notation. See POD for details
+ (Steven Leung).
+
+ Bug Fixes:
+
+ The Git store would fail if you specified the --root as a
+ relative path that contained any "../" updirs (William Wolf).
+
0.037 2012-04-10 19:57:09 America/Los_Angeles
No code changes. Just fixed dependency declarations.
View
5 TODO.pod
@@ -2,11 +2,6 @@
=over 4
-=item Support dist path and dist URL targets for Import action
-
-So that you can import a specific distribution, not just the
-latest distribution that contains a particular package.
-
=item Exception hierarchy/handling
Current regime is too complicated. Maybe just croak on any error,
View
47 lib/App/Pinto/Admin/Command/import.pm
@@ -41,8 +41,8 @@ sub usage_desc {
my ($command) = $self->command_names();
my $usage = <<"END_USAGE";
-%c --root=PATH $command [OPTIONS] PACKAGE_NAME ...
-%c --root=PATH $command [OPTIONS] < LIST_OF_PACKAGE_NAMES
+%c --root=PATH $command [OPTIONS] TARGET ...
+%c --root=PATH $command [OPTIONS] < LIST_OF_TARGETS
END_USAGE
chomp $usage;
@@ -58,12 +58,7 @@ sub execute {
return 0 if not @args;
$self->pinto->new_batch(%{$opts});
-
- for my $arg (@args) {
- my ($name, $version) = split m/ - /mx, $arg, 2;
- $self->pinto->add_action('Import', %{$opts}, package => $name,
- version => ($version || 0));
- }
+ $self->pinto->add_action($self->action_name, %{$opts}, target => $_) for @args;
my $result = $self->pinto->run_actions();
return $result->is_success() ? 0 : 1;
@@ -79,21 +74,21 @@ __END__
=head1 SYNOPSIS
- pinto-admin --root=/some/dir import [OPTIONS] PACKAGE_NAME ...
- pinto-admin --root=/some/dir import [OPTIONS] < LIST_OF_PACKAGE_NAMES
+ pinto-admin --root=/some/dir import [OPTIONS] TARGET ...
+ pinto-admin --root=/some/dir import [OPTIONS] < LIST_OF_TARGETS
=head1 DESCRIPTION
-This command locates a package on one of your remote repositories and
-then imports the distribution providing that package into your local
-repository. Then it recursively locates and imports all the
-distributions that provide the packages to satisfy the prerequisites
-for that distribution.
+This command locates a package in your upstream repositories and then
+imports the distribution providing that package into your repository.
+Then it recursively locates and imports all the distributions that are
+necessary to satisfy its prerequisites. You can also request to
+directly import a particular distribution.
When locating packages, Pinto first looks at the the packages that
already exist in the local repository, then Pinto looks at the
-packages that are available available on the remote repositories. At
-present, Pinto takes the *first* package it can find that satisfies
+packages that are available available on the upstream repositories.
+At present, Pinto takes the *first* package it can find that satisfies
the prerequisite. In the future, you may be able to direct Pinto to
instead choose the *latest* package that satisfies the prerequisite.
(NOT SURE THOSE LAST TWO STATEMENTS ARE TRUE).
@@ -107,23 +102,19 @@ higher version.
=head1 COMMAND ARGUMENTS
-To import a distribution that provides a particular package, just give
-the name of the package. For example:
-
- Foo::Bar
+Arguments are the targets that you want to import. Targets can be
+specified as packages (with or without a minimum version number) or
+as particular distributions. For example:
-To specify a minimum version for that package, append '-' and the
-minimum version number to the name. For example:
-
- Foo::Bar-1.2
+ Foo::Bar # Imports any version of Foo::Bar
+ Foo::Bar-1.2 # Imports Foo::Bar 1.2 or higher
+ SHAKESPEARE/King-Lear-1.2.tar.gz # Imports a specific distribuion
+ SHAKESPEARE/tragedies/Hamlet-4.2.tar.gz # Ditto, but from a subdirectory
You can also pipe arguments to this command over STDIN. In that case,
blank lines and lines that look like comments (i.e. starting with "#"
or ';') will be ignored.
-In the future, you may be able to specify distribution paths or
-specific URLs for import as well.
-
=head1 COMMAND OPTIONS
=over 4
View
11 lib/Pinto/Action/Import.pm
@@ -23,18 +23,11 @@ with qw( Pinto::Role::PackageImporter
#------------------------------------------------------------------------------
-# TODO: Allow the import target to be specified as a package/version,
-# dist path, or a particular URL. Then do the right thing for each.
-
-#------------------------------------------------------------------------------
-
sub execute {
my ($self) = @_;
- my $wanted = { name => $self->package(),
- version => $self->version() };
-
- my ($dist, $imported_flag) = $self->find_or_import( $wanted );
+ $DB::single = 1;
+ my ($dist, $imported_flag) = $self->find_or_import( $self->target );
return 0 if not $dist;
$self->add_message( Pinto::Util::imported_dist_message($dist) )
View
67 lib/Pinto/Role/PackageImporter.pm
@@ -4,10 +4,12 @@ package Pinto::Role::PackageImporter;
use Moose::Role;
+use Carp;
use Try::Tiny;
use Pinto::PackageExtractor;
use Pinto::Exceptions qw(throw_error);
+use Pinto::PackageSpec;
use Pinto::Util;
use namespace::autoclean;
@@ -50,26 +52,42 @@ sub _build_extractor {
#------------------------------------------------------------------------------
sub find_or_import {
- my ($self, $pkg_spec) = @_;
+ my ($self, $target) = @_;
- my ($pkg_name, $pkg_ver) = ($pkg_spec->{name}, $pkg_spec->{version});
- my $pkg_vname = "$pkg_name-$pkg_ver";
+ if ( $target->isa('Pinto::PackageSpec') ){
+ return $self->_import_by_package_spec($target);
+ }
+ elsif ($target->isa('Pinto::DistributionSpec') ){
+ return $self->_import_by_distribution_spec($target);
+ }
+ else {
+ my $type = ref $target;
+ confess "Don't know how to import $type";
+ }
+
+}
+
+#------------------------------------------------------------------------------
+
+sub _import_by_package_spec {
+ my ($self, $pspec) = @_;
- $self->info("Looking for package $pkg_vname");
+ $self->info("Looking for package $pspec");
+ my ($pkg_name, $pkg_ver) = ($pspec->name, $pspec->version);
my $where = {name => $pkg_name, is_latest => 1};
my $got_pkg = $self->repos->select_packages( $where )->single();
if ($got_pkg and $got_pkg->version() >= $pkg_ver) {
- $self->info("Already have package $pkg_vname or newer as $got_pkg");
+ $self->info("Already have package $pspec or newer as $got_pkg");
return ($got_pkg->distribution(), 0);
}
my $dist_url = $self->repos->cache->locate( package => $pkg_name,
version => $pkg_ver,
latest => 1 );
if ($dist_url) {
- $self->debug("Found package $pkg_vname or newer in $dist_url");
+ $self->debug("Found package $pspec or newer in $dist_url");
if ( Pinto::Util::isa_perl($dist_url) ) {
$self->debug("Distribution $dist_url is a perl. Skipping it.");
@@ -79,11 +97,44 @@ sub find_or_import {
return ($self->_import_distribution($dist_url), 1);
}
- throw_error "Cannot find $pkg_vname anywhere";
+ throw_error "Cannot find $pspec anywhere";
return;
}
+#------------------------------------------------------------------------------
+
+sub _import_by_distribution_spec {
+ my ($self, $dspec) = @_;
+
+ $self->info("Looking for distribution $dspec");
+
+ my $path = $dspec->path;
+ my $where = {path => $path};
+ my $got_dist = $self->repos->select_distributions( $where )->single();
+
+ if ($got_dist) {
+ $self->info("Already have distribution $dspec");
+ return ($got_dist, 0);
+ }
+
+ my $dist_url = $self->repos->cache->locate( distribution => $path );
+
+ if ($dist_url) {
+ $self->debug("Found package $dspec at $dist_url");
+
+ if ( Pinto::Util::isa_perl($dist_url) ) {
+ $self->debug("Distribution $dist_url is a perl. Skipping it.");
+ return;
+ }
+
+ return ($self->_import_distribution($dist_url), 1);
+ }
+
+ throw_error "Cannot find $dspec anywhere";
+
+ return;
+}
#------------------------------------------------------------------------------
@@ -165,7 +216,7 @@ sub _extract_prerequisites {
my @prereqs = try { $self->extractor->requires( archive => $archive ) }
catch { $self->error("Unable to extract prerequisites from $archive: $_"); () };
- return @prereqs;
+ return map { Pinto::PackageSpec->new($_) } @prereqs;
}
#------------------------------------------------------------------------------
View
42 t/24-import-dist.t
@@ -0,0 +1,42 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use Path::Class;
+use FindBin qw($Bin);
+
+use Pinto::Tester;
+
+#------------------------------------------------------------------------------
+# Fo this test, we're only using the 'b' repository...
+
+my $fakes = dir( $Bin, qw(data fakepan repos b) );
+my $source = URI->new("file://$fakes");
+my $auth_dir = $fakes->subdir( qw( authors id L LO LOCAL) );
+
+my $us = 'US'; # The local author
+my $them = 'LOCAL'; # Foreign author (used by CPAN::Faker)
+
+#------------------------------------------------------------------------------
+# Setup...
+
+my $t = Pinto::Tester->new( creator_args => {sources => "$source"} );
+my $pinto = $t->pinto();
+
+$t->repository_empty_ok();
+
+#------------------------------------------------------------------------------
+# Import by distribution spec (rather than by package spec)
+
+$pinto->new_batch();
+$pinto->add_action('Import', target => "$them/Salad-1.0.0.tar.gz");
+
+$t->result_ok( $pinto->run_actions() );
+$t->package_loaded_ok( "$them/Salad-1.0.0.tar.gz/Salad-1.0.0", 1);
+
+#------------------------------------------------------------------------------
+
+done_testing;
View
0 t/24-import-multi.t → t/25-import-multi.t
File renamed without changes.

No commit comments for this range

Something went wrong with that request. Please try again.