[Bps-public-commit] SD branch, master, updated. 673bd42bd12b8380a8225cc1fa51b1e58c7120e1

jesse jesse at bestpractical.com
Mon Apr 6 16:52:56 EDT 2009


The branch, master has been updated
       via  673bd42bd12b8380a8225cc1fa51b1e58c7120e1 (commit)
       via  a7dee64d991aefd5be002f16c15779749baadd76 (commit)
       via  f1c2afdde488ad70e28fd153b2bc41c826a65309 (commit)
      from  f1da7976bb60d4c14e1b919da96133fb846cf599 (commit)

Summary of changes:
 Makefile.PL                          |    1 -
 lib/App/SD/Model/Ticket.pm           |   15 ++++++------
 lib/App/SD/Replica/rt.pm             |    7 ++++-
 lib/App/SD/Replica/rt/PullEncoder.pm |   40 ++++++++++++++++++++-------------
 lib/App/SD/Util.pm                   |   28 +++++++++++++++++++++++
 t/sd-rt/basic.t                      |    2 +-
 tools/shipwright-package             |    9 ++++---
 7 files changed, 70 insertions(+), 32 deletions(-)
 create mode 100644 lib/App/SD/Util.pm

- Log -----------------------------------------------------------------
commit f1c2afdde488ad70e28fd153b2bc41c826a65309
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon Apr 6 16:51:58 2009 -0400

    packaging updates

diff --git a/tools/shipwright-package b/tools/shipwright-package
index 169d2ba..b6a6deb 100644
--- a/tools/shipwright-package
+++ b/tools/shipwright-package
@@ -1,7 +1,7 @@
 export REPO=/Users/jesse/shipwright-sd/
 export SVN_PATH="svn:file://$REPO"
 export MIN_PERL=5.008006
-export SKIP="--skip=Module::Signature,Test::Pod,Test::Pod::Coverage,Test::Distribution,Pod::Readme,Archive::Tar,Test::Script::Run,HTML::Lint,Prophet,Encode,Date::Calc"
+export SKIP="--skip=Pod::Simple,Module::Signature,Test::Pod,Test::Pod::Coverage,Test::Distribution,Pod::Readme,Archive::Tar,HTML::Lint,Prophet,Encode,Date::Calc"
 export IMPORT="shipwright import --min-perl-version=$MIN_PERL $SKIP -r $SVN_PATH --log-file - --log-level info"
 rm -rf $REPO
 svnadmin create $REPO
@@ -11,7 +11,6 @@ shipwright create -r $SVN_PATH
 # Optional deps we sitll want
 $IMPORT \
  cpan:Scalar::Util \
- cpan:Pod::Simple \
  cpan:Template::Declare \
  cpan:HTTP::Server::Simple \
  cpan:File::ShareDir \
@@ -20,7 +19,6 @@ $IMPORT \
  cpan:JSON::XS \
  cpan:Net::Bonjour \
  cpan:Term::ReadKey \
- cpan:Test::Script::Run \
  git:git+ssh://fsck.com/git/prophet.git \
  cpan:RT::Client::REST \
  cpan:Email::Address \
@@ -29,7 +27,7 @@ $IMPORT \
  git:git+ssh://fsck.com/git/sd.git
 cd /tmp
 rm -rf sdex
-shipwright update -r $SVN_PATH cpan-Module-Build --add-deps cpan-Pod-Simple
+#shipwright update -r $SVN_PATH cpan-Module-Build --add-deps cpan-Pod-Simple
 shipwright update -r $SVN_PATH cpan-IO-Compress-Base --add-deps cpan-Scalar-List-Utils
 shipwright update -r $SVN_PATH prophet.git      --add-deps cpan-Term-ReadLine-Perl,cpan-TermReadKey,cpan-DBD-SQLite,cpan-File-ShareDir,cpan-HTTP-Server-Simple,cpan-JSON-XS
 shipwright update -r $SVN_PATH sd.git           --add-deps prophet.git,cpan-Net-Bonjour,cpan-Email-Address,cpan-Net-Trac,cpan-RT-Client-REST
@@ -37,11 +35,14 @@ shipwright maintain -r $SVN_PATH --update-order
 cd /tmp
 mkdir svnhack-$$
 cd svnhack-$$
+
 svn co file://${REPO}/scripts/cpan-DateTime-Format-Natural
 cd cpan-DateTime-Format-Natural
 perl -pi -e s'/Build test/Build/g' build
 svn commit -m 'Made DTFN not run its tests which add a slew of deps' build
 cd ..
+
+
 svn co file://${REPO}/sources/cpan-Net-Bonjour/vendor
 cd vendor
 perl -pi -e's/^chomp.*?STDIN.*?$/my \$ans = "n";/g;' Makefile.PL

