summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-10-28 20:16:23 +0000
committerOlivier Blin <oblin@mandriva.com>2008-10-28 20:16:23 +0000
commit96b292695b3793e20ffc642c7cefa67cd3128448 (patch)
tree520aa285149a5bd88f2fd792eb88d07475afc2aa /lib
parent0378c0d6eae5fca0fb48d9e5a1475f6c25a29ca9 (diff)
downloaddraklive-96b292695b3793e20ffc642c7cefa67cd3128448.tar
draklive-96b292695b3793e20ffc642c7cefa67cd3128448.tar.gz
draklive-96b292695b3793e20ffc642c7cefa67cd3128448.tar.bz2
draklive-96b292695b3793e20ffc642c7cefa67cd3128448.tar.xz
draklive-96b292695b3793e20ffc642c7cefa67cd3128448.zip
move helpers in MDV::Draklive::Utils
Diffstat (limited to 'lib')
-rw-r--r--lib/MDV/Draklive/Utils.pm49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/MDV/Draklive/Utils.pm b/lib/MDV/Draklive/Utils.pm
new file mode 100644
index 0000000..e3e2e2b
--- /dev/null
+++ b/lib/MDV/Draklive/Utils.pm
@@ -0,0 +1,49 @@
+package MDV::Draklive::Utils;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(directory_usage run_ run_foreach);
+
+sub directory_usage { first(split /\s/, `du -sb $_[0]`) }
+
+#- expand only if the pattern contains '*'
+#- and matches dot characters (like shell dotglob)
+sub glob__ {
+ my ($pattern) = @_;
+ $pattern =~ /\*/ ? glob_($pattern) : $pattern;
+}
+
+sub run_ {
+ my $options = ref $_[0] eq 'HASH' ? shift @_ : {};
+ my @cmd = @_;
+ $options->{timeout} ||= 'never';
+ my $setarch = delete $options->{setarch};
+ unshift @cmd, 'setarch', $setarch if $setarch;
+ print STDERR "running " . (exists $options->{root} && "(in chroot) ") . join(' ', @cmd) . "\n";
+ run_program::raw($options, @cmd);
+}
+
+sub run_foreach {
+ my ($foreach, @command) = @_;
+ print STDERR "running " . join(' ', @command) . "\n";
+ my $pid = open3(my $cmd_in, my $cmd_out, undef, @command);
+ my $selector = IO::Select->new($cmd_out);
+ while (my @ready = $selector->can_read) {
+ foreach my $fh (@ready) {
+ local $_ = scalar<$fh>;
+ return if /^open3:/;
+ $foreach->();
+ $selector->remove($fh) if eof($fh);
+ }
+ }
+ close($cmd_out);
+ close($cmd_in);
+ return waitpid($pid, 0) > 0 && !($? >> 8);
+}
+
+sub mtools_run_ {
+ local $ENV{MTOOLS_SKIP_CHECK} = 1;
+ &run_;
+}
+
+1;