Permalink
Browse files

Merge pull request #80 from softmoth/master

Factor out make-default-ecosystem() for external scripts
  • Loading branch information...
2 parents 43822c6 + 035ffc6 commit 2714f9f7ffa9aaad5a87c32fed9a1c9b31ce076a @tadzik committed Jun 16, 2014
Showing with 37 additions and 37 deletions.
  1. +2 −35 bin/panda
  2. +1 −1 bin/redpanda
  3. +1 −1 lib/Panda.pm
  4. +33 −0 lib/Panda/App.pm
View
37 bin/panda
@@ -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(/^ <-[-]>/);
@@ -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
View
2 bin/redpanda
@@ -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);
View
2 lib/Panda.pm
@@ -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 {
View
33 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($_) };

0 comments on commit 2714f9f

Please sign in to comment.