]> mj.ucw.cz Git - bex.git/blob - lib/bin/bex-job
Maint: Reorganization of my directory structure
[bex.git] / lib / bin / bex-job
1 #!/usr/bin/perl
2 # Batch EXecutor -- Operations on a Job
3 # (c) 2011-2015 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use Getopt::Long;
8 use BEX;
9
10 my $edit;
11 my $long;
12 my $queue_name;
13
14 sub usage() {
15         print <<AMEN ;
16 Usage: bex job [<options>] [<job-id>]
17
18 If a job-id is given, print information on the given job.
19 Otherwise, list all known jobs.
20
21 Options:
22 -e, --edit              Run editor on the given job (no locking)
23 -l, --long              When listing jobs, use long format (with subjects)
24 -q, --queue=<name>      Act on the given queue
25 AMEN
26         exit 0;
27 }
28
29 GetOptions(
30         "e|edit!" => \$edit,
31         "l|long!" => \$long,
32         "q|queue=s" => \$queue_name,
33         "help" => \&usage,
34 ) && @ARGV <= 1 or die "Try `bex job --help' for more information.\n";
35
36 my $queue = BEX::Queue->new($queue_name);
37
38 if (!@ARGV) {
39         my @jobs = $queue->all_job_ids;
40         for my $id (sort @jobs) {
41                 if ($long) {
42                         my $job = $queue->job_metadata($id);
43                         my $has_att = -d $queue->attachment_dir($id);
44                         print $job->name;
45                         print " +ATT" if $has_att;
46                         print "\n";
47                 } else {
48                         print $id, "\n";
49                 }
50         }
51         exit 0;
52 }
53
54 my $jid = $queue->resolve_job_id($ARGV[0]);
55 my $fn = $queue->job_file($jid);
56
57 if ($edit) {
58         system "editor", $fn;
59 } else {
60         system "cat", $fn;
61 }