From owner-svn-src-user@FreeBSD.ORG Thu May 24 10:51:38 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4856E106566B; Thu, 24 May 2012 10:51:38 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2836F8FC17; Thu, 24 May 2012 10:51:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4OApcc4033497; Thu, 24 May 2012 10:51:38 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4OApbcb033491; Thu, 24 May 2012 10:51:37 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201205241051.q4OApbcb033491@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Thu, 24 May 2012 10:51:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r235894 - in user/des/fbce: . lib/FBCE/Model lib/FBCE/Script X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2012 10:51:38 -0000 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 @@ -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 + + + max_votes = 9 cutoff = 1 year - + 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")