[Bps-public-commit] cpan2rt branch, modules-in-queue-cf, created. 6ac5858a04fc2c6ad443fd43b7b892e75ff15de1

Ruslan Zakirov ruz at bestpractical.com
Fri May 27 17:55:04 EDT 2011


The branch, modules-in-queue-cf has been created
        at  6ac5858a04fc2c6ad443fd43b7b892e75ff15de1 (commit)

- Log -----------------------------------------------------------------
commit e31878be522b5b74b0db4a00cb0afa820486d26c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jan 10 00:35:11 2011 +0300

    minor

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index e4941df..41a9d91 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -304,7 +304,7 @@ sub sync_distributions {
     my @errors;
 
     my $last = ''; my $i = 0;
-    my $syncer = sub {
+    $self->for_mapped_distributions( sub {
         my $file = $_[2];
         return if $last eq $file;
 
@@ -319,8 +319,7 @@ sub sync_distributions {
         # we don't sync version here as sync_versions does this better
 
         DBIx::SearchBuilder::Record::Cachable->FlushCache unless ++$i % 100;
-    };
-    $self->for_mapped_distributions( $syncer );
+    } );
 
     return (undef, @errors) if @errors;
     return (1);

commit eac40c87ac67d89339d9b75841133bc647ccaac0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jan 10 00:36:14 2011 +0300

    for_dist_modules method, runs callback with ($dist, @modules)

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index 41a9d91..bd48796 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -246,6 +246,37 @@ sub for_mapped_distributions {
     close $fh;
 }
 
+sub for_dist_modules {
+    my $self = shift;
+    my $callback = shift;
+
+    my $file = 'dist_to_module.txt';
+    my $path = $self->file_path( $file );
+    if ( !-e $path || (stat $path)[9] != (stat $self->file_path('02packages.details.txt'))[9] ) {
+        open my $fh, "|-", 'sort', '-u', '>', $path
+            or die "Couldn't open sorter: $!";
+        $self->for_mapped_distributions( sub {
+            return unless my $dinfo = $self->file2distinfo('authors/id/'. $_[2]);
+            print $fh $dinfo->dist .' '. $_[0]
+        } );
+        close $fh;
+    }
+
+    my ($dist, @modules) = ( '', () );
+    open my $fh, "<:utf8", $path or die "Couldn't open '$path': $!";
+    while ( my $str = <$fh> ) {
+        my ($d, $m) = split /\s+/, $str;
+        if ( $d eq $dist ) {
+            push @modules, $m;
+            next;
+        }
+
+        $callback->( $dist, @modules );
+        ($dist, @modules) = ($d, $m);
+    }
+    $callback->( $dist, @modules );
+}
+
 sub for_all_distributions {
     my $self = shift;
     my $callback = shift;

commit cb3a7bbc36ce456f0bcdc7a1a451854cc8dde59d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jan 10 00:37:40 2011 +0300

    load_or_create_modules_cf that creates Modules CF that applies to queues

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index bd48796..6b8da79 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -785,6 +785,25 @@ sub load_or_create_version_cf {
     return ($cf);
 }
 
+sub load_or_create_modules_cf {
+    my $self = shift;
+
+    my $cf = RT::Queue->new( $RT::SystemUser )->LoadCustomFieldByIdentifier('Modules');
+    return $cf if $cf && $cf->id;
+
+    $cf = RT::CustomField->new( $RT::SystemUser );
+    my ($status, $msg) = $cf->Create(
+        Name        => 'Modules',
+        Description => 'Modules of the distribution',
+        Type        => 'Freeform',
+        LookupType  => 'RT::Queue',
+    );
+    return (undef, "Couldn't create custom field: $msg") unless $status; 
+    ($status, $msg) = $cf->AddToObject( RT::Queue->new( $cf->CurrentUser ) );
+    return (undef, "Couldn't apply custom field: $msg") unless $status;
+    return ($cf);
+}
+
 sub create_version_cf {
     my $self = shift;
     my ($queue, $name) = @_;

commit 952c14dc28f3b43d2e37076647af0e151b195c82
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jan 10 00:38:29 2011 +0300

    sync_modules method that updates Modules CF on Queues

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index 6b8da79..611ecce 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -356,6 +356,51 @@ sub sync_distributions {
     return (1);
 }
 
+sub sync_modules {
+    my $self = shift;
+    my $force = shift;
+    if ( !$force && !$self->is_new_file( '02packages.details.txt' ) ) {
+        debug { "Skip syncing, file's not changed\n" };
+        return (1);
+    }
+
+
+    my ($cf, $msg) = $self->load_or_create_modules_cf;
+    return (undef, $msg) unless $cf;
+
+    my @errors;
+    $self->for_dist_modules( sub {
+        my $dist = shift;
+        my @modules = @_;
+
+        my ($queue, @msg) = $self->load_or_create_queue( $dist );
+        unless ( $queue ) {
+            push @errors, @msg;
+            return;
+        }
+
+        my @current = map $_->Content, @{ $queue->CustomFieldValues( $cf )->ItemsArrayRef };
+
+        my $set = List::Compare->new( '--unsorted', \@current, \@modules );
+        foreach ( $set->get_unique ) {
+            debug { "Going to delete $_ from modules list of ". $queue->Name };
+            my ($status, @msg) = $queue->DeleteCustomFieldValue(
+                Field => $cf, Value => $_
+            );
+            push @errors, @msg unless $status;
+        }
+        foreach ( $set->get_complement ) {
+            debug { "Going to add $_ to modules list of ". $queue->Name };
+            my ($status, @msg) = $queue->AddCustomFieldValue(
+                Field => $cf, Value => $_
+            );
+            push @errors, @msg unless $status;
+        }
+
+        DBIx::SearchBuilder::Record::Cachable->FlushCache unless ++$i % 100;
+    } );
+}
+
 sub sync_versions {
     my $self = shift;
     my $force = shift;

commit 6ac5858a04fc2c6ad443fd43b7b892e75ff15de1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 01:51:49 2011 +0400

    call sync_modules from bin/cpan2rt

diff --git a/bin/cpan2rt b/bin/cpan2rt
index b334258..5aa125a 100755
--- a/bin/cpan2rt
+++ b/bin/cpan2rt
@@ -89,6 +89,7 @@ sub cmd_update {
     $importer->sync_distributions( $opt{'force'} ) unless $opt{'skip'}{'distributions'};
     $importer->sync_versions( $opt{'force'} ) unless $opt{'skip'}{'versions'};
     $importer->sync_maintainers( $opt{'force'} ) unless $opt{'skip'}{'maintainers'};
+    $importer->sync_modules( $opt{'force'} ) unless $opt{'skip'}{'modules'};
 }
 
 sub usage {

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



More information about the Bps-public-commit mailing list