From d8250bd26578871e624d5e513ff7919f37357fe2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 15 Feb 2012 21:22:16 +0100 Subject: [PATCH] The big move -- introduced subcommands --- BEX.cf => BEX/config | 0 epilog => BEX/epilog | 0 prolog => BEX/prolog | 0 bex | 51 ++++++++++++++++++++++++++++++++++++ benq => lib/bin/add | 6 ++--- bjob => lib/bin/job | 6 ++--- bls => lib/bin/ls | 6 ++--- bprun => lib/bin/prun | 7 ++--- bq => lib/bin/queue | 6 ++--- brun => lib/bin/run | 6 ++--- lib/{ => perl}/BEX.pm | 4 +-- lib/{ => perl}/BEX/Config.pm | 15 +++++++---- lib/{ => perl}/BEX/Job.pm | 4 +-- lib/{ => perl}/BEX/Queue.pm | 4 +-- 14 files changed, 79 insertions(+), 36 deletions(-) rename BEX.cf => BEX/config (100%) rename epilog => BEX/epilog (100%) rename prolog => BEX/prolog (100%) create mode 100755 bex rename benq => lib/bin/add (96%) rename bjob => lib/bin/job (84%) rename bls => lib/bin/ls (86%) rename bprun => lib/bin/prun (98%) rename bq => lib/bin/queue (97%) rename brun => lib/bin/run (98%) rename lib/{ => perl}/BEX.pm (60%) rename lib/{ => perl}/BEX/Config.pm (85%) rename lib/{ => perl}/BEX/Job.pm (96%) rename lib/{ => perl}/BEX/Queue.pm (98%) diff --git a/BEX.cf b/BEX/config similarity index 100% rename from BEX.cf rename to BEX/config diff --git a/epilog b/BEX/epilog similarity index 100% rename from epilog rename to BEX/epilog diff --git a/prolog b/BEX/prolog similarity index 100% rename from prolog rename to BEX/prolog diff --git a/bex b/bex new file mode 100755 index 0000000..ac89512 --- /dev/null +++ b/bex @@ -0,0 +1,51 @@ +#!/usr/bin/perl +# Batch EXecutor 3.0 -- Master Program +# (c) 2012 Martin Mares + +use strict; +use warnings; +use Getopt::Long; + +my $bex_home = $ENV{"BEX_HOME"} // "."; +my $bex_lib = $ENV{"BEX_LIB"} // "lib"; + +Getopt::Long::Configure('require_order'); +GetOptions( + "home=s" => \$bex_home, + "lib=s" => \$bex_lib, + "help" => sub { + print "Usage: brum\n"; + exit 0; + }, + "version" => sub { + print "BEX 3.0 (c) 2011-2012 Martin Mares \n"; + }, +) or die "Try `bex --help' for more information.\n"; +Getopt::Long::Configure('default'); + +if (!-d $bex_home) { + die "BEX home directory $bex_home does not exist.\n"; +} +if (!-d "$bex_home/BEX") { + die "BEX home directory $bex_home does not contain the BEX subdirectory.\n"; +} + +@ARGV or die "Missing subcommand.\n"; +my $sub = shift @ARGV; +$sub =~ /^[0-9a-zA-Z]+$/ or die "Invalid subcommand $sub\n"; + +my %aliases = ( + 'a' => 'add', + 'q' => 'queue', + 'r' => 'run', +); +if (defined $aliases{$sub}) { $sub = $aliases{$sub}; } + +my $sub_path = "$bex_lib/bin/$sub"; +-x $sub_path or die "Unknown subcommand $sub\n"; + +$ENV{"BEX_HOME"} = $bex_home; +$ENV{"BEX_LIB"} = $bex_lib; +$ENV{"PERL5LIB"} = join(":", $bex_lib . "/perl", $ENV{"PERL5LIB"} // ()); +exec $sub_path, @ARGV; +die "Cannot execute $sub_path: $!\n"; diff --git a/benq b/lib/bin/add similarity index 96% rename from benq rename to lib/bin/add index 1f92e94..95fbbb8 100755 --- a/benq +++ b/lib/bin/add @@ -1,13 +1,11 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- Insert to Queue -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; use File::stat; - -use lib 'lib'; use BEX; my $given_body; diff --git a/bjob b/lib/bin/job similarity index 84% rename from bjob rename to lib/bin/job index 0d6f468..bfd2f31 100755 --- a/bjob +++ b/lib/bin/job @@ -1,12 +1,10 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- Operations on a Job -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; - -use lib 'lib'; use BEX; my $edit; diff --git a/bls b/lib/bin/ls similarity index 86% rename from bls rename to lib/bin/ls index be558d3..5da501e 100755 --- a/bls +++ b/lib/bin/ls @@ -1,12 +1,10 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- List Machines and Groups -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; - -use lib 'lib'; use BEX; my $edit; diff --git a/bprun b/lib/bin/prun similarity index 98% rename from bprun rename to lib/bin/prun index 7a66f0b..d8b9872 100755 --- a/bprun +++ b/lib/bin/prun @@ -1,15 +1,12 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- Parallel Execution Using Screen -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use feature 'switch'; - use Getopt::Long; use POSIX; - -use lib 'lib'; use BEX; my $queue_name; diff --git a/bq b/lib/bin/queue similarity index 97% rename from bq rename to lib/bin/queue index 6fb7a17..483e794 100755 --- a/bq +++ b/lib/bin/queue @@ -1,13 +1,11 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- Show Queued Jobs -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; use POSIX; - -use lib 'lib'; use BEX; my $op_by_job; diff --git a/brun b/lib/bin/run similarity index 98% rename from brun rename to lib/bin/run index 040b6ba..e311729 100755 --- a/brun +++ b/lib/bin/run @@ -1,12 +1,10 @@ #!/usr/bin/perl -# Batch EXecutor 2.0 -- Run Queued Jobs -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Insert to Queue +# (c) 2011-2012 Martin Mares use strict; use warnings; use Getopt::Long; - -use lib 'lib'; use BEX; my $given_job; diff --git a/lib/BEX.pm b/lib/perl/BEX.pm similarity index 60% rename from lib/BEX.pm rename to lib/perl/BEX.pm index 579eff2..2c257de 100644 --- a/lib/BEX.pm +++ b/lib/perl/BEX.pm @@ -1,5 +1,5 @@ -# Batch EXecutor 2.0 -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 +# (c) 2011-2012 Martin Mares use strict; use warnings; diff --git a/lib/BEX/Config.pm b/lib/perl/BEX/Config.pm similarity index 85% rename from lib/BEX/Config.pm rename to lib/perl/BEX/Config.pm index a5ee67e..6a2efdd 100644 --- a/lib/BEX/Config.pm +++ b/lib/perl/BEX/Config.pm @@ -1,5 +1,5 @@ -# Batch EXecutor 2.0 -- Configuration -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Configuration +# (c) 2011-2012 Martin Mares use strict; use warnings; @@ -15,12 +15,17 @@ package BEX::Config; our %machines = ( ); +# Home directory in which everything resides +our $bex_home = $ENV{"BEX_HOME"} // "."; + +# Configuration directory +our $bex_cf_dir = $bex_home . "/BEX"; # A file whose contents should be prepended before the job. Should start with the "#!" line. -our $job_prolog = 'prolog'; +our $job_prolog = $bex_cf_dir . '/prolog'; # A file whose contents should be appended to the job -our $job_epilog = 'epilog'; +our $job_epilog = $bex_cf_dir . '/epilog'; # Keep history of successfully completed jobs our $keep_history = 1; @@ -84,6 +89,6 @@ sub host_name($) { return $machines{$mach}->{'Host'} // $mach; } -require 'BEX.cf'; +require $bex_cf_dir . '/config'; 42; diff --git a/lib/BEX/Job.pm b/lib/perl/BEX/Job.pm similarity index 96% rename from lib/BEX/Job.pm rename to lib/perl/BEX/Job.pm index d040f1a..a459cc3 100644 --- a/lib/BEX/Job.pm +++ b/lib/perl/BEX/Job.pm @@ -1,5 +1,5 @@ -# Batch EXecutor 2.0 -- Jobs -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Jobs +# (c) 2011-2012 Martin Mares use strict; use warnings; diff --git a/lib/BEX/Queue.pm b/lib/perl/BEX/Queue.pm similarity index 98% rename from lib/BEX/Queue.pm rename to lib/perl/BEX/Queue.pm index 3fb94f3..6ae9240 100644 --- a/lib/BEX/Queue.pm +++ b/lib/perl/BEX/Queue.pm @@ -1,5 +1,5 @@ -# Batch EXecutor 2.0 -- Queues -# (c) 2011 Martin Mares +# Batch EXecutor 3.0 -- Queues +# (c) 2011-2012 Martin Mares use strict; use warnings; -- 2.39.2