svn commit: r235894 - in user/des/fbce: . lib/FBCE/Model
lib/FBCE/Script
Dag-Erling Smorgrav
des at FreeBSD.org
Thu May 24 10:51:38 UTC 2012
Author: des
Date: Thu May 24 10:51:37 2012
New Revision: 235894
URL: http://svn.freebsd.org/changeset/base/235894
Log:
Add FBCE::Model::Rules and place max_votes and cutoff there, along with a
method that calculates the cutoff date based on the election start date
and the cutoff duration.
Update FBCE::Script::User.pm accordingly; also fix argv validation, which
was broken for the list command and non-existent for the others.
Added:
user/des/fbce/lib/FBCE/Model/Rules.pm (contents, props changed)
Modified:
user/des/fbce/fbce.conf
user/des/fbce/lib/FBCE/Model/Schedule.pm (contents, props changed)
user/des/fbce/lib/FBCE/Script/User.pm
Modified: user/des/fbce/fbce.conf
==============================================================================
--- user/des/fbce/fbce.conf Thu May 24 10:31:17 2012 (r235893)
+++ user/des/fbce/fbce.conf Thu May 24 10:51:37 2012 (r235894)
@@ -1,6 +1,7 @@
# $FreeBSD$
title = 2012 FreeBSD Core Team Election
+descr = 2012 FreeBSD core team election
<Model::FBCE>
<connect_info>
@@ -17,10 +18,12 @@ title = 2012 FreeBSD Core Team Election
voting_ends = 2012-06-27 00:00:00 UTC
announcement = 2012-06-27 18:00:00 UTC
investiture = 2012-07-04
- # XXX does not belong here
+</Model::Schedule>
+
+<Model::Rules>
max_votes = 9
cutoff = 1 year
-</Model::Schedule>
+</Model::Rules>
<Plugin::Session>
expires = 1800
Added: user/des/fbce/lib/FBCE/Model/Rules.pm
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/des/fbce/lib/FBCE/Model/Rules.pm Thu May 24 10:51:37 2012 (r235894)
@@ -0,0 +1,62 @@
+package FBCE::Model::Rules;
+use Moose;
+use MooseX::Types::Common::Numeric qw(PositiveInt);
+use MooseX::Types::DateTime::MoreCoercions qw(Duration);
+use DateTime;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Component' }
+
+=head1 NAME
+
+FBCE::Controller - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=cut
+
+has max_votes => (
+ isa => PositiveInt,
+ is => 'ro',
+ required => 1
+);
+
+has cutoff => (
+ isa => Duration,
+ coerce => 1,
+ is => 'ro',
+ required => 1,
+);
+
+our $cutoff_date;
+
+sub cutoff_date($) {
+ my ($self) = @_;
+
+ if (!defined($cutoff_date)) {
+ $cutoff_date =
+ FBCE->model('Schedule')->nominating_starts - $self->cutoff;
+ $cutoff_date->set(hour => 0, minute => 0, second => 0);
+ print STDERR $cutoff_date->ymd();
+ }
+ return $cutoff_date;
+}
+
+=head1 AUTHOR
+
+Dag-Erling Smørgrav
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+# $FreeBSD$
Modified: user/des/fbce/lib/FBCE/Model/Schedule.pm
==============================================================================
--- user/des/fbce/lib/FBCE/Model/Schedule.pm Thu May 24 10:31:17 2012 (r235893)
+++ user/des/fbce/lib/FBCE/Model/Schedule.pm Thu May 24 10:51:37 2012 (r235894)
@@ -59,21 +59,6 @@ has investiture => (
required => 1
);
-# XXX does not belong here
-has max_votes => (
- isa => PositiveInt,
- is => 'ro',
- required => 1
-);
-
-# XXX does not belong here
-has cutoff => (
- isa => Duration,
- coerce => 1,
- is => 'ro',
- required => 1,
-);
-
sub _phase($$$) {
my ($self, $phase, $now) = @_;
@@ -121,3 +106,5 @@ it under the same terms as Perl itself.
__PACKAGE__->meta->make_immutable;
1;
+
+# $FreeBSD$
Modified: user/des/fbce/lib/FBCE/Script/User.pm
==============================================================================
--- user/des/fbce/lib/FBCE/Script/User.pm Thu May 24 10:31:17 2012 (r235893)
+++ user/des/fbce/lib/FBCE/Script/User.pm Thu May 24 10:51:37 2012 (r235894)
@@ -89,10 +89,10 @@ sub retrieve_commit_data($$) {
# List existing users
#
sub cmd_list(@) {
- my ($self) = @_;
+ my ($self, @argv) = @_;
die("too many arguments")
- if @{$self->ARGV};
+ if @argv;
my $persons = FBCE->model('FBCE::Person')->
search({}, { order_by => 'login' });
printf("%-16s%-8s%-8s%s\n",
@@ -113,8 +113,10 @@ sub cmd_list(@) {
# Mark all users inactive
#
sub cmd_smash(@) {
- my ($self) = @_;
+ my ($self, @argv) = @_;
+ die("too many arguments")
+ if @argv;
my $persons = FBCE->model('FBCE::Person')->search();
my $schema = $persons->result_source()->schema();
$schema->txn_do(sub {
@@ -130,17 +132,13 @@ sub cmd_smash(@) {
# don't already have one, and set the active bit.
#
sub cmd_pull(@) {
- my ($self) = @_;
+ my ($self, @argv) = @_;
- # cutoff duration from config
- my $cutoff_duration = FBCE->model('Schedule')->cutoff;
+ die("too many arguments")
+ if @argv;
- # cutoff date: start out with current time (UTC)
- my $cutoff_date = DateTime->now(time_zone => 'UTC');
- # round down to midnight
- $cutoff_date->set(hour => 0, minute => 0, second => 0);
- # subtract the cutoff duration
- $cutoff_date->subtract_duration($cutoff_duration);
+ # retrieve cutoff date
+ my $cutoff_date = FBCE->model('Rules')->cutoff_date;
warn(sprintf("Setting cutoff date to %sT%sZ\n",
$cutoff_date->ymd(), $cutoff_date->hms()))
if $self->debug;
@@ -179,10 +177,13 @@ sub cmd_pull(@) {
# Set each user's realname column based on their gecos
#
sub cmd_gecos(@) {
- my ($self, $pwfn) = @_;
+ my ($self, $pwfn, @argv) = @_;
my %gecos;
+ die("too many arguments")
+ if @argv;
+
# read passwd file
$pwfn //= "/etc/passwd";
open(my $pwfh, '<', $pwfn)
@@ -275,7 +276,10 @@ sub pwgen($$;$) {
# Generate passwords for all users. Use with caution!
#
sub cmd_pwgen(@) {
- my ($self, @users) = @_;
+ my ($self, @argv) = @_;
+
+ die("too many arguments")
+ if @argv;
# please don't overwrite an existing password tarball...
die("$pwtar exists, delete or move and try again\n")
More information about the svn-src-user
mailing list