2a2abf5bcf
IMPORTANT: You need to link libreoffice-icon-themes and libreoffice-l10n packages to this one. I have moved the corresponding spec files. As discussed with the autobuild team, it should make the life easier. I need to keep the version in sync and update the spec files at the same time. - updated to libreoffice-3.5.3.2 (3.5.3-rc2) OBS-URL: https://build.opensuse.org/request/show/116218 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/libreoffice?expand=0&rev=32
336 lines
10 KiB
Perl
336 lines
10 KiB
Perl
#!/usr/bin/perl -w
|
|
|
|
# This script changes the definite article of ProductName
|
|
|
|
use strict;
|
|
use File::Copy;
|
|
|
|
my $args = join ' ', @ARGV;
|
|
my $max_level = 2;
|
|
|
|
sub init_lang_data($$$$)
|
|
{
|
|
my ($pdata, $lang_code, $long_name, $level) = @_;
|
|
|
|
my $curLang;
|
|
my $upstreamLang;
|
|
# we support the syntax: package_lang_code[/lo_source_lang_code]
|
|
if ($lang_code =~ m/([\w\-]+)\/?([\w\-]+)?/) {
|
|
$curLang = "$1";
|
|
if (defined $2) {
|
|
$upstreamLang = "$2";
|
|
} else {
|
|
$upstreamLang = $curLang;
|
|
}
|
|
} else {
|
|
die "Syntax error: unknown format of the language code: $lang_code, line $.";
|
|
}
|
|
|
|
% {$pdata->{'lang'}{$curLang}} = ();
|
|
my $pld = \% {$pdata->{'lang'}{$curLang}};
|
|
|
|
$pld->{'long_name'} = $long_name;
|
|
$pld->{'level'} = $level;
|
|
$pld->{'locale'} = $upstreamLang;
|
|
$pld->{'locale'} =~ s/-/_/g;
|
|
$pld->{'package'} = ();
|
|
|
|
($level <= $max_level) || die "Error: Maximum allowed level is $max_level, line $.";
|
|
foreach my $l ($level .. $max_level) {
|
|
@ {$pdata->{'level_langs_list'}[$l]} = () unless (defined $pdata->{'level_langs_list'}[$l]);
|
|
push @ {$pdata->{'level_langs_list'}[$l]}, $upstreamLang;
|
|
$l++;
|
|
}
|
|
|
|
return $pld;
|
|
}
|
|
|
|
sub read_data($$)
|
|
{
|
|
my ($pdata, $data_file) = @_;
|
|
# pointer to locale data
|
|
my $pld = undef;
|
|
|
|
$pdata->{'max_group'} = 0;
|
|
$pdata->{'level_langs_list'} = ();
|
|
@ {$pdata->{'level_langs_list'}[$_]} = () foreach (0 .. $max_level);
|
|
|
|
open DATA , "< $data_file" or die "Can't open '$data_file'\n";
|
|
|
|
while( my $line = <DATA>){
|
|
chomp $line;
|
|
# ignore comments
|
|
$line =~ s/#.*$//;
|
|
if ($line =~ m/^\s*\%lang\s+([\w\-\/]+)\s+(\w+)\s+(\d+)\s*$/ ) {
|
|
# long name without without quotation marks, e.g. %lang de German 1
|
|
$pld = init_lang_data($pdata, "$1", "$2", "$3");
|
|
} elsif ( $line =~ m/^\s*\%lang\s+([\w\-\/]+)\s+\"([\w\s]+)\"\s+(\d+)\s*$/ ) {
|
|
# long name with with quotation marks, e.g. %lang br "Breton French" 2
|
|
$pld = init_lang_data($pdata, "$1", "$2", "$3");
|
|
} elsif ( $line =~ /^\s*\%poor-help\s*$/ ) {
|
|
$pld->{'poor-help'} = 1;
|
|
} elsif ( $line =~ /^\s*\%package\s+(.*)$/ ) {
|
|
push @ {$pld->{'package'}}, "$1";
|
|
} elsif ( $line =~ /^\s*$/ ) {
|
|
# ignore empty line
|
|
} else {
|
|
die "Synrax error in $data_file, line $.\n";
|
|
}
|
|
}
|
|
close(DATA);
|
|
}
|
|
|
|
|
|
##################################
|
|
# conditional lines
|
|
|
|
sub write_level_begin($$$)
|
|
{
|
|
my ($curLevel, $newLevel, $outp) = @_;
|
|
|
|
if ($curLevel != $newLevel) {
|
|
${$outp} .= "%endif\n" if ($curLevel > 0);
|
|
${$outp} .= "%if %test_build_langs >= $newLevel\n" if ($newLevel > 0);
|
|
${$outp} .= "\n" if ($curLevel > 0);
|
|
}
|
|
|
|
return $newLevel;
|
|
}
|
|
|
|
sub write_level_end($$)
|
|
{
|
|
my ($curLevel, $outp) = @_;
|
|
|
|
if ($curLevel > 0) {
|
|
${$outp} .= "%endif\n";
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
##############################
|
|
# simple sections
|
|
|
|
sub write_do_not_edit_section($)
|
|
{
|
|
my $out = "###################################################################\n" .
|
|
"## DO NOT EDIT THIS SPEC FILE\n" .
|
|
"## Generated by:\n" .
|
|
"## perl lo-l10n-gen-spec $args\n" .
|
|
"###################################################################";
|
|
return $out;
|
|
}
|
|
|
|
|
|
##############################
|
|
# all langs sections
|
|
|
|
sub write_metadata_section($$)
|
|
{
|
|
my ($pdata, $curLang) = @_;
|
|
my $pld = \% {$pdata->{'lang'}{$curLang}};
|
|
my $out = "";
|
|
|
|
$out .= "%package -n libreoffice-l10n-$curLang\n";
|
|
$out .= "Summary: $pld->{'long_name'} Localization Files for LibreOffice\n";
|
|
$out .= "Group: Productivity/Office/Suite\n";
|
|
$out .= "Provides: locale(libreoffice:$pld->{'locale'})\n";
|
|
$out .= "%if 0%{?suse_version} > 01120\n";
|
|
$out .= "Requires(post): coreutils\n";
|
|
$out .= "Requires(post): grep\n";
|
|
$out .= "Requires(post): libreoffice >= 3.5\n";
|
|
$out .= "Requires(postun): coreutils\n";
|
|
$out .= "Requires(postun): grep\n";
|
|
$out .= "Requires(postun): libreoffice >= 3.5\n";
|
|
$out .= "%endif\n";
|
|
$out .= "%if 0%{?suse_version} && 0%{?suse_version} <= 01120\n";
|
|
$out .= "PreReq: coreutils\n";
|
|
$out .= "PreReq: grep\n";
|
|
$out .= "PreReq: libreoffice >= 3.5\n";
|
|
$out .= "%endif\n";
|
|
$out .= "Requires: libreoffice = %{version}\n";
|
|
foreach my $line (@{$pld->{'package'}}) {
|
|
$out .= "$line\n";
|
|
}
|
|
$out .= "# compat stuff\n";
|
|
$out .= "Provides: OpenOffice_org-$curLang = %{version}\n";
|
|
$out .= "Obsoletes: OpenOffice_org-$curLang <= %{version}\n";
|
|
$out .= "Provides: OpenOffice_org-l10n-$curLang = %{version}\n";
|
|
$out .= "Obsoletes: OpenOffice_org-l10n-$curLang <= %{version}\n";
|
|
$out .= "Provides: OpenOffice_org-$curLang:%{_prefix}/ooo-2.0/program/resource/sw680$curLang.res\n";
|
|
|
|
$out .= "\n";
|
|
|
|
$out .= "%description -n libreoffice-l10n-$curLang\n";
|
|
$out .= "$pld->{'long_name'} localization files for LibreOffice.\n";
|
|
$out .= "\n";
|
|
|
|
return $out;
|
|
}
|
|
|
|
sub write_install_scripts_section($$)
|
|
{
|
|
my ($pdata, $curLang) = @_;
|
|
my $pld = \% {$pdata->{'lang'}{$curLang}};
|
|
my $out = "";
|
|
|
|
$out .= "# $curLang\n";
|
|
$out .= "%posttrans -n libreoffice-l10n-$curLang\n";
|
|
$out .= "%{_datadir}/%ooo_home/link-to-ooo-home %{_datadir}/%ooo_home/lang_$pld->{'locale'}_list.txt || true\n";
|
|
$out .= "\n";
|
|
$out .= "%preun -n libreoffice-l10n-$curLang\n";
|
|
$out .= "test \"\$1\" = \"0\" && cp %{_datadir}/%ooo_home/lang_$pld->{'locale'}_list.txt %{_datadir}/%ooo_home/lang_$pld->{'locale'}_list.txt.postun || true\n";
|
|
$out .= "\n";
|
|
$out .= "%postun -n libreoffice-l10n-$curLang\n";
|
|
$out .= "test \"\$1\" = \"0\" && %{_datadir}/%ooo_home/link-to-ooo-home --unlink %{_datadir}/%ooo_home/lang_$pld->{'locale'}_list.txt.postun || true\n";
|
|
$out .= "rm -f %{_datadir}/%ooo_home/lang_$pld->{'locale'}_list.txt.postun 2>/dev/null\n";
|
|
|
|
return $out;
|
|
}
|
|
|
|
sub write_files_section($$)
|
|
{
|
|
my ($pdata, $curLang) = @_;
|
|
my $pld = \% {$pdata->{'lang'}{$curLang}};
|
|
my $out = "";
|
|
|
|
return if ("$curLang" eq "en-US"); # we do not have the l10n-en-US package
|
|
|
|
$out .= "%files -f lang_$pld->{'locale'}_list.txt -n libreoffice-l10n-$curLang\n";
|
|
$out .= "%defattr(-,root,root)\n";
|
|
$out .= "\n";
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
########################################################
|
|
# universal writing functions
|
|
|
|
sub write_level_langs($$)
|
|
{
|
|
my ($pdata, $level) = @_;
|
|
|
|
my $out = "";
|
|
foreach my $curLang (sort keys %{$pdata->{'lang'}}) {
|
|
$out .= " $curLang" if ($level >= $pdata->{'lang'}{$curLang}{'level'});
|
|
}
|
|
$out =~ s/^ //;
|
|
$out =~ s/_/-/g;
|
|
|
|
return $out;
|
|
}
|
|
|
|
# the text is not repeated for each locale
|
|
sub write_simple_section($$)
|
|
{
|
|
my ($pdata, $write_section) = @_;
|
|
|
|
return & {$write_section} ($pdata);
|
|
}
|
|
|
|
# the text is repeated for each locale
|
|
# it is used on all distributions
|
|
sub write_locale_sections($$)
|
|
{
|
|
my ($pdata, $write_single_lang_section, $outp) = @_;
|
|
my $curLevel = 0;
|
|
my $out = "";
|
|
|
|
foreach my $curLang (sort keys %{$pdata->{'lang'}}) {
|
|
$curLevel = write_level_begin($curLevel, $pdata->{'lang'}{$curLang}{'level'}, \$out);
|
|
$out .= & {$write_single_lang_section} ($pdata, $curLang);
|
|
}
|
|
|
|
$curLevel = write_level_end($curLevel, \$out);
|
|
|
|
return $out;
|
|
}
|
|
|
|
########################################################
|
|
# main write function
|
|
|
|
sub write_spec($$)
|
|
{
|
|
my ($pdata, $spec_template) = @_;
|
|
|
|
my $do_not_edit = write_simple_section ($pdata, \&write_do_not_edit_section);
|
|
my $metadata = write_locale_sections ($pdata, \&write_metadata_section);
|
|
my $install_scripts = write_locale_sections ($pdata, \&write_install_scripts_section);
|
|
my $files = write_locale_sections ($pdata, \&write_files_section);
|
|
|
|
my $spec = $spec_template;
|
|
$spec =~ s/.in$//;
|
|
|
|
print "Generating $spec...\n";
|
|
|
|
open TEMPLATE , "< $spec_template" or die "Can't open '$spec_template'\n";
|
|
open SPEC , "> $spec" or die "Can't open '$spec for writing'\n";
|
|
|
|
while( my $line = <TEMPLATE>) {
|
|
foreach my $level (0..2) {
|
|
my $level_langs = write_level_langs($pdata, $level);
|
|
$line =~ s/\@OOO_LANGS_MIN_$level\@/$level_langs/;
|
|
}
|
|
$line =~ s/\@DO_NOT_EDIT_COMMENT\@/$do_not_edit/;
|
|
$line =~ s/\@METADATA\@/$metadata/;
|
|
$line =~ s/\@INSTALL_SCRIPTS\@/$install_scripts/;
|
|
$line =~ s/\@FILES\@/$files/;
|
|
|
|
print SPEC $line;
|
|
}
|
|
|
|
close(TEMPLATE);
|
|
close(SPEC);
|
|
}
|
|
|
|
sub usage()
|
|
{
|
|
print "This tool generates the l10n spec file\n\n" .
|
|
|
|
"Usage:\n".
|
|
"\tlo-l10n-gen-spec [--help] spec_template.in data_file\n\n";
|
|
}
|
|
|
|
# info about localizations
|
|
# it is a hash, keys introduce perl-like structure items:
|
|
# 'level_langs_list' ... array, index is the level number, value is an array of
|
|
# the localizations defined for the givel level
|
|
# 'lang' ...the key is the lang id, e.g. "en-US", the value is:
|
|
# a hash, keys introduce perl-like structure items:
|
|
# 'long_name' ... string, long name of the language, e.g. "American"
|
|
# 'level' ... integer, level in whih it should get build, e.g. '1'
|
|
# it is the level in the rpm spec to do a reduced build
|
|
# 'locale' ... string, it is the code used by the upstream sources;
|
|
# it is usually the lang id with undersore instead of dash,
|
|
# e.g. "en_US"; ot it might differ from the package lang code if
|
|
# upstream renamed it later, for example, "gu-IN" was renamed to
|
|
# "gu" in ooo320-m5
|
|
# 'package-l10n' ... array of strings that should be added to the %package section for
|
|
# the given language
|
|
my %data;
|
|
my $spec_template;
|
|
my $data_file;
|
|
|
|
for my $arg (@ARGV) {
|
|
if ($arg eq '--help' || $arg eq '-h') {
|
|
usage;
|
|
exit 0;
|
|
} else {
|
|
-f $arg || die "Error: The file does not exist: $arg\n";
|
|
if (! defined $spec_template) {
|
|
$spec_template = $arg;
|
|
} elsif (! defined $data_file) {
|
|
$data_file = $arg;
|
|
} else {
|
|
die "Error: Too many arguments!\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
die "Error: Spec file template is not defined, try --help" unless (defined $spec_template);
|
|
die "Error: Data file is not defined, try --help" unless (defined $data_file);
|
|
|
|
read_data(\%data, $data_file);
|
|
write_spec(\%data, $spec_template);
|