source: trunk/soft/ObsData/bin/obsdata @ 211

Last change on this file since 211 was 211, checked in by thauvin, 18 years ago
  • add function to genrated mail report
  • Property cvs2svn:cvs-rev set to 1.18
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1#!/usr/bin/perl
2
3# $Id$
4
5=head1 NAME
6
7obsdata - Find, sort and dispatch data files
8
9=head1 VERSION
10
11CVS: $Revision$
12
13=cut
14
15use strict;
16use warnings;
17use ObsData;
18use Getopt::Long;
19use Pod::Usage;
20
21my $verbose = 2;
22
23GetOptions(
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
47Use this configuration file
48
49=item --check
50
51Only check config file and exit
52
53=item -l|--logfile logfile
54
55Write all messages into this file
56
57=item -v|--verbose
58
59Increase verbosity (this does not affect log output)
60
61=item --dry-run
62
63Does everything except write on disk, log are filled anyway
64
65=item --debug
66
67Increase verbosity to debug level (does same things than -v -v -v)
68
69=item -h|--help
70
71Print short help message
72
73=back
74
75=cut
76
77sub 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
100my $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";
116my $checkres = $obsdata->checkconfig or die "Error while checking configuration";
117exit(0) if ($check_only);
118
119my @obs = $obsdata->list_obs;
120my @datatype = ();
121
122foreach 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
133my $s = $obsdata->generated_reported();
134
135
136
137=head1 AUTHOR
138
139Olivier Thauvin <olivier.thauvin@aerov.jussieu.fr>
140
141=cut
Note: See TracBrowser for help on using the repository browser.