OSDN Git Service

admin: (JM-tl-modify.pl) Get name and email from environments.
authorAkihiro MOTOKI <amotoki@gmail.com>
Wed, 30 May 2012 20:21:35 +0000 (05:21 +0900)
committerAkihiro MOTOKI <amotoki@gmail.com>
Wed, 30 May 2012 20:21:35 +0000 (05:21 +0900)
admin/JM-tl-modify.pl

index a80403b..e79c1db 100755 (executable)
@@ -11,9 +11,9 @@ use Getopt::Std;
 my $DEBUG = 1;
 my %status;
 my $tlist_body = "";
-my $update_timestamp = 0;
-my $update_name = "";
-my $update_email = "";
+my $update_timestamp = 1;
+my $update_translator = 1;
+my $clear_entry = 0;
 my %opts;
 
 BEGIN{
@@ -25,7 +25,21 @@ BEGIN{
 use strict 'vars';
 use JMtl ('line2hash', 'hash2line');
 
-getopts("tn:e:c", \%opts);
+getopts("tTuUn:e:c", \%opts);
+$update_timestamp = 1 if $opts{"t"};
+$update_timestamp = 0 if $opts{"T"};
+$update_translator = 1 if $opts{"u"};
+$update_translator = 0 if $opts{"U"};
+
+my $user_name  = $opts{"n"} || $ENV{'JM_USER_NAME'};
+my $user_mail = $opts{"e"} || $ENV{'JM_USER_MAIL'};
+if ($update_translator && ($user_name eq "" || $user_mail eq "")) {
+    print STDERR "Translator name or mail not specified.\n";
+    exit 0;
+}
+
+$clear_entry = 1 if $opts{"c"};
+$ARGV[2] = "_DUMMY_" if $clear_entry;
 
 if ($#ARGV < 2) {
     print STDERR "Usage: JM-tl-modify.pl [OPTIONS] translation_list pagename new_status\n";
@@ -33,10 +47,14 @@ if ($#ARGV < 2) {
     print STDERR "    new_status = TR DO DP PR RO RR\n";
     print STDERR "\n";
     print STDERR "OPTIONS:\n";
-    print STDERR "    -t : Update timestamp\n";
-    print STDERR "    -n NAME : Update name field\n";
-    print STDERR "    -e MAIL : Update mail field\n";
+    print STDERR "    -t : Update timestamp (default)\n";
+    print STDERR "    -T : DO NOT update timestamp\n";
+    print STDERR "    -u : Update Translator info (default)\n";
+    print STDERR "    -U : DO NOT update Translator info\n";
+    print STDERR "    -n NAME : Update name field [JM_USER_NAME]\n";
+    print STDERR "    -e MAIL : Update mail field [JM_USER_MAIL]\n";
     print STDERR "    -c : Clear entry of specified pagename\n";
+    print STDERR "         (new_status is not required when -c is specified.)\n";
     exit 0;
 }
 
@@ -63,7 +81,7 @@ while (<TLO>) {
     if ($ti{'kind'} eq 'link' &&
        "$ti{'lname'}.$ti{'lsec'}" eq $status{'page'})
     {
-       if ($opts{"c"}) {
+       if ($clear_entry) {
            $ti{'stat'} = '1st_non';
            my $tll = hash2line(%ti);
            if ($DEBUG eq "yes") {print "$ismatch MATCH: $tll\n"};
@@ -98,7 +116,9 @@ while (<TLO>) {
       if ($status{'stat'} =~ /^PR/){$ti{'stat'} .= 'prf'; last SW1;}
       if ($status{'stat'} =~ /^RO/){$ti{'stat'} = 'up2date'; last SW1;}
       if ($status{'stat'} =~ /^RR/){$ti{'stat'} = 'up2datR'; last SW1;}
-      die "error in STAT description\n" if not $opts{"c"};
+      if (not $clear_entry) {
+         die "Invalid new status. Valid status is one of TR DO DP PR RO RR.\n";
+      }
   }
 
     if ($status{'stat'} =~ /^R/){
@@ -111,15 +131,16 @@ while (<TLO>) {
 #    $ti{'tmail'} = $status{'mail'};
 #    $ti{'tname'} = $status{'name'};
 
-    if ($opts{"t"}) {
+    if ($update_timestamp) {
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
        $year += 1900; $mon += 1;
        $ti{'tdat'} = sprintf("%04d/%02d/%02d", $year, $mon, $mday);
     }
-    $ti{'tname'} = $opts{"n"} if $opts{"n"};
-    $ti{'tmail'} = $opts{"e"} if $opts{"e"};
-
-    if ($opts{"c"}) {
+    if ($update_translator) {
+       $ti{'tname'} = $user_name;
+       $ti{'tmail'} = $user_mail;
+    }
+    if ($clear_entry) {
        $ti{'stat'} = '1st_non';
        $ti{'tdat'} = '';
        $ti{'tname'} = '';