1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 |
|
---|
5 | my ($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
|
---|
15 | my %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 |
|
---|
22 | my $count = 0;#11;
|
---|
23 | my $cleanall = 0;#1;
|
---|
24 | my $upload = 0;#1;
|
---|
25 |
|
---|
26 | if($#ARGV != 0)
|
---|
27 | {
|
---|
28 | warn "No argument given (try Launchpad download URL, \"bzr\", \"bzronly\", \"upload\" or \"download\").";
|
---|
29 | system "ant";
|
---|
30 | makeupload();
|
---|
31 | }
|
---|
32 | elsif($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";
|
---|
40 | if($ARGV[0] ne "bzronly")
|
---|
41 | {
|
---|
42 | system "ant";
|
---|
43 | makeupload();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | elsif($ARGV[0] eq "upload")
|
---|
47 | {
|
---|
48 | potupload();
|
---|
49 | }
|
---|
50 | elsif($ARGV[0] eq "download")
|
---|
51 | {
|
---|
52 | podownload();
|
---|
53 | }
|
---|
54 | else
|
---|
55 | {
|
---|
56 | mkdir "build";
|
---|
57 | mkdir "build/josm_trans";
|
---|
58 | die "Could not change into new data dir." if !chdir "build/josm_trans";
|
---|
59 | system "wget $ARGV[0]";
|
---|
60 | system "tar -xf laun*";
|
---|
61 | chdir "../..";
|
---|
62 | copypo("build/josm_trans");
|
---|
63 | system "rm -rv build/josm_trans";
|
---|
64 | system "ant";
|
---|
65 | makeupload();
|
---|
66 | }
|
---|
67 |
|
---|
68 | sub makeupload
|
---|
69 | {
|
---|
70 | if($upload)
|
---|
71 | {
|
---|
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 "..";
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | sub copypo
|
---|
98 | {
|
---|
99 | my ($path) = @_;
|
---|
100 | foreach my $name (split("\n", `find $path -name "*.po"`))
|
---|
101 | {
|
---|
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 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | sub 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");
|
---|
142 | die "Could not login.\n" if !$form;
|
---|
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 |
|
---|
156 | sub 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 |
|
---|
165 | sub 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 |
|
---|
176 | sub 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 | }
|
---|