Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Define make-default-ecosystem in Panda::App
Enable Panda::App to be used by other tools to set up the same
ecosystem that bin/panda uses.
  • Loading branch information
softmoth committed May 9, 2014
1 parent abafd49 commit da6558d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
35 changes: 1 addition & 34 deletions bin/panda
Expand Up @@ -8,40 +8,7 @@ use Panda::App;
if %*ENV<PANDA_DEFAULT_OPTS> {
@*ARGS = %*ENV<PANDA_DEFAULT_OPTS> ~ (@*ARGS ?? ' ' ~ @*ARGS !! '');
}

# initialize the Panda object
my $panda;
{
my $pandadir;
my $destdir = %*ENV<DESTDIR>;
$destdir = "{cwd}/$destdir" if defined($destdir) && $*OS ne 'MSWin32' && $destdir !~~ /^ '/' /;
for grep(*.defined, $destdir, %*CUSTOM_LIB<site home>) -> $prefix {
$destdir = $prefix;
$pandadir = "$prefix/panda";
try mkpath $pandadir unless $pandadir.IO ~~ :d;
last if $pandadir.path.w
}
unless $pandadir.path.w {
die "Found no writable directory into which panda could be installed";
}

my @extra-statefiles;
unless $destdir eq %*CUSTOM_LIB<site> {
for grep(*.defined, $destdir, %*CUSTOM_LIB<site home>) -> $prefix {
unless $destdir eq $prefix {
@extra-statefiles.push("$prefix/panda/state");
}
}
}

my $ecosystem = Panda::Ecosystem.new(
statefile => "$pandadir/state",
projectsfile => "$pandadir/projects.json",
extra-statefiles => @extra-statefiles
);

$panda = Panda.new(:$ecosystem);
}
my $panda = Panda.new(:ecosystem(make-default-ecosystem));

# allow switches after positionals
@*ARGS = @*ARGS.grep(/^ '-'/), @*ARGS.grep(/^ <-[-]>/);
Expand Down
33 changes: 33 additions & 0 deletions lib/Panda/App.pm
@@ -1,6 +1,39 @@
module Panda::App;
use Shell::Command;
use Panda::Ecosystem;
use Panda::Project;

# initialize the Panda object
sub make-default-ecosystem is export {
my $pandadir;
my $destdir = %*ENV<DESTDIR>;
$destdir = "{cwd}/$destdir" if defined($destdir) && $*OS ne 'MSWin32' && $destdir !~~ /^ '/' /;
for grep(*.defined, $destdir, %*CUSTOM_LIB<site home>) -> $prefix {
$destdir = $prefix;
$pandadir = "$prefix/panda";
try mkpath $pandadir unless $pandadir.IO ~~ :d;
last if $pandadir.path.w
}
unless $pandadir.path.w {
die "Found no writable directory into which panda could be installed";
}

my @extra-statefiles;
unless $destdir eq %*CUSTOM_LIB<site> {
for grep(*.defined, $destdir, %*CUSTOM_LIB<site home>) -> $prefix {
unless $destdir eq $prefix {
@extra-statefiles.push("$prefix/panda/state");
}
}
}

return Panda::Ecosystem.new(
statefile => "$pandadir/state",
projectsfile => "$pandadir/projects.json",
extra-statefiles => @extra-statefiles
);
}

sub listprojects($panda, :$installed, :$verbose) is export {
my $es = $panda.ecosystem;
my @projects = $es.project-list.sort.map: { $es.get-project($_) };
Expand Down

0 comments on commit da6558d

Please sign in to comment.