return correct image_id in process_image.
[cxgn-corelibs.git] / bin / publish.pl
blob31a5b69a4fa0373b2b5aa426888aeb27fa670d16
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use English;
5 use Carp;
6 use FindBin;
7 use Getopt::Std;
9 #use Data::Dumper;
10 use CXGN::Publish qw/publish/;
12 sub usage {
13 my $message = shift || '';
14 $message = "Error: $message\n" if $message;
15 die <<EOU;
16 $message
17 Usage:
18 $FindBin::Script <options> rm FILE...
19 $FindBin::Script <options> rm -f FILE...
20 $FindBin::Script <options> cp SOURCE... DEST
21 $FindBin::Script <options> cp SOURCE... DIRECTORY
22 $FindBin::Script <options> touch FILE
24 Do deletes or copies, preserving a file-based version history of the
25 target file(s). Try it out, you'll see what I mean.
27 Makes its best effort to keep the operation atomic. For example, if
28 you're copying a bunch of files to a directory and the destination
29 runs out of disk space, all of the files that _were_ copied will be
30 removed, and the old ones put back in place, as if the operation
31 never happened.
33 Note that operations are skipped if the new file is the same as the
34 old file.
36 Operations:
38 rm 'remove' the target file. Die if it is not present.
39 rm -f 'remove' the target file. Ignore if not present.
40 cp 'copy' the source(s) to the destination
41 touch right now, simply ensures that the proper curr/ symlink is
42 present, making it if necessary.
44 Uses the CXGN::Publish module. If you need to do more than what's
45 provided by this script, chances are you can do it by using the
46 module directly.
48 Options:
50 -x dry run. don't actually do anything, just print.
52 -v be verbose
54 -d create target directories if necessary
56 -b bac repository mode. processes filename extensions a bit
57 differently to allow for sequence versions. Requires
58 CXGN::TomatoGenome::BACPublish to be installed
59 EOU
62 #get command-line switches
63 our %opt;
64 getopts('vxdb',\%opt) or usage();
65 $CXGN::Publish::print_ops = 1 if $opt{v};
66 $CXGN::Publish::dry_run = 1 if $opt{x};
67 $CXGN::Publish::make_dirs = 1 if $opt{d};
69 #parse the rest of the arguments
70 @ARGV >= 2 or usage;
72 my @operands = @ARGV; #the
73 my $operation = shift @operands; #the operation we will perform
74 if($operation eq 'rm' && $operands[0] eq '-f') {
75 shift @operands;
76 $operation = 'rm -f';
79 #assemble the list of publishing operations (see CXGN::Publish)
80 my @publish_operations = do {
82 if( $operation eq 'rm' || $operation eq 'rm -f' || $operation eq 'touch' ) {
83 map {[$operation,$_]} @operands
85 elsif($operation eq 'cp') {
86 my $destination = pop @operands;
87 @operands == 1 or -d $destination or $opt{d} or die "'$destination' is not a directory\n";
88 map {['cp',$_,$destination]} @operands;
90 else {
91 usage("unknown operation '$operation'");
96 #do the publish operation
97 if($opt{b}) {
98 eval 'require CXGN::TomatoGenome::BACPublish';
99 die "Cannot load CXGN::TomatoGenome::BACPublish, required for -b mode:\n$@" if $@;
100 CXGN::TomatoGenome::BACPublish::bac_publish(@publish_operations);
102 else {
103 publish(@publish_operations);