Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 78 lines (66 sloc) 2.446 kB
1448eed @franckcuny initial import
authored
1 #!/usr/bin/perl -w
2 use strict;
3 use feature ':5.10';
4
5 use Getopt::Long;
6
7 use lib ( 'lib' );
8 use CPAN::Testers;
9 use CPAN::cpants;
10 use CPAN::mapcpan;
07241f5 @franckcuny remove modules, add datetime, add version
authored
11 use DateTime;
1448eed @franckcuny initial import
authored
12
13 my $options = GetOptions(
14 'dbtest=s' => \my $db_test,
15 'dball=s' => \my $db_all,
16 'dbout=s' => \my $db_out,
17 );
18
2a32bcd @franckcuny use datetime object
authored
19 # TODO
20 # generer une carte des auteurs
21
1448eed @franckcuny initial import
authored
22 my $sqltest
23 = CPAN::Testers->connect( "dbi:SQLite:dbname=" . $db_test, '', '' );
24 my $sqlall = CPAN::cpants->connect( "dbi:SQLite:dbname=" . $db_all, '', '' );
25 my $dbmap = CPAN::cpanmap->connect( "dbi:SQLite:dbname=" . $db_out, "", "" );
26
27 $dbmap->deploy;
28
29 my $dists = $sqlall->resultset( 'dist' )->search( { is_core => 0 } );
30
31 while ( my $dist = $dists->next ) {
32 print "processing ".$dist->package ."... ";
33 my $map_package = $dbmap->resultset( 'packages' )
34 ->find_or_create( { dist => $dist->dist, } );
35
36 my $tests_pass = $sqltest->resultset( 'reports' )
37 ->count( { distribution => $dist->dist, status => 'PASS' } );
38 my $tests_fail = $sqltest->resultset( 'reports' )
39 ->count( { distribution => $dist->dist, status => 'FAIL' } );
40 my $total_tests = $tests_pass + $tests_fail;
41 $total_tests = 1 if $total_tests == 0;
42 my $tests_success = int( ( $tests_pass / $total_tests ) * 100 );
43
44 my $author = $sqlall->resultset( 'author' )->find( $dist->author );
07241f5 @franckcuny remove modules, add datetime, add version
authored
45 my ($year, $month, $day) = $dist->released =~ /^(\d{4})-(\d{2})-(\d{2})/;
1448eed @franckcuny initial import
authored
46 $map_package->update(
47 { tests_success => $tests_success,
48 author => $author->pauseid,
07241f5 @franckcuny remove modules, add datetime, add version
authored
49 version => $dist->version,
50 released =>
51 DateTime->new( year => $year, month => $month, day => $day ),
1448eed @franckcuny initial import
authored
52 }
53 );
54
55 my $deps = $sqlall->resultset( 'uses' )->search(
56 { dist => $dist->id,
57 in_code => 1,
58 in_tests => 0
59 }
60 );
61 while ( my $dep = $deps->next ) {
62 my $dist_dep = $sqlall->resultset( 'dist' )->find( $dep->in_dist );
63 next
64 if !defined $dep->in_dist
65 || $dep->in_dist == 0
66 || $dist_dep->is_core;
67 my $pack_dep = $dbmap->resultset( 'packages' )
68 ->find_or_create( { dist => $dist_dep->dist, } );
69 my $node_from = $dbmap->resultset( 'edges' )->create(
70 { dist_from => $map_package->id,
71 dist_to => $pack_dep->id
72 }
73 );
74 }
75 say "done";
76 }
77
78 say "importing CPAN data is terminated";
Something went wrong with that request. Please try again.