~adiroiban/+junk/rosetta-group-review

« back to all changes in this revision

Viewing changes to trans-grous-review.pl

  • Committer: Adi Roiban
  • Date: 2009-07-09 14:31:12 UTC
  • Revision ID: adi@roiban.ro-20090709143112-p4p023toy9teif7d
fix parsing of lp

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
my @templates_review;
11
11
my %langs;
12
12
my %langs_name;
13
 
my %templates_review_nr;
 
13
my %templates_review;
 
14
my %templates_url;
 
15
my %langs_total_review;
 
16
my %langs_total_untranslated;
14
17
 
15
18
#login
16
19
# curl -c /tmp/cook -d "loginpage_email=USER&loginpage_password=PASS&loginpage_submit_login=Log+In" https://edge.launchpad.net/+login
19
22
# find projects
20
23
open (FH, "$curl https://translations.launchpad.net/+groups/".$group."/ 2> /dev/null |") or die "Failed to open rosetta group lists";
21
24
while(<FH>) {
22
 
 
23
25
    if ($_ =~ m/.*<a href="\/(.*)" class="sprite product">(.*)<\/a>.*/){
24
 
 
25
 
    print "Found project: $2\n";
 
26
    print "Found project: $1 : $2\n";
26
27
    push(@projects,$1);
27
28
    }
28
29
 
30
31
close(FH);
31
32
 
32
33
 
33
 
 
34
 
# find link to all templates
 
34
# find status to all templates recommended translation template
35
35
my $project;
 
36
my $current_language;
 
37
my $current_value;
 
38
$current_language="";
 
39
$current_value=0;
36
40
foreach $project (@projects) {
37
41
    open (FH, "$curl https://translations.launchpad.net/".$project." 2> /dev/null |") or die "Failed to open team project lists";
38
 
   while(<FH>) {    
39
 
       #print $_;
40
 
        if ($_ =~ m#.*<a href="(/[^/]+/[^/]+/\+pots/[^/]+)">*#g) {
41
 
            print "Found all templates for: $1\n";
42
 
            push(@templates_all,$1);
43
 
        }
44
 
    } 
45
 
    close(FH);
46
 
 
47
 
}
48
 
 
49
 
# find templates
50
 
my $template_all;
51
 
foreach $template_all (@templates_all) {
52
 
    open (FH, "$curl https://translations.launchpad.net/".$template_all." 2> /dev/null |") or die "Failed to open team project lists";
53
 
   while(<FH>) {    
54
 
       #print $_;
55
 
 
56
 
        if ($_ =~ m#.*    <a href="(/(.*)/.*/\+pots/.*/([^/]+)/\+translate\?show=new_suggestions)">(\d+)</a>
57
 
.*#) {
58
 
 
59
 
            print "Found review template for project $2 lang $3: $1\n";
60
 
            $langs{$3} .= "|".$1;
61
 
            $templates_review_nr{$1} = $4;
62
 
            push(@templates_review,$1);
63
 
        }
64
 
 
65
 
        if ($_ =~ m#.*    <a href="/(.*)/.*/\+pots/.*/([^/]+)/\+translate">(.*)</a>
66
 
.*#) {
67
 
 
68
 
            $langs_name{$2} = $3;
69
 
        }
70
 
 
71
 
 
72
 
 
73
 
    } 
74
 
    close(FH);
75
 
 
76
 
}
77
 
 
78
 
generate:
79
 
my @needs_review;
80
 
my $template;
81
 
# generate HTML + RSS feeds
 
42
    while(<FH>) {
 
43
       #print $_;
 
44
 
 
45
        if ($_ =~ m#.*    <a href="(/(.*)/.*/\+pots/.*/([^/]+)/\+translate)">(.*)</a>
 
46
.*#) {
 
47
            #print "Found for $project $3 $4\n";
 
48
            $templates_url{$project.$3}=$1;
 
49
            $langs_name{$3} = $4;
 
50
            $current_language = $3;
 
51
            $current_value = 0;
 
52
        }
 
53
 
 
54
        if (($current_language ne "") &&
 
55
            ($_ =~ m/<span class="sortkey">(.*)<\/span>/)) {
 
56
 
 
57
            if ($current_value == 2) {
 
58
                $langs_total_untranslated{$current_language} += $1;
 
59
                #print "Found $project $current_language untranslated: $1\n";
 
60
            }
 
61
 
 
62
            if ($current_value == 3) {
 
63
                $langs_total_review{$current_language} += $1;
 
64
                $templates_review{$project.$current_language}=$1;
 
65
                #print "Found  $project $current_language review: $1\n";
 
66
            }
 
67
            $current_value++;
 
68
            #$langs{$3} .= "|".$1
 
69
            #$templates_review_nr{$1} = $4;
 
70
            #push(@templates_review,$1);
 
71
        }
 
72
    }
 
73
    close(FH);
 
74
}
 
