diff options
| author | fukachan <fukachan> | 2001-03-27 17:01:09 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-03-27 17:01:09 +0000 |
| commit | 9abb5dafad5887fda1637c1320d0d86133e39593 (patch) | |
| tree | d7818a8db794012b01437b2cce814d9d979a9eac | |
| parent | bde2fc4d3815353c2a2a67615a50e01873dd59cc (diff) | |
| download | fml8-9abb5dafad5887fda1637c1320d0d86133e39593.tar.gz fml8-9abb5dafad5887fda1637c1320d0d86133e39593.tar.bz2 fml8-9abb5dafad5887fda1637c1320d0d86133e39593.zip | |
demonstration to add a little CUI and GUI to the system. "fmlsch" and
"fmlsch.cgi" is a tiny scheduler using HTML::CalenderMonthSimple and
w3m:)
I log how to make them as a document, which is the purpose of this hack.
| -rwxr-xr-x | INSTALL.sh | 3 | ||||
| -rwxr-xr-x | fml/bin/fmlsch | 17 | ||||
| -rw-r--r-- | fml/lib/FML/CGI/Scheduler.pm | 102 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Scheduler.pm | 104 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Switch.pm | 12 | ||||
| -rw-r--r-- | fml/lib/TinyScheduler.pm | 194 | ||||
| -rw-r--r-- | regress/scheduler/MANIFEST | 6 |
7 files changed, 437 insertions, 1 deletions
@@ -83,7 +83,7 @@ echo update $libexec_dir/$fml_version/ cp -pr fml/libexec/* $libexec_dir/$fml_version/ echo update /usr/local/bin/ -for prog in fmldoc fmlticket fmlconf makefml +for prog in fmldoc fmlticket fmlconf makefml fmlsch do echo update /usr/local/bin/$prog cp fml/bin/$prog /usr/local/bin/$prog.new @@ -94,6 +94,7 @@ PROGRAMS="fml.pl distribute command "; PROGRAMS="$PROGRAMS fmlserv mead fmlconf fmldoc" PROGRAMS="$PROGRAMS fmlticket fmlticket.cgi" PROGRAMS="$PROGRAMS makefml makefml.cgi" +PROGRAMS="$PROGRAMS fmlsch fmlsch.cgi" if [ ! -f $libexec_dir/loader ];then diff --git a/fml/bin/fmlsch b/fml/bin/fmlsch new file mode 100755 index 00000000..3d973ca6 --- /dev/null +++ b/fml/bin/fmlsch @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Copyright (C) 2001 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $Id$ +# $FML$ +# + +default_prefix=/usr/local +libexec_dir=$default_prefix/libexec/fml + +exec $libexec_dir/fmlsch $* + +echo 'not reach here' +exit 0; diff --git a/fml/lib/FML/CGI/Scheduler.pm b/fml/lib/FML/CGI/Scheduler.pm new file mode 100644 index 00000000..b723c490 --- /dev/null +++ b/fml/lib/FML/CGI/Scheduler.pm @@ -0,0 +1,102 @@ +#-*- perl -*- +# +# Copyright (C) 2001 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $Id$ +# $FML$ +# + +package FML::CGI::Scheduler; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + +use CGI qw/:standard/; # load standard CGI routines + +use FML::Process::CGI; +@ISA = qw(FML::Process::CGI); + + +=head1 NAME + +FML::CGI::Scheduler - CGI details to control ticket system + +=head1 SYNOPSIS + + $ticket = new FML::CGI::Scheduler; + $ticket->new(); + $ticket->run(); + +See L<FML::Process::Flow> for flow methods details. + +=head1 DESCRIPTION + +C<NOT YET IMPLEMENTED>. + +=head2 CLASS HIERARCHY + +C<FML::CGI::Scheduler> is a subclass of C<FML::Process::CGI>. + + FML::Process::Kernel + | + A + FML::Process::CGI + | + A + ----------------------- + | | + A A + FML::CGI::Scheduler + +=head1 METHODS + +Almost methods common for CGI or HTML are forwarded to +C<FML::Process::CGI> base class. + +This module has routines needed for CGI. + +=cut + + +sub run +{ + my ($curproc, $args) = @_; + + use FileHandle; + use TinyScheduler; + + my $schedule = new TinyScheduler { user => param('user') }; + $schedule->parse; + $schedule->print; +} + + +=head1 SEE ALSO + +L<CGI>, +L<FML::Process::CGI> +and +L<FML::Process::Flow> + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::CGI::Scheduler appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Process/Scheduler.pm b/fml/lib/FML/Process/Scheduler.pm new file mode 100644 index 00000000..49b5f103 --- /dev/null +++ b/fml/lib/FML/Process/Scheduler.pm @@ -0,0 +1,104 @@ +#!/usr/local/bin/perl -w +#-*- perl -*- +# +# Copyright (C) 2000 Ken'ichi Fukamachi +# All rights reserved. +# +# $FML$ +# + +package FML::Process::Scheduler; + +use vars qw($debug @ISA @EXPORT @EXPORT_OK); +use strict; +use Carp; + +use FML::Process::Kernel; +@ISA = qw(FML::Process::Kernel); + +=head1 NAME + +FML::Process::Scheduler -- demonstration + +=head1 SYNOPSIS + + use FML::Process::Configure; + $curproc = new FML::Process::Configure; + $curproc->run(); + +=head1 DESCRIPTION + +FML::Process::Configure is the wrapper for fmlconf and makefml. +See C<FML::Process::Flow> for each method definition. + +=head2 MODULES + +These programs, +C<fmlconf> and C<makefml>, +bootstrap by using these modules in this order. + + libexec/loader -> FML::Process::Switch -> FML::Process::Configure + +=head1 METHODS + +=head2 C<new($args)> + +usual constructor. + +=head2 C<prepare($args)> + +dummy. + +=cut + + +sub prepare { ; } + + +sub run +{ + my ($self, $args) = @_; + + use FileHandle; + use TinyScheduler; + + my $schedule = new TinyScheduler; + $schedule->parse; + + my $tmp = $schedule->tmpfile; + my $fh = new FileHandle $tmp, "w"; + $schedule->print($fh); + $fh->close; + + system "w3m -dump $tmp"; + + unlink $tmp; +} + + +# dummy to avoid the error ( undefined function ) +sub AUTOLOAD +{ + ; +} + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Process::Configure appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Process/Switch.pm b/fml/lib/FML/Process/Switch.pm index 8f7d6633..cc2f087a 100644 --- a/fml/lib/FML/Process/Switch.pm +++ b/fml/lib/FML/Process/Switch.pm @@ -323,6 +323,9 @@ sub _module_specific_options elsif ($myname eq 'makefml.cgi') { return qw(debug!); } + elsif ($myname eq 'fmlsch.cgi' || $myname eq 'fmlsch') { + return qw(debug!); + } else { croak "options for $myname are not defined.\n"; } @@ -340,6 +343,9 @@ sub _ml_name_is_required if ($myname eq 'fmldoc') { return 0; } + elsif ($myname eq 'fmlsch' || $myname eq 'fmlsch.cgi') { + return 0; + } elsif ($myname eq 'makefml') { return 0; } @@ -391,6 +397,12 @@ sub _module_we_use elsif ($name eq 'makefml.cgi') { $pkg = 'FML::CGI::Configure'; } + elsif ($name eq 'fmlsch') { + $pkg = 'FML::Process::Scheduler'; + } + elsif ($name eq 'fmlsch.cgi') { + $pkg = 'FML::CGI::Scheduler'; + } else { return ''; } diff --git a/fml/lib/TinyScheduler.pm b/fml/lib/TinyScheduler.pm new file mode 100644 index 00000000..a6b68def --- /dev/null +++ b/fml/lib/TinyScheduler.pm @@ -0,0 +1,194 @@ +#-*- perl -*- +# +# Copyright (C) 2001 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $Id$ +# $FML$ +# + +package TinyScheduler; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + +=head1 NAME + +TinyScheduler - what is this + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=head2 C<new()> + +=cut + + +sub new +{ + my ($self, $args) = @_; + my ($type) = ref($self) || $self; + my $me = {}; + my $user = $args->{ user } || $ENV{'USER'}; + + # directory + use User::pwent; + my $pw = getpwnam($user); + my $home_dir = $pw->dir; + my $dir = "$home_dir/.tsch"; + + # ~/.schedule/ by default + $me->{ _user } = $user; + $me->{ _schedule_dir } = $dir; + $me->{ _schedule_file } = $args->{ schedule_file } || "$dir/$user"; + + return bless $me, $type; +} + + +sub tmpfile +{ + my ($self, $args) = @_; + my $user = $self->{ _user }; + my $dir = $self->{ _schedule_dir }; + my $tmpdir; + + if (-w $dir) { + $tmpdir = $dir; + } + else { + croak("Hmm, unsafe ? I cannot write $dir, stop\n"); + } + + $self->{ _tmpfile } = $tmpdir ."/$$.html"; + return $self->{ _tmpfile }; +} + + +=head2 C<parse($args)> + +=cut + +sub parse +{ + my ($self, $args) = @_; + my ($sec,$min,$hour,$mday,$month,$year,$wday) = localtime(time); + + # get the date to show + $year = $args->{ year } || (1900 + $year); + $month = $args->{ month } || ($month + 1); + + # schedule file + my $data_file = $args->{ schedule_file } || $self->{ _schedule_file }; + + # pattern to match + my @pat; + $pat[0] = sprintf("^%04d%02d(\\d{1,2})\\s+(.*)", $year, $month); + $pat[1] = sprintf("^%04d/%02d/(\\d{1,2})\\s+(.*)", $year, $month); + $pat[2] = sprintf("^%02d(\\d{1,2})\\s+(.*)", $year, $month); + $pat[3] = sprintf("^%02d/(\\d{1,2})\\s+(.*)", $year, $month); + + # + use HTML::CalendarMonthSimple; + + my $cal = new HTML::CalendarMonthSimple('year'=> $year, 'month'=> $month); + + if (defined $cal) { + $self->{ _schedule } = $cal; + } + else { + croak("cannot get object"); + } + + $cal->width('50%'); + $cal->border(10); + $cal->header("$year/$month schedule"); + $cal->bgcolor('pink'); + + if (-f $data_file) { + use FileHandle; + my $fh = new FileHandle $data_file; + + while (<$fh>) { + for my $pat (@pat) { + if (/$pat(.*)/) { + $self->_parse($1, $2); + } + } + } + close($fh); + } +} + + +sub _parse +{ + my ($self, $day, $buf) = @_; + my $cal = $self->{ _schedule }; + $cal->addcontent($day, "<p>". $buf); +} + + +sub print +{ + my ($self, $fd) = @_; + $fd = $fd || \*STDOUT; + print $fd $self->{ _schedule }->as_HTML; +} + + +if ($0 eq __FILE__) { + eval q{ + my %options; + + use Getopt::Long; + GetOptions(\%options, "e!"); + + require FileHandle; import FileHandle; + require TinyScheduler; import TinyScheduler; + my $schedule = new TinyScheduler; + + if ($options{'e'}) { + my $editor = $ENV{'EDITOR'} || 'mule'; + system $editor, '-nw', $schedule->{ _schedule_file }; + } + + $schedule->parse; + + my $tmp = $schedule->tmpfile; + my $fh = new FileHandle $tmp, "w"; + $schedule->print($fh); + $fh->close; + + system "w3m -dump $tmp"; + + unlink $tmp; + }; + croak($@) if $@; +} + + +=head1 AUTHOR + +Ken'chi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 Ken'chi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +TinyScheduler appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/regress/scheduler/MANIFEST b/regress/scheduler/MANIFEST new file mode 100644 index 00000000..67f4dbe0 --- /dev/null +++ b/regress/scheduler/MANIFEST @@ -0,0 +1,6 @@ +M INSTALL.sh +A fml/bin/fmlsch +A fml/lib/TinyScheduler.pm +A fml/lib/FML/CGI/Scheduler.pm +A fml/lib/FML/Process/Scheduler.pm +M fml/lib/FML/Process/Switch.pm |
