[MOBY-guts] biomoby commit
Martin Senger
senger at dev.open-bio.org
Sat Nov 11 23:04:34 UTC 2006
senger
Sat Nov 11 18:04:34 EST 2006
Update of /home/repository/moby/moby-live/Java/src/scripts
In directory dev.open-bio.org:/tmp/cvs-serv15098/src/scripts
Modified Files:
install.pl
Log Message:
removing java warnings + update of Perl-Moses
moby-live/Java/src/scripts install.pl,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/scripts/install.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/scripts/install.pl 2006/10/16 18:07:15 1.6
+++ /home/repository/moby/moby-live/Java/src/scripts/install.pl 2006/11/11 23:04:34 1.7
@@ -47,6 +47,8 @@
}
}
+ use constant MSWIN => $^O =~ /MSWin32|Windows_NT/i ? 1 : 0;
+
say 'Welcome, BioMobiers. Preparing stage for Perl MoSeS...';
say '------------------------------------------------------';
@@ -59,11 +61,20 @@
Template
Config::Simple
IO::Scalar
- IO::Prompt
Unicode::String
) ) {
check_module ($module);
}
+ if (MSWIN) {
+ check_module ('Term::ReadLine');
+ {
+ local $^W = 0;
+ $SimplePrompt::Terminal = Term::ReadLine->new ('Installation');
+ }
+ } else {
+ check_module ('IO::Prompt');
+ require IO::Prompt; import IO::Prompt;
+ }
if ($errors_found) {
say "\nSorry, some needed modules were not found.";
say "Please install them and run 'install.pl' again.";
@@ -76,26 +87,31 @@
use lib "$Bin/../Perl"; # assuming: Perl/MOSES/...
# scripts/install.pl
use File::Spec;
-use IO::Prompt;
use MOSES::MOBY::Base;
use MOSES::MOBY::Cache::Central;
use MOSES::MOBY::Cache::Registries;
use English qw( -no_match_vars ) ;
use strict;
+# different prompt modules used for different OSs
+# ('pprompt' as 'proxy_prompt')
+sub pprompt {
+ return prompt (@_) unless MSWIN;
+ return SimplePrompt::prompt (@_);
+}
# $prompt ... a prompt asking for a directory
# $prompted_dir ... suggested directory
sub prompt_for_directory {
my ($prompt, $prompted_dir) = @_;
while (1) {
- my $dir = prompt ("$prompt [$prompted_dir] ");
+ my $dir = pprompt ("$prompt [$prompted_dir] ");
$dir =~ s/^\s*//; $dir =~ s/\s*$//;
$dir = $prompted_dir unless $dir;
return $dir if -d $dir and -w $dir; # okay: writable directory
$prompted_dir = $dir;
next if -e $dir and say "'$dir' is not a writable directory. Try again please.";
- next unless prompt ("Directory '$dir' does not exists. Create? ", -yn);
+ next unless pprompt ("Directory '$dir' does not exists. Create? ", -yn);
# okay, we agreed to create it
mkdir $dir and return $dir;
@@ -107,7 +123,7 @@
sub prompt_for_registry {
my $cache = new MOSES::MOBY::Cache::Central;
my @regs = MOSES::MOBY::Cache::Registries->list;
- my $registry = prompt ("What registry to use? [default] ",
+ my $registry = pprompt ("What registry to use? [default] ",
-m => [@regs]);
$registry ||= 'default';
}
@@ -144,14 +160,13 @@
# --- main ---
no warnings 'once';
-my $pmoses_home = File::Spec->catfile ($Bin, '..', 'Perl');
-my $jmoby_home = File::Spec->catfile ($Bin, '..', '..');
+my $pmoses_home = "$Bin/../Perl";
+my $jmoby_home = "$Bin/../..";
say "Installing in $pmoses_home\n";
# log files (create, or just change their write permissions)
-my $log_file1 = $MOBYCFG::LOG_FILE ||
- File::Spec->catfile ($pmoses_home, 'services.log');
-my $log_file2 = File::Spec->catfile ($pmoses_home, 'parser.log');
+my $log_file1 = $MOBYCFG::LOG_FILE || "$pmoses_home/services.log";
+my $log_file2 = "$pmoses_home/parser.log";
foreach my $file ($log_file1, $log_file2) {
unless (-e $file) {
eval {
@@ -164,15 +179,14 @@
}
# log4perl property file (will be found and used, or created)
-my $log4perl_file = $MOBYCFG::LOG_CONFIG ||
- File::Spec->catfile ($pmoses_home, 'log4perl.properties');
+my $log4perl_file = $MOBYCFG::LOG_CONFIG || "$pmoses_home/log4perl.properties";
if (-e $log4perl_file and ! $opt_F) {
say "\nLogging property file '$log4perl_file' exists.";
say "It will not be overwritten unless you start 'install.pl -F'.\n";
} else {
file_from_template
($log4perl_file,
- File::Spec->catfile ($pmoses_home, 'log4perl.properties.template'),
+ "$pmoses_home/log4perl.properties.template",
'Log properties file',
{ '@LOGFILE@' => $log_file1,
'@LOGFILE2@' => $log_file2,
@@ -181,20 +195,20 @@
# MobyServer.cgi file
my $generated_dir = $MOBYCFG::GENERATORS_OUTDIR ||
- File::Spec->catfile ($pmoses_home, 'generated');
+ "$pmoses_home/generated";
my $services_dir = $MOBYCFG::GENERATORS_IMPL_OUTDIR ||
- File::Spec->catfile ($pmoses_home, 'services');
+ "$pmoses_home/services";
my $services_table = $MOBYCFG::GENERATORS_IMPL_SERVICES_TABLE ||
'SERVICES_TABLE';
-my $cgibin_file = File::Spec->catfile ($pmoses_home, 'MobyServer.cgi');
+my $cgibin_file = "$pmoses_home/MobyServer.cgi";
if (-e $cgibin_file and ! $opt_F) {
say "\nWeb Server file '$cgibin_file' exists.";
say "It will not be overwritten unless you start 'install.pl -F'.\n";
} else {
file_from_template
($cgibin_file,
- File::Spec->catfile ($pmoses_home, 'MobyServer.cgi.template'),
+ "$pmoses_home/MobyServer.cgi.template",
'Web Server file',
{ '@PMOSES_HOME@' => $pmoses_home,
'@GENERATED_DIR@' => $generated_dir,
@@ -207,12 +221,12 @@
# directory for local cache
my $cachedir = $MOBYCFG::CACHEDIR ||
prompt_for_directory ( 'Directory for local cache',
- File::Spec->catfile ($jmoby_home, 'myCache'));
+ "$jmoby_home/myCache");
say "Local cache in '$cachedir'.\n";
# filling/updating local cache
my $registry = 'default';
-if ('y' eq prompt ('Should I try to fill or update the local cache [y]? ', -ynd=>'y')) {
+if ('y' eq pprompt ('Should I try to fill or update the local cache [y]? ', -ynd=>'y')) {
$registry = prompt_for_registry;
my $details =
MOSES::MOBY::Cache::Registries->get ($registry);
@@ -221,11 +235,10 @@
my $uri = $details->{namespace};
say 'Using registry: ' . $registry;
say "(at $endpoint)\n";
-# my $os = ($OSNAME =~ /Win/i ? '.bat' : '');
my $run_script =
File::Spec->catfile ($jmoby_home, 'build', 'run', 'run-cache-client');
if (-e $run_script) {
- my $cmd = "$run_script -e $endpoint -uri $uri -cachedir $cachedir -update";
+ my $cmd = "\"$run_script\" -e $endpoint -uri $uri -cachedir $cachedir -update";
say "The following command will be executed to update the cache:\n\n$cmd\n";
say "Updating local cache (it may take several minutes)...\n";
print `$cmd`;
@@ -248,7 +261,7 @@
} else {
file_from_template
($config_file,
- File::Spec->catfile ($pmoses_home, 'moby-services.cfg.template'),
+ "$pmoses_home/moby-services.cfg.template",
'Configuration file',
{ '@CACHE_DIR@' => $cachedir,
'@REGISTRY@' => $registry,
@@ -258,11 +271,93 @@
'@LOG4PERL_FILE@' => $log4perl_file,
'@LOGFILE@' => $log_file1,
'@MABUHAY_RESOURCE@' =>
- File::Spec->catfile ($jmoby_home, 'src', 'samples-resources', 'mabuhay.file'),
+ "$jmoby_home/src/samples-resources/mabuhay.file",
} );
}
say 'Done.';
+package SimplePrompt;
+
+use vars qw/ $Terminal /;
+
+sub prompt {
+ my ($msg, $flags, $others) = @_;
+
+ # simple prompt
+ return get_input ($msg)
+ unless $flags;
+
+ $flags =~ s/^-//o; # ignore leading dash
+
+ # 'waiting for yes/no' prompt, possibly with a default value
+ if ($flags =~ /^yn(d)?/i) {
+ return yes_no ($msg, $others);
+ }
+
+ # prompt with a menu of possible answers
+ if ($flags =~ /^m/i) {
+ return menu ($msg, $others);
+ }
+
+ # default: again a simple prompt
+ return get_input ($msg);
+}
+
+sub yes_no {
+ my ($msg, $default_answer) = @_;
+ while (1) {
+ my $answer = get_input ($msg);
+ return $default_answer if $default_answer and $answer =~ /^\s*$/o;
+ return 'y' if $answer =~ /^(1|y|yes|ano)$/;
+ return 'n' if $answer =~ /^(0|n|no|ne)$/;
+ }
+}
+
+sub get_input {
+ my ($msg) = @_;
+ local $^W = 0;
+ my $line = $Terminal->readline ($msg);
+ chomp $line; # remove newline
+ $line =~ s/^\s*//; $line =~ s/\s*$//; # trim whitespaces
+ $Terminal->addhistory ($line) if $line;
+ return $line;
+}
+
+sub menu {
+ my ($msg, $ra_menu) = @_;
+ my @data = @$ra_menu;
+
+ my $count = @data;
+# die "Too many -menu items" if $count > 26;
+# die "Too few -menu items" if $count < 1;
+
+ my $max_char = chr(ord('a') + $count - 1);
+ my $menu = '';
+
+ my $next = 'a';
+ foreach my $item (@data) {
+ $menu .= ' ' . $next++ . '.' . $item . "\n";
+ }
+ while (1) {
+ print STDOUT $msg . "\n$menu";
+ my $answer = get_input (">");
+
+ # blank and escape answer accepted as undef
+ return undef if $answer =~ /^\s*$/o;
+ return undef
+ if length $answer == 1 && $answer eq "\e";
+
+ # invalid answer not accepted
+ if (length $answer > 1 || ($answer lt 'a' || $answer gt $max_char) ) {
+ print STDOUT "(Please enter a-$max_char)\n";
+ next;
+ }
+
+ # valid answer
+ return $data[ord($answer)-ord('a')];
+ }
+}
+
__END__
More information about the MOBY-guts
mailing list