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

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

minor fix

  • Property svn:executable set to *
File size: 5.4 KB
RevLine 
[16400]1#!/usr/bin/perl -w
2
3use strict;
4
[27020]5my ($user, $pwd);
6
7# Three ways to handle login data:
8 # Enter data directly in these two lines (Be careful witn svn checkin later!)
9 # create a file "uploadpot.pl_credits" containing the two lines with proper values
10 # leave credits empty and enter them on runtime
11$user = '';
12$pwd = '';
13
14# list of supported languages
[26928]15my %lang = map {$_ => 1} (
16"ar", "bg", "cs", "da", "de", "el", "en_AU", "en_GB",
17"es", "et", "eu", "fi", "fr", "gl", "he", "id", "is",
18"it", "ja", "nb", "nl", "pl", "pt_BR", "ru", "sk",
19"sv", "tr", "uk", "zh_CN", "zh_TW"
20);
21
[25528]22my $count = 0;#11;
23my $cleanall = 0;#1;
[26928]24my $upload = 0;#1;
[16400]25
[16973]26if($#ARGV != 0)
[16400]27{
[27020]28 warn "No argument given (try Launchpad download URL, \"bzr\", \"bzronly\", \"upload\" or \"download\").";
29 system "ant";
30 makeupload();
[16400]31}
[26928]32elsif($ARGV[0] eq "bzr" || $ARGV[0] eq "bzronly")
33{
34 mkdir "build";
35 die "Could not change into new data dir." if !chdir "build";
36 system "bzr export -v josm_trans lp:~openstreetmap/josm/josm_trans";
37 chdir "..";
38 copypo("build/josm_trans/josm");
39 system "rm -rv build/josm_trans";
[27020]40 if($ARGV[0] ne "bzronly")
41 {
42 system "ant";
43 makeupload();
44 }
[26928]45}
[27020]46elsif($ARGV[0] eq "upload")
47{
48 potupload();
49}
50elsif($ARGV[0] eq "download")
51{
52 podownload();
53}
[16973]54else
55{
[26849]56 mkdir "build";
[26928]57 mkdir "build/josm_trans";
58 die "Could not change into new data dir." if !chdir "build/josm_trans";
[16973]59 system "wget $ARGV[0]";
60 system "tar -xf laun*";
[26849]61 chdir "../..";
[26928]62 copypo("build/josm_trans");
63 system "rm -rv build/josm_trans";
[27020]64 system "ant";
65 makeupload();
[26928]66}
67
[27020]68sub makeupload
[26928]69{
[27020]70 if($upload)
[16973]71 {
[27020]72 my $outdate = `date -u +"%Y-%m-%dT%H_%M_%S"`;
73 chomp $outdate;
74 mkdir "build/josm";
75 system "cp po/*.po po/josm.pot build/josm";
76 chdir "build";
77 if(!$count)
78 {
79 system "tar -cjf ../launchpad_upload_josm_$outdate.tar.bz2 josm";
80 }
81 else
82 {
83 my @files = sort glob("josm/*.po");
84 my $num = 1;
85 while($#files >= 0)
86 {
87 my @f = splice(@files, 0, $count);
88 system "tar -cjf ../launchpad_upload_josm_${outdate}_$num.tar.bz2 josm/josm.pot ".join(" ",@f);
89 ++$num;
90 }
91 }
92 system "rm -rv josm";
93 chdir "..";
[26928]94 }
95}
96
97sub copypo
98{
99 my ($path) = @_;
100 foreach my $name (split("\n", `find $path -name "*.po"`))
101 {
[27020]102 $name =~ /([a-zA-Z_]+)\.po/;
103 if($lang{$1})
104 {
105 system "cp -v $name po/$1.po";
106 }
107 elsif($cleanall)
108 {
109 local $/; undef $/;
110 open FILE,"<",$name or die;
111 my $x = <FILE>;
112 close FILE;
113 $x =~ s/\n\n.*$/\n/s;
114 open FILE,">","po/$1.po" or die;
115 print FILE $x;
116 close FILE;
117 }
[16973]118 }
119}
[27020]120
121sub dologin
122{
123 require WWW::Mechanize;
124
125 my $mech = WWW::Mechanize->new("agent" => "JOSM_Launchpad/1.0");
126
127 #$mech->add_handler("request_send" => sub {
128 # my($request, $ua, $h) = @_;
129 # printf "FORM: %s\n", $request->content();
130 # return undef;
131 #});
132 $mech->get("https://translations.launchpad.net/josm/trunk/+login");
133 #print $mech->status() ." - ". $mech->uri()."\n";
134 $mech->submit_form(form_number => 1);
135 getcredits();
136 #print $mech->status() ." - ". $mech->uri()."\n";
137 $mech->submit_form(with_fields => {"email" => $user, "password" => $pwd});
138 #$mech->dump_headers();
139 #print $mech->status() ." - ". $mech->uri()."\n";
140 #print $mech->content();
141 my $form = $mech->form_name("decideform");
[27026]142 die "Could not login.\n" if !$form;
[27020]143 my %par = ("yes" => ""); # We need to add "yes" or it does not work
144 foreach my $p ($form->param)
145 {
146 $par{$p} = $form->value($p);
147 }
148 $mech->post($form->action, \%par);
149 #$mech->dump_headers();
150 #print $mech->content();
151 #print $mech->status() ." - ". $mech->uri()."\n";
152 #$mech->dump_forms();
153 return $mech;
154}
155
156sub potupload
157{
158 my $mech = dologin();
159 $mech->get("https://translations.launchpad.net/josm/trunk/+translations-upload");
160 chdir("po");
161 $mech->submit_form(with_fields => {"file" => "josm.pot"});
162 chdir("..");
163}
164
165sub podownload
166{
167 my $mech = dologin();
168 $mech->get("https://translations.launchpad.net/josm/trunk/+export");
169 $mech->submit_form(with_fields => {"format" => "PO"});
170 if(!($mech->content() =~ /receive an email shortly/))
171 {
172 warn "Error requesting file\n";
173 }
174}
175
176sub getcredits
177{
178 if(!$user || !$pwd)
179 {
180 require Term::ReadKey;
181 local undef $/;
182 if(open FILE, "launchpad.pl_credits")
183 {
184 eval <FILE>;
185 close FILE;
186 }
187
188 if(!$user)
189 {
190 Term::ReadKey::ReadMode(4); # Turn off controls keys
191 printf("Enter username: ");
192 for(;;)
193 {
194 my $c = getc();
195 print $c;
196 last if $c eq "\n";
197 $user .= $c;
198 }
199 Term::ReadKey::ReadMode(0);
200 }
201
202 if(!$pwd)
203 {
204 Term::ReadKey::ReadMode(4); # Turn off controls keys
205 printf("Enter password: ");
206 for(;;)
207 {
208 my $c = getc();
209 last if $c eq "\n";
210 print "*";
211 $pwd .= $c;
212 }
213 print "\n";
214 Term::ReadKey::ReadMode(0);
215 }
216 }
217}
Note: See TracBrowser for help on using the repository browser.