#!/usr/bin/perl # Batch EXecutor 3.0 -- Operations on Queues # (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; use BEX; my $init; sub usage() { print <] Subcommands: init Create a new queue ls List all queues Options: None defined so far. AMEN exit 0; } GetOptions( "init!" => \$init, "help" => \&usage, ) or die "Try `bex queue --help' for more information.\n"; my $op = shift @ARGV // 'ls'; if ($op eq 'init') { my $queue_name = shift @ARGV or die "bex queue init requires a queue name\n"; my $path = $BEX::Config::home . '/' . $queue_name; -d $path and die "Queue directory $path already exists\n"; mkdir $path; mkdir "$path/hosts"; mkdir "$path/jobs"; print "Queue $queue_name initialized.\n"; } elsif ($op eq 'ls' && @ARGV == 0) { opendir D, $BEX::Config::home or die "Cannot read BEX home directory\n"; for my $q (sort readdir D) { next if $q =~ /^\./; my $d = $BEX::Config::home . '/' . $q; if (-d $d && -d "$d/hosts" && -d "$d/jobs") { print "$q\n"; } } closedir D; } else { die "Invalid subcommand\n"; }