75
 
 
76
# generate HTML
82
77
open (INDEX_PAGE, ">$root/index.html");
83
78
write_header (*INDEX_PAGE{IO});
84
79
print INDEX_PAGE "<h1>Translation status for $group</h1>";
88
83
        <thead>
89
84
          <tr>
90
85
            <th>Language</th>
91
 
            <th>Needs review</th>
 
86
            <th>Total needs review</th>
92
87
          </tr>
93
88
        </thead>
94
89
        <tbody>';
95
90
 
96
91
 
97
92
#$langs{'fr'} ="|/geany/trunk/+pots/geany/fr/+translate?show=new_suggestions|/deja-dup/trunk/+pots/deja-dup/fr/+translate?show=new_suggestions|/gui-ufw/trunk/+pots/gufw/fr/+translate?show=new_suggestions";
98
 
foreach  $lang (sort (keys(%langs))) {
99
 
    @needs_review = split(/\|/,$langs{$lang});
100
 
    shift(@needs_review);
101
 
    print INDEX_PAGE "<tr>
102
 
            <td><a href='$lang.html'>".$langs_name{$lang}."</a></td><td><a href='$lang.html'>".scalar(@needs_review)."</a></td>
103
 
          </tr>\n";
 
93
foreach  $lang (sort (keys(%langs_name))) {
 
94
    print INDEX_PAGE "<tr>".
 
95
            "<td><a href='$lang.html'>".$langs_name{$lang}."</a></td>".
 
96
            "<td><a href='$lang.html'>".$langs_total_review{$lang}."</a></td>".
 
97
            "</tr>\n";
 
98
}
 
99
print INDEX_PAGE "</tbody></table>\n";
 
100
write_footer(*INDEX_PAGE{IO});
 
101
close (INDEX_PAGE);
104
102
 
 
103
foreach  $lang (sort (keys(%langs_name))) {
105
104
    open LANG_PAGE, ">$root/$lang.html"; 
106
105
    write_header (*LANG_PAGE{IO});
107
106
    print LANG_PAGE "<h1>Translation status for group $group, language ".$langs_name{$lang}."</h1>";
108
107
    print LANG_PAGE '<table class="sortable listing" id="translation-groups" width="100%">
109
108
        <thead>
110
109
          <tr>
111
 
            <th>Template</th>
 
110
            <th>Project</th>
112
111
            <th>Needs review</th>
113
112
          </tr>
114
113
        </thead>
115
114
        <tbody>';
116
 
 
117
 
 
118
 
    my $template_short;
119
 
    foreach $template (@needs_review) {
120
 
        $template_short = $template;
121
 
        $template_short =~ s/\+translate\?show=new_suggestions//;
122
 
        print LANG_PAGE "<tr>
123
 
            <td><a href='http://translations.launchpad.net/$template'>$template_short</a></td><td>".$templates_review_nr{$template}."</td>
124
 
          </tr>\n";
125
 
 
 
115
    my $url;
 
116
    foreach $project (@projects) {
 
117
        if (defined($templates_url{$project.$lang})){
 
118
            $url = 'http://translations.launchpad.net/'.$templates_url{$project.$lang}."?show=new_suggestions";
 
119
            print LANG_PAGE "<tr>".
 
120
                "<td><a href='$url'>$project</a></td>".
 
121
                "<td>".$templates_review{$project.$lang}."</td>".
 
122
                "</tr>\n";
 
123
        }
126
124
    }
127
125
 
128
126
    print LANG_PAGE "</tbody></table>\n";
129
127
    write_footer(*LANG_PAGE{IO});
130
128
    close LANG_PAGE;
131
 
 
132
129
}
133
 
print INDEX_PAGE "</tbody></table>\n";
134
 
write_footer(*INDEX_PAGE{IO});
135
 
close (INDEX_PAGE);
136
130
 
137
131
sub write_header {
138
132
   local *FH = shift;