Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #80 from softmoth/master
Factor out make-default-ecosystem() for external scripts
  • Loading branch information
Tadeusz Sośnierz committed Jun 16, 2014
2 parents 43822c6 + 035ffc6 commit 2714f9f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
37 changes: 2 additions & 35 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 Expand Up @@ -77,7 +44,7 @@ multi MAIN ('search', $pattern) {
}

END {
rm_rf '.work' if '.work'.IO.e;
rm_rf '.panda-work' if '.panda-work'.IO.e;
}

# vim: ft=perl6
2 changes: 1 addition & 1 deletion bin/redpanda
Expand Up @@ -27,7 +27,7 @@ sub get-meta($module is copy) {
}

sub MAIN($url) {
my $dir = '.work'.path.absolute;
my $dir = '.panda-work'.path.absolute;
rm_rf $dir;
try {
Panda::Fetcher::fetch($url, $dir);
Expand Down
2 changes: 1 addition & 1 deletion lib/Panda.pm
Expand Up @@ -9,7 +9,7 @@ use JSON::Tiny;

sub tmpdir {
state $i = 0;
".work/{time}_{$i++}".path.absolute
".panda-work/{time}_{$i++}".path.absolute
}

class Panda {
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 2714f9f

Please sign in to comment.