commit a7dee64d991aefd5be002f16c15779749baadd76
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon Apr 6 16:52:06 2009 -0400

    removing a redundant statement

diff --git a/t/sd-rt/basic.t b/t/sd-rt/basic.t
index c9f716c..7500644 100644
--- a/t/sd-rt/basic.t
+++ b/t/sd-rt/basic.t
@@ -66,9 +66,9 @@ RT::Client::REST::Ticket->new(
     status => 'open',
 )->store();
 
-run_script( 'sd', ['init'] );
 ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
 
+
 run_output_matches(
     'sd',
     [ 'ticket', 'list', '--regex', '.' ],

commit 673bd42bd12b8380a8225cc1fa51b1e58c7120e1
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon Apr 6 16:52:29 2009 -0400

    Rationalization of date/time handling ; removing HTTP::Date dependecny

diff --git a/Makefile.PL b/Makefile.PL
index 20fc20e..cb52710 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -8,7 +8,6 @@ requires('DateTime');
 requires('Time::Progress');
 requires('Path::Class');
 requires 'Prophet'; # URI UNIVERSAL::require Params::Validate Class::Accessor Template::Declare::Tags Test::HTTP::Server::Simple JSON Test::WWW::Mechanize Any::Moose
-requires('HTTP::Date');
 requires('HTML::TreeBuilder');
 requires('DateTime::Format::Natural');
 requires('HTML::Tree');
diff --git a/lib/App/SD/Model/Ticket.pm b/lib/App/SD/Model/Ticket.pm
index 709a91c..32a7192 100644
--- a/lib/App/SD/Model/Ticket.pm
+++ b/lib/App/SD/Model/Ticket.pm
@@ -3,7 +3,7 @@ use Any::Moose;
 extends 'App::SD::Record';
 
 use Term::ANSIColor;
-use HTTP::Date;
+use App::SD::Util;
 
 use constant collection_class => 'App::SD::Collection::Ticket';
 has type => ( default => 'ticket');
@@ -262,23 +262,22 @@ in the future. Returns true if the due date has passed.
 
 =cut
 
-# this expects ISO dates. we should improve it in the future to require
 sub is_overdue {
     my $self = shift;
     my $date = shift || $self->prop('due');
 
-    return 0 if !$date;
+    my $then = App::SD::Util::string_to_datetime($date);
 
-    if ($date !~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/) {
+    if (!$then) {
         warn "Unknown date format '$date'";
         return 0;
     }
 
-    my $then = HTTP::Date::str2time($date, 'GMT');
-    return 0 if !$then;
+    if ($then < DateTime->now()){ 
+        return 1;
+    }
 
-    my $now = time();
-    return $now > $then;
+    return 0;
 }
 
 
diff --git a/lib/App/SD/Replica/rt.pm b/lib/App/SD/Replica/rt.pm
index a654e37..acaa9ef 100644
--- a/lib/App/SD/Replica/rt.pm
+++ b/lib/App/SD/Replica/rt.pm
@@ -5,7 +5,6 @@ extends qw/App::SD::ForeignReplica/;
 use Params::Validate qw(:all);
 use Path::Class;
 use File::Temp 'tempdir';
-use HTTP::Date;
 use Memoize;
 
 use constant scheme => 'rt';
@@ -73,7 +72,11 @@ sub record_pushed_transactions {
 
         # get the completion time _after_ we do our next round trip to rt to try to make sure
         # a bit of lag doesn't skew us to the wrong side of a 1s boundary
-        my $txn_created = HTTP::Date::str2time($txn->created);
+        my $txn_created_dt = App::SD::Util::string_to_datetime($txn->created);
+        unless($txn_created_dt) {
+            die "Couldn't parse '".$txn->created."' as a timestamp";
+        }
+        my $txn_created = $txn_created_dt->epoch;
         if (!$earliest_valid_txn_date){
             my $change_window =  time() - $args{start_time};
             # skip any transaction created more than 5 seconds before the push started.
diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index 44e09ed..8d7351f 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -5,7 +5,7 @@ extends 'App::SD::ForeignReplica::PullEncoder';
 use Params::Validate qw(:all);
 use Memoize;
 use Time::Progress;
-use HTTP::Date;
+use App::SD::Util;
 
 has sync_source => 
     ( isa => 'App::SD::Replica::rt',
@@ -61,7 +61,7 @@ sub run {
     my @changesets;
     for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @transactions ) {
 
-        my $created = str2time($txn->{Created}); 
+        my $created = App::SD::Util::string_to_datetime($txn->{Created}); 
 
         $last_modified = $created if ( !$last_modified || ($created > $last_modified ));
         $last_txn = $txn->{'id'} if (!$last_txn || ($txn->{id} > $last_txn));
@@ -80,8 +80,12 @@ sub run {
         $args{callback}->($_)
     }
 
-    $self->sync_source->record_upstream_last_modified_date($last_modified) if (($last_modified ||0) > ($self->sync_source->upstream_last_modified_date ||0 ));
-    $self->sync_source->record_upstream_last_txn($last_txn) if (($last_txn ||0) > ($self->sync_source->upstream_last_txn ||0 ));
+    my $last_modified_datetime = App::SD::Util::string_to_datetime($self->sync_source->upstream_last_modified_date);
+    $self->sync_source->record_upstream_last_modified_date($last_modified)
+        if ( ( $last_modified ? $last_modified->epoch : 0 )
+             > ( $last_modified_datetime ? $last_modified_datetime->epoch : 0 ) );
+    $self->sync_source->record_upstream_last_txn($last_txn)
+        if ( ( $last_txn || 0 ) > ( $self->sync_source->upstream_last_txn || 0 ) );
 }
 
 
@@ -112,8 +116,14 @@ sub _translate_final_ticket_state {
         }
     }
 
-    $ticket->{$_} = $self->rt_time_to_iso( $ticket->{$_} )
-        for grep defined $ticket->{$_}, qw(Created Resolved Told LastUpdated Due Starts Started);
+    for my $date (grep defined $ticket->{$_}, qw(Created Resolved Told LastUpdated Due Starts Started)) {
+        my $dt = App::SD::Util::string_to_datetime($ticket->{$date});
+        if ($dt) {
+            $ticket->{$date} =  $dt->ymd('-')." ".$dt->hms(":");
+        } else {
+            delete $ticket->{$date}
+        }
+    }
 
     $ticket->{$_} =~ s/ minutes$//
         for grep defined $ticket->{$_}, qw(TimeWorked TimeLeft TimeEstimated);
@@ -145,12 +155,17 @@ sub find_matching_tickets {
         # XXX TODO we are playing FAST AND LOOSE WITH DATE MATH
         # XXX TODO THIS WILL HURT US SOME DAY
         # At that time, Jesse will buy you a beer.
-        my $before = HTTP::Date::str2time($self->sync_source->upstream_last_modified_date() ) - (86400 + 7200) ; # 26 hours ago deals with most any possible edge case
+        my $before = App::SD::Util::string_to_datetime($self->sync_source->upstream_last_modified_date());
+        die "Failed to parse '".$self->sync_source->upstream_last_modified_date() ."' as a timestamp" unless ($before);
+        ; # 26 hours ago deals with most any possible edge case
+        $before->subtract(hours => 26);
 
 
-        $query = "($query) AND LastUpdated >= '".HTTP::Date::time2iso($before) ."'";
+        $query = "($query) AND LastUpdated >= '".$before->ymd('-'). " " .$before->hms(':') ."'";
 
-        $self->sync_source->log("Skipping all tickets not updated since ".HTTP::Date::time2iso($before));
+    
+        warn $query;
+        $self->sync_source->log("Skipping all tickets not updated since ".$before->iso8601);
     }
 
     return $self->sync_source->rt->search( type => 'ticket', query => $query );
@@ -503,13 +518,6 @@ sub resolve_user_id_to {
 memoize 'resolve_user_id_to';
 
 
-sub rt_time_to_iso {
-    my $self = shift;
-    my $date = shift;
-
-    return undef if $date eq 'Not set';
-    return HTTP::Date::time2iso($date);
-}
 
 our %PROP_MAP = (
     subject         => 'summary',
diff --git a/lib/App/SD/Util.pm b/lib/App/SD/Util.pm
new file mode 100644
index 0000000..415b471
--- /dev/null
+++ b/lib/App/SD/Util.pm
@@ -0,0 +1,28 @@
+package App::SD::Util;
+use DateTime;
+
+sub string_to_datetime {
+    my $date= shift;
+    if ($date =~ /^(\d{4})-(\d{2})-(\d{2})[T\s](\d{1,2}):(\d{2}):(\d{2})Z?$/ ){
+        my ($year,$month,$day, $hour,$min,$sec) = ($1,$2,$3,$4,$5,$6);
+        my $dt = DateTime->new( year => $year,
+                                month => $month,
+                                day => $day,
+                                hour => $hour,
+                                minute => $min,
+                                second => $sec,
+                                time_zone => 'GMT');
+        return $dt;
+    } elsif ($date) {
+        require DateTime::Format::Natural;
+        # XXX DO we want floating or GMT?
+        my $parser = DateTime::Format::Natural->new(time_zone => 'floating');
+        my $dt = $parser->parse_datetime($date);
+        if ($parser->success) {
+            return $dt;
+        } 
+    }
+    return undef;
+}
+
+1;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list