1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # $Id$ |
---|
4 | |
---|
5 | =head1 NAME |
---|
6 | |
---|
7 | obsdata - Find, sort and dispatch data files |
---|
8 | |
---|
9 | =head1 VERSION |
---|
10 | |
---|
11 | CVS: $Revision$ |
---|
12 | |
---|
13 | =cut |
---|
14 | |
---|
15 | use strict; |
---|
16 | use warnings; |
---|
17 | use ObsData; |
---|
18 | use Getopt::Long; |
---|
19 | use Pod::Usage; |
---|
20 | |
---|
21 | my $verbose = 2; |
---|
22 | |
---|
23 | GetOptions( |
---|
24 | 'c|config=s' => \my $configfile, |
---|
25 | 'check' => \my $check_only, |
---|
26 | 'dry-run' => \my $dryrun, |
---|
27 | 'l|logfile=s' => \my $log, |
---|
28 | 'debug' => sub { $verbose = 0 }, |
---|
29 | 'v|verbose' => sub { $verbose-- }, |
---|
30 | 'h|help' => sub { pod2usage(-exitval => 0) }, |
---|
31 | 'i' => \my $interactif, |
---|
32 | 'only-new' => \my $onlynew, |
---|
33 | 'only-old' => \my $onlyold, |
---|
34 | ) or pod2usage(); |
---|
35 | |
---|
36 | =head1 SYNOPSIS |
---|
37 | |
---|
38 | obsdata -c config_file [[-l logfile] [-d] [-v|--debug]] [--check] |
---|
39 | obsdata [-h|-help] |
---|
40 | |
---|
41 | =head1 OPTIONS |
---|
42 | |
---|
43 | =over 4 |
---|
44 | |
---|
45 | =item -c|--config config-file |
---|
46 | |
---|
47 | Use this configuration file |
---|
48 | |
---|
49 | =item --check |
---|
50 | |
---|
51 | Only check config file and exit |
---|
52 | |
---|
53 | =item -l|--logfile logfile |
---|
54 | |
---|
55 | Write all messages into this file |
---|
56 | |
---|
57 | =item -v|--verbose |
---|
58 | |
---|
59 | Increase verbosity (this does not affect log output) |
---|
60 | |
---|
61 | =item --dry-run |
---|
62 | |
---|
63 | Does everything except write on disk, log are filled anyway |
---|
64 | |
---|
65 | =item --debug |
---|
66 | |
---|
67 | Increase verbosity to debug level (does same things than -v -v -v) |
---|
68 | |
---|
69 | =item -h|--help |
---|
70 | |
---|
71 | Print short help message |
---|
72 | |
---|
73 | =back |
---|
74 | |
---|
75 | =cut |
---|
76 | |
---|
77 | sub sub_interactive { |
---|
78 | my ($oa, $oe) = @_; |
---|
79 | for ($oe->id) { |
---|
80 | /^do_archive$/ and do { |
---|
81 | if ($onlyold && !$oe->test_result('archive_exists')) { |
---|
82 | return 0; |
---|
83 | } |
---|
84 | if($onlynew && $oe->test_result('archive_exists')) { |
---|
85 | return 0 |
---|
86 | } |
---|
87 | }; |
---|
88 | /^overwrite$/ && !$oe->test_result('dest_exists') and return 1; |
---|
89 | } |
---|
90 | print $oe->message ."\n"; |
---|
91 | foreach ($oe->list_test) { |
---|
92 | printf("\t%s\n", $oe->test_message($_)); |
---|
93 | } |
---|
94 | print "Processing ? Y/n: "; |
---|
95 | my $res = <STDIN>; |
---|
96 | chomp($res); |
---|
97 | return($res =~ /^[Yy]$/ ? 1 : 0); |
---|
98 | } |
---|
99 | |
---|
100 | my $obsdata = ObsData->new( |
---|
101 | $configfile, |
---|
102 | logfile => $log, |
---|
103 | verbose => 0, |
---|
104 | dry_run => $dryrun, |
---|
105 | logcallback => sub { |
---|
106 | return if($_[0] < $verbose); |
---|
107 | printf("%-9s %s\n", sprintf("[%s]", ObsData::loglevel($_[0])), $_[1]); |
---|
108 | }, |
---|
109 | interactive_callback => $interactif ? \&sub_interactive : undef, |
---|
110 | ) or do { |
---|
111 | warn "Can't create obsdata object\n"; |
---|
112 | pod2usage() |
---|
113 | }; |
---|
114 | |
---|
115 | $obsdata->load or die "Can load osbdata"; |
---|
116 | my $checkres = $obsdata->checkconfig or die "Error while checking configuration"; |
---|
117 | exit(0) if ($check_only); |
---|
118 | |
---|
119 | my @obs = $obsdata->list_obs; |
---|
120 | my @datatype = (); |
---|
121 | |
---|
122 | foreach my $o (@obs) { |
---|
123 | my %datadir = $obsdata->list_obsdatadir($o); |
---|
124 | foreach my $d (keys %datadir) { |
---|
125 | if(@datatype && !grep { $_ eq $d } @datatype) { |
---|
126 | next; |
---|
127 | } |
---|
128 | my $dir = $obsdata->get_obs_data_handle($o, $d) or next; |
---|
129 | $dir->process; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | my $s = $obsdata->generated_reported(); |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | =head1 AUTHOR |
---|
138 | |
---|
139 | Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr> |
---|
140 | |
---|
141 | =cut |
---|