source: subversion/applications/editors/josm/plugins/photoadjust/i18n/poimport.pl @ 31953

Last change on this file since 31953 was 30155, checked in by holgermappt, 6 years ago

Reorganized i18n.

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1#! /usr/bin/perl -w
2
3#####################################################################
4### http://www.perl.com/doc/manual/html/utils/pod2man.html
5### http://search.cpan.org/dist/perl/pod/perlpod.pod
6
7=head1 NAME
8
9poimport.pl - Import the translation from the tarball downloaded from
10Launchpad.
11
12=head1 SYNOPSIS
13
14B<poimport.pl> [B<--help>] [B<--man>] [B<--podir> I<po>]
15    [B<--workdir> I<poimport>] [B<--(no)rmworkdir>] I<tarball>
16
17=head1 DESCRIPTION
18
19Import the plugin translations from Launchpad.  The argument
20I<tarball> can be a tarball file that was downloaded from Launchpad, a
21tarball download URL, a JOSM translation branch revision number
22(e.g. I<789>), or the keyword I<latest> for the latest revision.
23Default is to download the latest translation branch revision.
24
25=head1 OPTIONS
26
27=over 4
28
29=item B<--help>
30
31Prints a brief help message and exits.
32
33=item B<--man>
34
35Prints the manual page and exits.
36
37=item B<--podir>
38
39Destination directory relative to directory where this script was
40started in.  Default is F<po>.
41
42=item B<--workdir>
43
44Temporary directory.  A unique directory name that is not used for
45anything else.  Default is F<poimport>.
46
47=item B<--rmworkdir>
48
49Remove the temporary directory after the work is done.  Disable
50removal with B<--normworkdir>.  Default is to remove the temporary
51directory.
52
53=back
54
55=cut
56#####################################################################
57
58use strict;
59use File::Copy;
60use Cwd;
61use File::Spec::Functions;
62use File::Basename;
63use Getopt::Long;
64use Pod::Usage;
65
66### Name of the tarball downloaded from Launchpad.  Or download URL.
67### Or JOSM translation branch revision number.  Or keyword "latest".
68my $tarball;
69#$tarball = "launchpad-export.tar.gz";
70#$tarball = "http://launchpadlibrarian.net/159932691/launchpad-export.tar.gz";
71#$tarball = "http://bazaar.launchpad.net/~openstreetmap/josm/josm_trans/tarball/747";
72#$tarball = "747";
73#$tarball = "http://bazaar.launchpad.net/~openstreetmap/josm/josm_trans/tarball";
74$tarball = "latest";
75my $workdir = "poimport";       ### Temp. directory.
76my $rmworkdir = 1;              ### Remove the temp. directory (0/1)?
77my $podir = "po";               ### Destination directory.
78my $showhelp = 0;               ### Show help screen.
79my $showman = 0;                ### Show manual page of this script.
80
81GetOptions('help|?|h'   => \$showhelp,
82           'man'        => \$showman,
83           'podir=s'    => \$podir,
84           'workdir=s'  => \$workdir,
85           'rmworkdir!' => \$rmworkdir,
86          ) or pod2usage(2);
87
88pod2usage(1) if $showhelp;
89pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
90
91### Check for arguments.  The only supported argument is the tarball.
92if ($#ARGV == 0) {
93  $tarball = $ARGV[0];
94}
95elsif ($#ARGV > 0) {
96  die "This script accepts only one argument.\n";
97}
98
99my $josmtburl = "http://bazaar.launchpad.net/~openstreetmap/josm/josm_trans/"
100  . "tarball";
101
102### Check for JOSM translation branch revision number.
103if ($tarball =~ m/^\d+$/) {
104  $tarball = $josmtburl . "/" . $tarball;
105}
106### Or for keyword "latest", i.e. the latest JOSM translation revision.
107elsif ($tarball eq "latest") {
108  $tarball = $josmtburl;
109}
110
111### Check if tarball is a URL and download it.  The downloaded file
112### will not be removed and is available for a second import.
113my $downurl;
114if ($tarball =~ m,^http://.+/([^/]+)$,) {
115  ### URL: Download file.
116  $downurl = $tarball;
117  my $downfile = $1;
118  if ($downfile =~ m/^\d+$/) {
119    ### Download of revision number.
120    if ($tarball =~ m:/([^/]+)/tarball/(\d+)$:) {
121      $downfile = $1 . "_" . $2 . ".tar.gz";
122    }
123    else {
124      $downfile .= ".tar.gz";
125    }
126  }
127  elsif ($downfile eq "tarball") {
128    ### Download of latest revision.
129    if ($tarball =~ m:/([^/]+)/tarball$:) {
130      $downfile = $1 . "_latest.tar.gz";
131    }
132    else {
133      $downfile .= ".tar.gz";
134    }
135  }
136  print "Will download file $downfile from $downurl.\n";
137  system("wget -O $downfile $downurl") == 0 or die "wget failed: $?";
138  $tarball = $downfile;
139}
140
141die "Tarball $tarball not found.\n" if (! -r $tarball);
142if (! -d $workdir) {
143  mkdir $workdir or die "Failed to create work directory $workdir: $!";
144}
145copy($tarball, $workdir);
146my $startdir = getcwd();
147chdir $workdir;
148my $tarballfile = basename($tarball);
149system "tar -xf $tarballfile";
150print "Copy language files:";
151foreach my $lpponame (split("\n", `find . -name "*.po"`)) {
152  if ($lpponame =~ /([a-zA-Z_@]+)\.po/) {
153    my $lang = $1;
154    my $poname = $1 . ".po";
155    print " $lang";
156    copy($lpponame, catfile($startdir, $podir, $poname));
157  }
158}
159print "\n";
160
161if ($rmworkdir) {
162  chdir $startdir;
163  system "rm -rf $workdir";
164}
Note: See TracBrowser for help on using the repository browser.