source: osm/applications/editors/josm/i18n/launchpad.pl@ 28064

Last change on this file since 28064 was 27289, checked in by stoecker, 13 years ago

remove ar, he and is languages

  • Property svn:executable set to *
  • Property svn:keywords set to Revision
File size: 8.1 KB
Line 
1#!/usr/bin/perl -w
2# -CDSL would be better than explicit encoding settings
3
4use strict;
5use utf8;
6
7my ($user, $pwd);
8
9# Three ways to handle login data:
10 # Enter data directly in these two lines (Be careful witn svn checkin later!)
11 # create a file "uploadpot.pl_credits" containing the two lines with proper values
12 # leave credits empty and enter them on runtime
13$user = '';
14$pwd = '';
15
16# list of supported languages
17my %lang = map {$_ => 1} (
18"bg", "cs", "da", "de", "el", "en_AU", "en_GB",
19"es", "et", "eu", "fi", "fr", "gl", "id",
20"it", "ja", "nb", "nl", "pl", "pt_BR", "ru", "sk",
21"sv", "tr", "uk", "zh_CN", "zh_TW"
22);
23
24my $revision = '$Revision: 27289 $';
25$revision =~ s/^.*?(\d+).*$/$1/;
26my $agent = "JOSM_Launchpad/1.$revision";
27
28my $count = 0;#11;
29my $cleanall = 0;#1;
30my $upload = 0;#1;
31
32if($#ARGV != 0)
33{
34 warn "No argument given (try Launchpad download URL, \"bzr\", \"bzronly\", \"upload\" or \"download\").";
35 system "ant";
36 makeupload();
37}
38elsif($ARGV[0] eq "bzr" || $ARGV[0] eq "bzronly")
39{
40 mkdir "build";
41 die "Could not change into new data dir." if !chdir "build";
42 system "bzr export -v josm_trans lp:~openstreetmap/josm/josm_trans";
43 chdir "..";
44 copypo("build/josm_trans/josm");
45 system "rm -rv build/josm_trans";
46 if($ARGV[0] ne "bzronly")
47 {
48 system "ant";
49 makeupload();
50 }
51}
52elsif($ARGV[0] eq "upload")
53{
54 potupload();
55}
56elsif($ARGV[0] eq "download")
57{
58 podownload();
59}
60elsif($ARGV[0] eq "stats")
61{
62 getstats();
63}
64else
65{
66 mkdir "build";
67 mkdir "build/josm_trans";
68 die "Could not change into new data dir." if !chdir "build/josm_trans";
69 system "wget $ARGV[0]";
70 system "tar -xf laun*";
71 chdir "../..";
72 copypo("build/josm_trans");
73 system "rm -rv build/josm_trans";
74 system "ant";
75 makeupload();
76}
77
78sub makeupload
79{
80 if($upload)
81 {
82 my $outdate = `date -u +"%Y-%m-%dT%H_%M_%S"`;
83 chomp $outdate;
84 mkdir "build/josm";
85 system "cp po/*.po po/josm.pot build/josm";
86 chdir "build";
87 if(!$count)
88 {
89 system "tar -cjf ../launchpad_upload_josm_$outdate.tar.bz2 josm";
90 }
91 else
92 {
93 my @files = sort glob("josm/*.po");
94 my $num = 1;
95 while($#files >= 0)
96 {
97 my @f = splice(@files, 0, $count);
98 system "tar -cjf ../launchpad_upload_josm_${outdate}_$num.tar.bz2 josm/josm.pot ".join(" ",@f);
99 ++$num;
100 }
101 }
102 system "rm -rv josm";
103 chdir "..";
104 }
105}
106
107sub copypo
108{
109 my ($path) = @_;
110 foreach my $name (split("\n", `find $path -name "*.po"`))
111 {
112 $name =~ /([a-zA-Z_]+)\.po/;
113 if($lang{$1})
114 {
115 system "cp -v $name po/$1.po";
116 }
117 elsif($cleanall)
118 {
119 local $/; undef $/;
120 open FILE,"<",$name or die;
121 my $x = <FILE>;
122 close FILE;
123 $x =~ s/\n\n.*$/\n/s;
124 open FILE,">","po/$1.po" or die;
125 print FILE $x;
126 close FILE;
127 }
128 }
129}
130
131sub dologin
132{
133 require WWW::Mechanize;
134
135 my $mech = WWW::Mechanize->new("agent" => $agent);
136
137 #$mech->add_handler("request_send" => sub {
138 # my($request, $ua, $h) = @_;
139 # printf "FORM: %s\n", $request->content();
140 # return undef;
141 #});
142 $mech->get("https://translations.launchpad.net/josm/trunk/+login");
143 #print $mech->status() ." - ". $mech->uri()."\n";
144 $mech->submit_form(form_number => 1);
145 getcredits();
146 #print $mech->status() ." - ". $mech->uri()."\n";
147 $mech->submit_form(with_fields => {"email" => $user, "password" => $pwd});
148 #$mech->dump_headers();
149 #print $mech->status() ." - ". $mech->uri()."\n";
150 #print $mech->content();
151 my $form = $mech->form_name("decideform");
152 die "Could not login.\n" if !$form;
153 my %par = ("yes" => ""); # We need to add "yes" or it does not work
154 foreach my $p ($form->param)
155 {
156 $par{$p} = $form->value($p);
157 }
158 $mech->post($form->action, \%par);
159 #$mech->dump_headers();
160 #print $mech->content();
161 #print $mech->status() ." - ". $mech->uri()."\n";
162 #$mech->dump_forms();
163 return $mech;
164}
165
166sub potupload
167{
168 my $mech = dologin();
169 $mech->get("https://translations.launchpad.net/josm/trunk/+translations-upload");
170 chdir("po");
171 $mech->submit_form(with_fields => {"file" => "josm.pot"});
172 chdir("..");
173}
174
175sub podownload
176{
177 my $mech = dologin();
178 $mech->get("https://translations.launchpad.net/josm/trunk/+export");
179 $mech->submit_form(with_fields => {"format" => "PO"});
180 if(!($mech->content() =~ /receive an email shortly/))
181 {
182 warn "Error requesting file\n";
183 }
184}
185
186sub getcredits
187{
188 if(!$user || !$pwd)
189 {
190 require Term::ReadKey;
191 local undef $/;
192 if(open FILE, "launchpad.pl_credits")
193 {
194 eval <FILE>;
195 close FILE;
196 }
197
198 if(!$user)
199 {
200 Term::ReadKey::ReadMode(4); # Turn off controls keys
201 printf("Enter username: ");
202 for(;;)
203 {
204 my $c = getc();
205 print $c;
206 last if $c eq "\n";
207 $user .= $c;
208 }
209 Term::ReadKey::ReadMode(0);
210 }
211
212 if(!$pwd)
213 {
214 Term::ReadKey::ReadMode(4); # Turn off controls keys
215 printf("Enter password: ");
216 for(;;)
217 {
218 my $c = getc();
219 last if $c eq "\n";
220 print "*";
221 $pwd .= $c;
222 }
223 print "\n";
224 Term::ReadKey::ReadMode(0);
225 }
226 }
227}
228
229sub doget
230{
231 my ($mech, $page, $arg) = @_;
232 for(my $i = 1; $i <= 5; $i++)
233 {
234 $mech->timeout(30);
235 eval
236 {
237 $mech->get($page);
238 };
239 my $code = $mech->status();
240 print "Try $i: ($code) $@" if $@;
241 return $mech if !$@;
242 sleep(30+5*$i);
243 last if $arg && $arg eq "no503" and $code == 503;
244 $mech = WWW::Mechanize->new("agent" => $agent);
245 }
246 return $mech;
247}
248
249sub getstats
250{
251 my %results;
252 require WWW::Mechanize;
253 require Data::Dumper;
254 require URI::Escape;
255 my $mech = WWW::Mechanize->new("agent" => $agent);
256
257 if(open DFILE,"<:utf8","launchpadtrans.data")
258 {
259 local $/;
260 $/ = undef;
261 my $val = <DFILE>;
262 eval $val;
263 close DFILE;
264 }
265
266 binmode STDOUT, ":utf8";
267
268 open FILE,">:utf8","launchpadtrans.txt" or die "Could not open output file.";
269
270 for my $lang (sort keys %lang)
271 {
272 doget($mech, "https://translations.launchpad.net/josm/trunk/+pots/josm/$lang/");
273 sleep(1);
274 my $cont = $mech->content();
275 while($cont =~ /<a href="https?:\/\/launchpad.net\/~(.*?)" class="sprite person(-inactive)?">(.*?)<\/a>/g)
276 {
277 my ($code, $inactive, $name) = ($1, $2, $3);
278 if(exists($results{$code}{$lang}))
279 {
280 printf "%-5s - %-30s - Found - %s\n", $lang,$code,$name;
281 next;
282 }
283 my $urlcode = URI::Escape::uri_escape($code);
284 $mech = doget($mech, "https://translations.launchpad.net/josm/trunk/+pots/josm/$lang/+filter?person=$urlcode", "no503");
285 sleep(1);
286 my $cont = $mech->content() || "";
287 my ($count) = $cont =~ /of[\r\n\t ]+?(\d+)[\r\n\t ]+?result/;
288 if($count && $mech->status == 200)
289 {
290 $results{$code}{NAME} = $name;
291 $results{$code}{$lang} = $count;
292 $results{$code}{TOTAL} += $count;
293 if(open DFILE,">:utf8","launchpadtrans.data")
294 {
295 print DFILE Data::Dumper->Dump([\%results],['*results']);
296 close DFILE;
297 }
298 printf "%-5s - %-30s - %5d - %s\n", $lang,$code,$count,$name;
299
300 }
301 else
302 {
303 printf "%-5s - %-30s - Skip - %s\n", $lang,$code,$name;
304 }
305 }
306 }
307 for my $code (sort {$results{$b}{TOTAL} <=> $results{$a}{TOTAL}} keys %results)
308 {
309 print FILE "$results{$code}{NAME}:$results{$code}{TOTAL}";
310 printf "%5d - %-50s",$results{$code}{TOTAL}, $results{$code}{NAME};
311 for my $lang (sort keys %{$results{$code}})
312 {
313 next if $lang eq "NAME" or $lang eq "TOTAL";
314 print FILE ";$lang=$results{$code}{$lang}";
315 printf " - %-5s=%5d",$lang, $results{$code}{$lang};
316 }
317 print FILE "\n";
318 print "\n";
319 }
320}
Note: See TracBrowser for help on using the repository browser.