Poprawiłem programik, generujący domyślną konfigurację dla użytkownika.

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@8 e293616e-ec6a-49c2-aa92-f4a8b91c5d16
This commit is contained in:
pawelk 2008-03-12 11:27:45 +00:00
parent eedf64882e
commit e1b08a23fa
2 changed files with 195 additions and 53 deletions

View File

@ -1,53 +1,141 @@
#!/usr/bin/perl #!c:\usr\perl\bin\perl.exe
use Cwd 'abs_path'; use Cwd 'abs_path';
use File::Basename; use File::Basename;
use POSIX; use File::HomeDir;
use File::Spec::Functions;
my $cur_dir = dirname(abs_path($0)); use POSIX;
open(FILE, ">$cur_dir/conf/utt.conf"); my $sys_home = catdir(dirname(abs_path($0)), "..");
my $usr_home = catdir(home(), '.utt');
# we put some description into utt.conf file
print FILE "# ************************************************************\n"; prepareUttUsrHome($usr_home);
print FILE "# * This file was created automatically during installation. *\n"; conf_cor(catfile($usr_home, 'cor.conf'), $sys_home);
print FILE "# * If you don't need do not change it. *\n"; conf_grp(catfile($usr_home, 'grp.conf'), $sys_home);
print FILE "# * *\n"; conf_gue(catfile($usr_home, 'gue.conf'), $sys_home);
print FILE "# * UAM Text Tools *\n"; conf_lem(catfile($usr_home, 'lem.conf'), $sys_home);
print FILE "# * Adam Mickiewicz University, Poland *\n"; conf_ser(catfile($usr_home, 'ser.conf'), $sys_home);
print FILE "# * http://utt.amu.edu.pl *\n"; conf_utt(catfile($usr_home, 'utt.conf'), $sys_home);
print FILE "# ************************************************************\n";
print FILE "\n\n"; print "UTT user configuration created in $usr_home\n";
# we need utt home directory
print FILE "# absolute path to utt directory\n";
print FILE "UTT_HOME=$cur_dir\n\n"; #Kasuje stare configi i tworzy katalog .utt
sub prepareUttUsrHome() {
my $dir = shift;
# we need user default locale
$best_locale = findLocale(); if(-d $dir) {
print FILE "# user locale\n"; print "Old configuration will be deleted!\n";
print FILE "UTT_LOCALE=$best_locale\n"; my $cnt = unlink <$dir/*>;
print FILE "\n"; print "$cnt files deleted.\n";
}
close FILE; else {
print "Creating directory $dir\n";
if(1 != mkdir $dir) {
die "Unable to create UTT user configuration!\n";
sub findLocale() { }
$cur_locale = setlocale(LC_CTYPE); }
}
# we replace Latinx to ISO-8859-x
$cur_locale =~ s/(.+?)Latin(.+?)/$1ISO\-8859\-$2/g; # Tworzy naglowek dla wszystkich plikow konfiguracyjnych
sub makeConfigHeader() {
if($cur_locale =~ /\w+_\w+\.\S+/) { return "# ************************************************************\n".
$best_locale = $cur_locale; "# * This file was created automatically during installation. *\n".
} "# * If you don't need do not change it. *\n".
elsif($cur_locale =~ /\w+_\w+/) { "# * *\n".
$best_locale = $cur_locale.".UTF-8"; "# * UAM Text Tools *\n".
} "# * Adam Mickiewicz University, Poland *\n".
else { "# * http://utt.amu.edu.pl *\n".
$best_locale = toupper($cur_locale).'_'.tolower($cur_locale).'.UTF-8'; "# ************************************************************\n".
} "#\n".
return $best_locale; "# All lines must looks like:\n".
} "# parameter_name [=] value\n".
"#\n\n";
}
sub conf_cor() {
my $cor_file = shift;
my $utthome = shift;
open(FILE, ">$cor_file");
print FILE makeConfigHeader();
print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n";
close FILE;
}
sub conf_grp() {
my $grp_file = shift;
my $utthome = shift;
open(FILE, ">$grp_file");
print FILE makeConfigHeader();
print FILE "macros=", abs_path("$utthome/lib/utt/terms.m4"), "\n";
close FILE;
}
sub conf_gue() {
my $gue_file = shift;
my $utthome = shift;
open(FILE, ">$gue_file");
print FILE makeConfigHeader();
close FILE;
}
sub conf_lem() {
my $lem_file = shift;
my $utthome = shift;
open(FILE, ">$lem_file");
print FILE makeConfigHeader();
print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n";
close FILE;
}
sub conf_ser() {
my $ser_file = shift;
my $utthome = shift;
open(FILE, ">$ser_file");
print FILE makeConfigHeader();
print FILE "macros=", abs_path("$utthome/lib/utt/terms.m4"), "\n";
print FILE "flex-template=", abs_path("$utthome/lib/utt/ser.l.template"), "\n";
close FILE;
}
sub conf_utt() {
my $utt_file = shift;
my $utthome = shift;
open(FILE, ">$utt_file");
print FILE makeConfigHeader();
print FILE "# user locale\n";
print FILE "language=", findLocale(), "\n";
close FILE;
}
# Szuka locali u uzytkownika
sub findLocale() {
$cur_locale = setlocale(LC_CTYPE);
# we replace Latinx to ISO-8859-x
$cur_locale =~ s/(.+?)Latin(.+?)/$1ISO\-8859\-$2/g;
if($cur_locale =~ /\w+_\w+\.\S+/) {
$best_locale = $cur_locale;
}
elsif($cur_locale =~ /\w+_\w+/) {
$best_locale = $cur_locale.".UTF-8";
}
else {
$best_locale = toupper($cur_locale).'_'.tolower($cur_locale).'.UTF-8';
}
return $best_locale;
}

54
app/dist/struktura.txt vendored Normal file
View File

@ -0,0 +1,54 @@
/usr/local/bin/aut2fsa
/usr/local/bin/compiledic
/usr/local/bin/con
/usr/local/bin/cor
/usr/local/bin/fla
/usr/local/bin/fsm2aut
/usr/local/bin/grp
/usr/local/bin/gue
/usr/local/bin/kot
/usr/local/bin/lem
/usr/local/bin/mar
/usr/local/bin/sen
/usr/local/bin/sen-nl
/usr/local/bin/ser
/usr/local/bin/tok
/usr/local/bin/unfla
/usr/local/bin/utt-make-config.pl
/usr/local/bin/ipi.tag2re
/usr/local/bin/uam.tag2re
/usr/local/etc/utt/con.conf
/usr/local/etc/utt/cor.conf
/usr/local/etc/utt/fla.conf
/usr/local/etc/utt/grp.conf
/usr/local/etc/utt/gue.conf
/usr/local/etc/utt/kot.conf
/usr/local/etc/utt/lem.conf
/usr/local/etc/utt/mar.conf
/usr/local/etc/utt/sen.conf
/usr/local/etc/utt/ser.conf
/usr/local/etc/utt/tok.conf
/usr/local/etc/utt/unfla.conf
/usr/local/etc/utt/utt.conf
/usr/local/share/utt/pl_PL.ISO-8859-2/pl_PL.ISO-8859-2.sym
/usr/local/share/utt/pl_PL.ISO-8859-2/cor.bin
/usr/local/share/utt/pl_PL.ISO-8859-2/gue.bin
/usr/local/share/utt/pl_PL.ISO-8859-2/lem.bin
/usr/local/share/utt/pl_PL.UTF-8/pl_PL.UTF-8.sym
/usr/local/share/utt/pl_PL.UTF-8/cor.bin
/usr/local/share/utt/pl_PL.UTF-8/gue.bin
/usr/local/share/utt/pl_PL.UTF-8/lem.bin
/usr/local/lib/utt/ser.l.template
/usr/local/lib/utt/terms.m4
/usr/local/share/doc/utt/FAQ
/usr/local/share/doc/utt/COPYRIGHT
/usr/local/share/doc/utt/NEWS
/usr/local/share/doc/utt/README
/usr/local/share/info/utt.info.gz
/usr/local/share/man/man3/utt.gz
~/.utt/*.conf (wszystko z /usr/local/etc/utt)