diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-13 21:11:21 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-13 21:11:21 +0000 |
commit | f7e630b95fdceef16f37eaeda74fe4d4b9ded8f7 (patch) | |
tree | f2ef6061874965c2642875fd10eefbfa7a33f84c /vest/dist-vest.pl | |
parent | c28b222df1af55f72f64f53f79e42e08ded32025 (diff) |
vest allow logfile in directory
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@243 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'vest/dist-vest.pl')
-rwxr-xr-x | vest/dist-vest.pl | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/vest/dist-vest.pl b/vest/dist-vest.pl index 32a8edbd..3f19d83a 100755 --- a/vest/dist-vest.pl +++ b/vest/dist-vest.pl @@ -1,6 +1,8 @@ #!/usr/bin/env perl use strict; +my @ORIG_ARGV=@ARGV; +use Cwd qw(getcwd); my $SCRIPT_DIR; BEGIN { use Cwd qw/ abs_path /; use File::Basename; $SCRIPT_DIR = dirname(abs_path($0)); push @INC, $SCRIPT_DIR; } use Getopt::Long; use IPC::Open2; @@ -146,20 +148,32 @@ my $newIniFile = "$dir/$decoderBase.ini"; my $inputFileName = "$dir/input"; my $user = $ENV{"USER"}; + # process ini file -e $iniFile || die "Error: could not open $iniFile for reading\n"; open(INI, $iniFile); +sub dirsize { + opendir ISEMPTY,$_[0]; + return scalar(readdir(ISEMPTY))-1; +} if ($dryrun){ write_config(*STDERR); exit 0; } else { - if (-e $dir){ + if (-e $dir && dirsize($dir)>1){ # allow preexisting logfile die "ERROR: working dir $dir already exists\n\n"; } else { - mkdir $dir; + -e $dir || mkdir $dir; mkdir "$dir/hgs"; mkdir "$dir/scripts"; + my $cmdfile="$dir/rerun-vest.sh"; + open CMD,'>',$cmdfile; + print CMD "cd ",&getcwd,"\n"; +# print CMD &escaped_cmdline,"\n"; #buggy - last arg is quoted. + print CMD &cmdline,"\n"; + close CMD; + chmod(0755,$cmdfile); unless (-e $initialWeights) { print STDERR "Please specify an initial weights file with --initial-weights\n"; print_help(); @@ -584,3 +598,33 @@ sub convert { } + +sub cmdline { + return join ' ',($0,@ORIG_ARGV); +} + +#buggy: last arg gets quoted sometimes? +my $is_shell_special=qr{[ \t\n\\><|&;"'`~*?{}$!()]}; +my $shell_escape_in_quote=qr{[\\"\$`!]}; + +sub escape_shell { + my ($arg)=@_; + return undef unless defined $arg; + if ($arg =~ /$is_shell_special/) { + $arg =~ s/($shell_escape_in_quote)/\\$1/g; + return "\"$arg\""; + } + return $arg; +} + +sub escaped_shell_args { + return map {local $_=$_;chomp;escape_shell($_)} @_; +} + +sub escaped_shell_args_str { + return join ' ',&escaped_shell_args(@_); +} + +sub escaped_cmdline { + return "$0 ".&escaped_shell_args_str(@ORIG_ARGV); +} |