From: Eric Bollengier Date: Thu, 6 Dec 2007 19:27:09 +0000 (+0000) Subject: ebl Add Bweb::Schedule Object to parse show schedule output. X-Git-Tag: Release-3.0.0~2178 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b47704d52fd024cf1095900cf4e678ea3f068ddc;p=bacula%2Fbacula ebl Add Bweb::Schedule Object to parse show schedule output. Now, we can make ical events for example... git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6023 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/gui/bweb/INSTALL b/gui/bweb/INSTALL index b1c71eef66..cbc4550d11 100644 --- a/gui/bweb/INSTALL +++ b/gui/bweb/INSTALL @@ -77,14 +77,16 @@ Simply use lang/fr/tpl/*.tpl files instead of tpl/*.tpl - CGI - Expect - Time::ParseDate + - Date::Calc You can install perl modules with CPAN perl -e shell -MCPAN > install Expect Or use your distribution - apt-get install libgd-graph-perl libhtml-template-perl libexpect-perl - apt-get install libdbd-mysql-perl libdbd-pg-perl libdbi-perl libtime-modules-perl + apt-get install libgd-graph-perl libhtml-template-perl libexpect-perl \ + libdbd-mysql-perl libdbd-pg-perl libdbi-perl \ + libdate-calc-perl libtime-modules-perl Note: the best way to test if you have all the dependencies fullfilled for Perl is to: diff --git a/gui/bweb/Makefile.PL b/gui/bweb/Makefile.PL index 45833d1c1a..b21b21887d 100644 --- a/gui/bweb/Makefile.PL +++ b/gui/bweb/Makefile.PL @@ -1,4 +1,4 @@ -use Test::More tests => 7; +use Test::More tests => 8; require_ok('DBI'); require_ok('GD::Graph'); @@ -7,6 +7,7 @@ require_ok('HTML::Template'); require_ok('CGI'); require_ok('Expect'); require_ok('Time::ParseDate'); +require_ok('Date::Calc'); use ExtUtils::MakeMaker; diff --git a/gui/bweb/UPGRADE b/gui/bweb/UPGRADE index 79fbe8fd44..074d7fcc14 100644 --- a/gui/bweb/UPGRADE +++ b/gui/bweb/UPGRADE @@ -1,5 +1,16 @@ Upgrade notes for Bweb +Upgrade from 2.2.Y to 3.0 +------------------------- + + - Add the Date::Calc package to your perl library + - Add user, new job overview and bresto tables to your catalog + + mysql) + load the bweb/script/upgrade-2.2_3.0_mysql.sql file + postgresql) + load the bweb/script/upgrade-2.2_3.0_postgresql.sql file + Upgrade from 2.0.X to 2.2.Y --------------------------- diff --git a/gui/bweb/lib/Bweb.pm b/gui/bweb/lib/Bweb.pm index 983fd23326..7f12f43f0a 100644 --- a/gui/bweb/lib/Bweb.pm +++ b/gui/bweb/lib/Bweb.pm @@ -1012,6 +1012,190 @@ WHERE Media.VolumeName IN ($media_list) 1; +################################################################ + +package Bweb::Sched; +use base q/Bweb::Gui/; + +=head1 PACKAGE + + Bweb::Sched() - Bweb package that parse show schedule ouput + + new Bweb::Sched(format => '%Y-%m-%d'); + +=head2 USAGE + + my $b = $bweb->get_bconsole(); + my $s = $b->send_cmd("show schedule"); + my $sched = new Bweb::Sched(); + $sched->parse_scheds(split(/\r?\n/, $s)); + + +$VAR1 = { + 'event' => [ + '2007-01-04 04:05', + '2007-12-05 04:05', + '2007-12-12 04:05', + '2007-12-19 04:05', + '2007-12-26 04:05' + ], + 'level' => 'Differential', + 'pool' => 'Semaine' + }; +=cut + +# cleanup and add a schedule +sub add_sched +{ + my ($self, $name, $info) = @_; + # bacula uses dates that start from 0, we start from 1 + foreach (@{$info->{mday}},@{$info->{month}}) { $_++ }; + + # get events + $info->{event} = [ $self->get_events($info, $self->{format}) ]; + + foreach my $i (qw/hour mday month wday wom woy mins/) { + delete $info->{$i}; + } + + push @{$self->{schedules}->{$name}}, $info; +} + +# return the name of all schedules +sub list_scheds +{ + my ($self, $name) = @_; + my %ret; + return keys %{ $self->{schedules} }; +} + +# return an array of all schedule +sub get_scheds +{ + my ($self, $sched) = @_; + return $self->{schedules}->{$sched}; +} + +# return an ref array of all events +# [ '2007-12-19 04:05', '2007-12-19 04:05' ] +sub get_event +{ + my ($self, $sched) = @_; + return $sched->{event}; +} + +# return the pool name +sub get_pool +{ + my ($self, $sched) = @_; + return $sched->{pool} || ''; +} + +# return the level name (Incremental, Differential, Full) +sub get_level +{ + my ($self, $sched) = @_; + return $sched->{level}; +} + +# parse bacula sched bitmap +sub parse_scheds +{ + my ($self, @output) = @_; + + my $run; + my $name; + my $schedule; + my $elt; + + foreach my $ligne (@output) { + if ($ligne =~ /Schedule: name=(.+)/) { + if ($name and $elt) { + $elt->{level} = $run; + $self->add_sched($name, $elt); + $elt=undef; + } + $name = $1; + } + elsif ($ligne =~ /Run Level=(.+)/) { + if ($name and $elt) { + $elt->{level} = $run; + $self->add_sched($name, $elt); + $elt=undef; + } + $run = $1; + } + elsif ($ligne =~ /(hour|mday|month|mins)=(.+)/) { + # All theses lines have the same format + + my ($k,$v) = ($1,$2); + # we get all values (0 1 4 9) + $elt->{$k}=[split (/\s/,$v)]; + } + # we make a bitmap for this kind of data (0 0 1 0 0 0 1) for a quick access + elsif ($ligne =~ /(wday|wom|woy)=(.+)/) { + my ($k,$v) = ($1,$2); + foreach my $e (split (/\s/,$v)) { + $elt->{$k}->[$e]=1; + } + } + elsif ($ligne =~ /Pool: name=(.+?) PoolType/) { + $elt->{pool} = $1; + } + } + + if ($name and $elt) { + $elt->{level} = $run; + $self->add_sched($name, $elt); + } +} + +use Date::Calc qw(:all); + +# read bacula schedule bitmap and get $format date string +sub get_events +{ + use integer; + my ($self, $s,$format) = @_; + my $year = $self->{year} || ((localtime)[5] + 1900); + $format = $format || '%u-%02u-%02u %02u:%02u'; + + my @ret; + foreach my $m (@{$s->{month}}) # mois de l'annee + { + foreach my $md (@{$s->{mday}}) # jour du mois + { +# print " m=$m md=$md\n"; + # we check if this day exists (31 fev) + next if (!check_date($year,$m,$md)); +# print " check_date ok\n"; + + my $w = ($md-1)/7; # we use the same thing than bacula + next if (! $s->{wom}->[$w]); +# print " wom ok\n"; + + # on recupere le jour de la semaine + my $wd = Day_of_Week($year,$m,$md); + + my ($w1,undef) = Week_of_Year($year,$m,$wd); + next if (! $s->{woy}->[$w1-1]); # bacula 0-51 +# print " woy ok\n"; + + $wd = 0 if ($wd == 7) ; # sunday is 0 on bacula + next if (! $s->{wday}->[$wd]); +# print " wday ok\n"; + + foreach my $h (@{$s->{hour}}) # hour of the day + { + foreach my $min (@{$s->{mins}}) # minute + { + push @ret, sprintf($format, $year,$m,$md,$h,$min); + } + } + } + } + return @ret; +} ################################################################ diff --git a/gui/bweb/technotes-2.3 b/gui/bweb/technotes-2.3 index 839797c996..d2b66b0691 100644 --- a/gui/bweb/technotes-2.3 +++ b/gui/bweb/technotes-2.3 @@ -1,3 +1,7 @@ +06Dec07 +ebl Add Bweb::Schedule Object to parse show schedule output. + Now, we can make ical events for example... + 05Dec07 ebl Add truncate to second function ebl Add btime module diff --git a/gui/debian/changelog b/gui/debian/changelog index 7572df84f0..b4e2ef9ca7 100644 --- a/gui/debian/changelog +++ b/gui/debian/changelog @@ -1,6 +1,7 @@ bweb (2.2.7-1) stable; urgency=low * Add new btime module - + * Add a new scheduled view, you MUST have Date::Calc module + -- Eric Bollengier Tue, 4 Dec 2007 22:15:47 +0000 bweb (2.2.6-1) stable; urgency=low diff --git a/gui/debian/control b/gui/debian/control index 2c1b6c7d57..1e5d799c54 100644 --- a/gui/debian/control +++ b/gui/debian/control @@ -15,14 +15,14 @@ Description: Bacula restore interface Package: bweb Section: base Architecture: all -Depends: libtime-modules-perl, bweb-common, libgd-graph-perl, libdbd-pg-perl|libdbd-mysql-perl,libhtml-template-perl -Description: Bacula restore interface +Depends: libtime-modules-perl, bweb-common, libgd-graph-perl, libdbd-pg-perl|libdbd-mysql-perl,libhtml-template-perl,libdate-calc-perl +Description: Bacula web interface Bweb is a Bacula web interface Package: bweb-common Section: base Architecture: all Depends: libtime-modules-perl, libexpect-perl -Description: Bacula restore interface +Description: Common files for bweb and brestore Bweb is a Bacula web interface