voxforge.org
VoxForge Dev

Changeset 2633

Show
Ignore:
Timestamp:
07/29/08 17:25:12 (4 months ago)
Author:
kmaclean
Message:

draft ManualWebForum? update script - takes a user submission, and submits it to a WebGUI forum.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/Scripts/Mirroring_scripts/ManualWebGUIForum.pm

    r2631 r2633  
    11#!/usr/bin/perl -w 
    2 $VERSION = 0.1.1
     2$VERSION = 0.2
    33 
    44=head1 NAME 
     
    1616use File::Basename; 
    1717use VoxForge_config; 
    18 my $parms = VoxForge_config->new(); 
    1918use WebGUIForum;  
    20  
    2119use lib '../Audio_scripts'; 
    2220use UserSubmission::README(); 
     
    2422=head1 SYNOPSIS 
    2523 
    26     $./manual_WebGUIForum -h                                            display help 
     24    $./manual_WebGUIForum -h                                                                                                                                    display help 
     25    $./ManualWebGUIForum.pm -d /path/to/tarfile -t EN-filename-[12341234].zip                                   upload single tar file 
     26    $./ManualWebGUIForum.pm -d /path/to/tarfile -g                                                                                              upload group of tar files contained in directory (-d) 
    2727 
    2828=head1 DESCRIPTION 
     
    3030=cut 
    3131 
    32 #################################################################### 
    33 ### Class Variables 
    34 #################################################################### 
    35 our ($opt_h, $opt_t, $opt_d,$opt_d); 
     32=head2 Class Variables  
     33 
     34=cut 
     35 
     36our ($opt_h,$opt_g, $opt_t, $opt_d); 
     37my @suffixlist = ("tgz", "tar.gz", "zip"); 
     38my $command; 
     39 
     40=head2 Main  
     41 
     42=cut 
     43 
    3644my $self = {}; 
    3745$self->{'debug'} = 0; 
     46$self->{'parms'} = VoxForge_config->new(); 
     47# yes = language supported in SVN, only put link to audio in VoxForge repository (no tar file upload) 
     48#       only use if SpeechSubmission script fails 
     49# no = language not supported in SVN, upload gzipped tar file to WebGUI forum 
    3850$self->{'languages'} = { 
    39         'EN' => ['English',1], # 1 = language supported in SVN, only put link to audio in VoxForge repository 
    40         'NL' => ['Netherlands',1], 
    41         'DE' => ['Germany',1], 
    42         'RU' => ['Russian',1], 
    43         'HE' => ['Hebrew',0], # 0 = language not supported in SVN, upload tar file to WebGUI 
    44         'IT' => ['Italian',0], 
    45         'SP' => ['Spanish',0], 
    46         'PT-BR' => ['BrazillianPortuguese',0] 
     51        'EN' => ['English','yes'], 
     52        'NL' => ['Netherlands','yes'], 
     53        'DE' => ['Germany','yes'], 
     54        'RU' => ['Russian','yes'], 
     55        'HE' => ['Hebrew','no'],  
     56        'IT' => ['Italian','no'], 
     57        'SP' => ['Spanish','no'], 
     58        'PT-BR' => ['Brazillian-Portuguese','no'], 
    4759}; 
     60$self->{"processedUserSubmissions"} = {}; 
    4861bless($self,"ManualWebGUIForum"); 
    4962 
    50 my $command; 
    51 #my ($promptspath, $readmepath, $licensepath); 
    52 #my ($path_original,$AudioDirName,$tarfile,$pathtoTarfile); 
    53  
    54 #################################################################### 
    55 ### Main 
    56 #################################################################### 
    57 $self->getOptions(); 
    58 $self->main(); 
    59 print "completed\n";     
    60  
    61 #################################################################### 
    62 ### Main 
    63 #################################################################### 
    64  
    65 sub Main { 
    66         my ($self)= @_;  
     63$self->Process(); 
     64print "completed\n"; 
     65         
     66=head2 Process  
     67 
     68=cut 
     69 
     70sub Process { 
     71        my ($self)= @_; 
     72        getopts('t:d:hg');    #  sets $opt_* as a side effect. 
     73        if ($opt_h) { 
     74                print "\nVoxForge Manual WebGUIForum Update\n";  
     75                print   "=============================================\n";       
     76                print "-d\t directory containing tar file or \n"; 
     77                print "\t set of tar files to be uploaded to WebGUI Forum\n"; 
     78                print "-g\t group of tar files contained in directory (-d)\n"; 
     79                print "-h\t help\n";     
     80                print "-t\t tar file name (use \"-d\" to set path)\n"; 
     81                print "--\n";                    
     82                print "Free Speech... Recognition\n"; 
     83                print "http://www.voxforge.org\n\n"; 
     84                exit; 
     85        } elsif ($opt_t and $opt_d) { 
     86                $self->{"tarFile"} = $opt_t; 
     87                $self->{"tarFilePath"} = $opt_d; 
     88                $self->processSingleTar(); 
     89        } elsif ($opt_g and $opt_d) { 
     90                $self->{"tarFile"} = undef; 
     91                $self->{"tarFilePath"} = $opt_d; 
     92                $self->processDirOfTars(); 
     93        } else { 
     94                print "\nVoxForge Manual WebGUIForum Update\n";  
     95                print   "==================================\n";  
     96                print "Use -h parameter for more information\n\n"; 
     97                print "--\n";                    
     98                print "Free Speech... Recognition\n"; 
     99                print "http://www.voxforge.org\n\n"; 
     100                exit; 
     101        }        
     102
     103 
     104=head2 processSingleTar  
     105 
     106=cut 
     107 
     108sub processSingleTar { 
     109        my ($self)= @_; 
    67110        my $tarFilePath = $self->{"tarFilePath"}; 
    68111        my $tarFile = $self->{"tarFile"}; 
    69         my $languages = $self->{"languages"}; 
    70         my %ProcessedUserSubmissions;    
     112        my $parms = $self->{'parms'};    
     113        my $ProcessedUserSubmissions = $self->{"processedUserSubmissions"}; 
     114         
     115        my ($filename,$path,$suffix) = fileparse($tarFile,@suffixlist);  
     116        if (grep /$suffix/, @suffixlist) { 
     117                my $newTarfileName = $self->renameTarfile($tarFilePath,$tarFile); 
     118                my $tarfileDirName = $self->extractTarFile($tarFilePath,$newTarfileName); 
     119                my $readme = $self->getReadmeWithPath($tarFilePath,$tarfileDirName);             
     120                $ProcessedUserSubmissions->{$tarfileDirName}= { 
     121                        "path_original" => "$tarFilePath", 
     122                        "readme" => $readme, 
     123                        "tarfile" => $newTarfileName, 
     124                } 
     125        } 
     126        $self->Update('speechsubmission', 'n@wp@$$') || confess "error: $?";     
     127        return 1;        
     128
     129 
     130=head2 processDirOfTars  
     131 
     132=cut 
     133 
     134sub processDirOfTars { 
     135        my ($self)= @_; 
     136        my $tarFilePath = $self->{"tarFilePath"}; 
     137        my $tarFile = $self->{"tarFile"}; 
     138        my $parms = $self->{'parms'};    
     139        my $ProcessedUserSubmissions = $self->{"processedUserSubmissions"}; 
     140 
     141        opendir(DIR, $tarFilePath) || confess ("Unable to open file: $tarFilePath"); 
     142        while (my $line = readdir(DIR)) { 
     143                chomp ($line); 
     144                if ($line ne "." and $line ne ".." ) { 
     145                        my ($filename,$path,$suffix) = fileparse($line,@suffixlist); 
     146                        if (grep /$suffix/, @suffixlist) { 
     147                                my $newTarfileName = $self->renameTarfile($tarFilePath,$line); 
     148                                my $tarfileDirName = $self->extractTarFile($tarFilePath,$newTarfileName); 
     149                                my $readme = $self->getReadmeWithPath($tarFilePath,$tarfileDirName); 
     150                                $ProcessedUserSubmissions->{$tarfileDirName}= { 
     151                                        "path_original" => "$tarFilePath", 
     152                                        "readme" => $readme, 
     153                                        "tarfile" => $newTarfileName, 
     154                                } 
     155                        } 
     156                } 
     157        } 
     158        $self->Update('speechsubmission', 'n@wp@$$') || confess "error: $?";     
     159        return 1; 
     160
     161 
     162=head2 getReadmeWithPath 
     163 
     164=cut 
     165 
     166sub getReadmeWithPath { 
     167        my ($self,$tarFilePath,$tarfileDirName)= @_; 
     168        my $parms = $self->{'parms'}; 
     169        my $readmeWithPath = UserSubmission::README->getFileWithPath($parms,"$tarFilePath/$tarfileDirName"); 
     170        $command = ("dos2unix -c Mac $readmeWithPath"); print "$command\n"; system($command) == 0 or confess "getReadmeWithPath $command failed: $?";  
     171        $command = ("dos2unix $readmeWithPath"); print "$command\n"; system($command) == 0 or confess "getReadmeWithPath $command failed: $?";  
     172        return UserSubmission::README->new($parms,$readmeWithPath,$tarfileDirName); 
     173
     174 
     175=head2 renameTarfile  
     176 
     177=cut 
     178 
     179sub renameTarfile { 
     180        my ($self,$tarFilePath,$tarFile)= @_; 
     181        my $languages = $self->{"languages"};    
    71182         
    72183        print "tarfile1:$tarFilePath/$tarFile\n"; 
    73184        my $newTarFileName = $tarFile; 
    74185        foreach my $key (keys %$languages) { 
    75                 $newTarFileName =~ s/^$key-//; 
     186                $newTarFileName =~ s/^$key-//; # remove leading language identifier 
    76187        } 
    77         $newTarFileName =~ s/\[.*\]//; 
     188        $newTarFileName =~ s/\[.*\]//; # remove random number contained in brackets 
    78189        rename("$tarFilePath/$tarFile", "$tarFilePath/$newTarFileName")  || confess "error:tar file not found, cannot rename: $?";       
    79190        print "tarfile2:$tarFilePath/$newTarFileName\n"; 
    80  
     191        return $newTarFileName; 
     192
     193 
     194=head2 extractTarFile  
     195 
     196=cut 
     197 
     198sub extractTarFile { 
     199        my ($self,$tarFilePath,$newTarFileName)= @_; 
    81200        my @suffixlist = ("tgz", "tar\.gz", "zip"); 
    82201        my ($AudioDirName,$path,$suffix) = fileparse($newTarFileName,@suffixlist); 
     
    85204        my $ae = Archive::Extract->new( archive => "$tarFilePath/$newTarFileName" ); 
    86205        $ae->extract( to => "$tarFilePath/$AudioDirName") or die $ae->error; 
    87                                  
    88         my $readmeWithPath = UserSubmission::README->getFileWithPath($parms,"$tarFilePath/$AudioDirName"); 
    89         print "!!!!!!readmeWithPath:$readmeWithPath\n"; 
    90         my $readme = UserSubmission::README->new($parms, "$readmeWithPath"); 
    91          
    92         $ProcessedUserSubmissions{$AudioDirName}= { 
    93                 "path_original" => $tarFilePath, 
    94                 "readme" => $readme 
    95         }; 
    96          
    97         if ($languages->{$readme->getLanguage()}[1]) { 
    98                 if ((-e "$tarFilePath/$newTarFileName") and (-e "$tarFilePath/$AudioDirName")) { 
    99                         print "Main: path to tar file: $tarFilePath/$newTarFileName\n"; 
    100                         print "Main: path to Audio Directory: $tarFilePath/$AudioDirName\n"; 
    101                         Update($parms, \%ProcessedUserSubmissions, 'speechsubmission', 'password') || confess "error: $?"; 
    102                 } else { 
    103                         confess "Zip/Tar file: $tarFilePath/$newTarFileName does not exist\n"; 
    104                 } 
    105         } else { 
    106                 Update($parms, \%ProcessedUserSubmissions, 'speechsubmission', 'password') || confess "error: $?"; 
    107         } 
    108 
    109  
    110 #################################################################### 
    111 ### Overrides 
    112 #################################################################### 
     206        return $AudioDirName; 
     207
     208 
     209=head2 Update  
     210 
     211Overrides UserSubmission method 
     212 
     213=cut 
     214 
    113215sub Update { 
    114         my ($parms,$ProcessedUserSubmissions, $username, $identifier) = @_; 
    115                 my $debug = $$parms{"debug"}; 
     216        my ($self, $username, $identifier) = @_; 
     217        my $debug = $self->{'debug'}; 
     218        my $ProcessedUserSubmissions = $self->{"processedUserSubmissions"}; 
     219        my $languages = $self->{"languages"}; 
     220        my $parms = $self->{'parms'}; 
     221 
    116222        print "\nWebGUIForumUpdate.pm starting****************************************************\n\n"; 
    117223        my $counter; 
    118  
    119224        my $browser = LWP::UserAgent->new(keep_alive => 1 ); 
    120225        $browser->cookie_jar( {} ); 
     
    123228                $counter++; 
    124229                print  "=== $counter. $AudioDirName ==============================================\n"; 
    125                 my $path_original = $$ProcessedUserSubmissions{$AudioDirName}{"path_original"}; 
    126                 my $readme = $$ProcessedUserSubmissions{$AudioDirName}{"readme"}; 
    127                         print STDERR "Update Forum with AudioDirName:$path_original/$AudioDirName\n" if $debug; 
    128                         #my ($content,$title)= WebGUIForum::getSubmissionContents($parms,$readmepath,$promptspath,$licensepath,$AudioDirName, $readme,$tarfile); 
    129                         my ($content,$title)= WebGUIForum::getSubmissionContents($parms,$path_original,$AudioDirName,$readme,$tarfile); 
    130                         WebGUIForum::Upload($parms,$browser,$content,$title,$readme,$pathtoTarfile); 
    131         } 
    132         print "\nWebGUIForumUpdate.pm completed!\n****************************************************\n\n"; 
    133 
    134  
    135 =head2 getOptions  
    136  
    137 Get the user submitted options ('a:b:d:hil:m:p:r:s:t:u:x:q:vwST') 
    138  
    139 =cut 
    140  
    141 sub getOptions { 
    142         my ($self)= @_; 
    143         my $debug = $self->{'debug'};    
    144         getopts('t:d:hg');    #  sets $opt_* as a side effect. 
    145         if ($opt_h) { 
    146                 print "\nVoxForge Manual WebGUIForum Update Parameters\n";       
    147                 print   "=============================================\n";       
    148                 print "-d\t directory containing tar file or set of tar files to be uploaded to WebGUI\n"; 
    149                 print "-g\t group of tar files contained in directory (-d)\n"; 
    150                 print "-h\t help\n";     
    151                 print "-t\t tar file name (no path; use \"-d\")\n"; 
    152                 print "--\n";                    
    153                 print "Free Speech... Recognition\n"; 
    154                 print "http://www.voxforge.org\n\n"; 
    155                 exit; 
    156         } elsif ($opt_t) { 
    157                  
    158                  
    159         } else { 
    160                 print "\nVoxForge Manual WebGUIForum Update Parameters\n";       
    161                 print   "==================================\n";  
    162                 print "Use -h parameter for more information\n\n"; 
    163                 print "--\n";                    
    164                 print "Free Speech... Recognition\n"; 
    165                 print "http://www.voxforge.org\n\n"; 
    166                 exit; 
    167         } 
    168 
    169          
    170          
     230                my $path_original = $ProcessedUserSubmissions->{$AudioDirName}{"path_original"}; 
     231                my $readme = $ProcessedUserSubmissions->{$AudioDirName}{"readme"}; 
     232                #print "!!!!!!!readme$readme\n"; 
     233                my $tarfile = $ProcessedUserSubmissions->{$AudioDirName}{"tarfile"}; 
     234                #my $readmeLanguage = $readme->getLanguage(); 
     235                #print "!!!!!!!readmeLanguage:$readmeLanguage:\n"; 
     236                #print "!!!!!!!languagesSupportedInSVN:" . $languages->{$readmeLanguage}[0] . $languages->{$readmeLanguage}[1] . "\n";   
     237                #print "!!!!!!!languagesSupportedInSVN:" . $languages->{'EN'}[0] . $languages->{'EN'}[1] . "\n";                                 
     238                print STDERR "Update Forum with AudioDirName:$path_original/$AudioDirName\n" if $debug; 
     239                if ($languages->{$readme->getLanguage()}[1] eq 'yes') { # check for switch telling you that language is supported in svn (then only need to link to audio tar file on voxforge repository) 
     240                        my $tarFileWithPath = undef; # if this is undef, then WebGUIForum script will add link to VoxForge repository in body of post to forum 
     241                        my ($content,$title)= WebGUIForum::getSubmissionContents($parms,$path_original,$AudioDirName,$readme,$tarFileWithPath); 
     242                        WebGUIForum::Upload($parms,$browser,$content,$title,$readme,$tarFileWithPath); 
     243                } elsif ($languages->{$readme->getLanguage()}[1] eq 'no') { 
     244                        my $tarFileWithPath = "$path_original/$tarfile"; # if this points to a tar file, then WebGUIForum script will upload tar file as part of the post to forum 
     245                        my ($content,$title)= WebGUIForum::getSubmissionContents($parms,$path_original,$AudioDirName,$readme,$tarFileWithPath); 
     246                        WebGUIForum::Upload($parms,$browser,$content,$title,$readme,$tarFileWithPath); 
     247                } else { 
     248                        confess "Error: language:" . $readme->getLanguage() .": not defined\n"; 
     249                } 
     250        }                
     251        return 1;        
     252
     253 
    171254=head1 Change Log     
    172255 
    1732562008.2.02 - 0.1 - created 
    174 2008/07/28 - 0.1.1 add perldoc and Getopt; process submissions contained in a directory 
     2572008/07/28 - 0.1.1 add perldoc and Getopt; process submissions contained in a directory; refactor 
    175258         
    176259=head1 AUTHOR 
  • Trunk/Scripts/Mirroring_scripts/VoxForge_config.pm

    r2577 r2633  
    145145sub setWebguiForumLanguage { 
    146146        my ($parms, $language ) = @_; 
    147         $$parms{"webguiLoginURL"} ='http://www.voxforge.org'; 
     147        $parms->{"webguiLoginURL"} ='http://www.voxforge.org'; 
    148148        if ($language =~ /EN/) { 
    149                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/english';  
    150                 #$$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr'; # for testing 
    151                 $$parms{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/SpeechCorpus/Trunk/Audio/Original';    
     149                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/english';  
     150                #$parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr'; # for testing 
     151                $parms->{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/SpeechCorpus/Trunk/Audio/Original';   
    152152        } elsif ($language =~ /DE/) { 
    153                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/german-speech-files'; 
     153                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/german-speech-files'; 
    154154                #$$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr';  # for testing 
    155                 $$parms{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/de/Trunk/Audio/Original';      
     155                $parms->{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/de/Trunk/Audio/Original';     
    156156        } elsif ($language =~ /HB/) { 
    157                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/hebrew'; 
    158                 $$parms{"webguiRepositoryURL"} = 'Error: repository not set up yet'; 
     157                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/hebrew'; 
     158                $parms->{"webguiRepositoryURL"} = 'Error: repository not set up yet'; 
    159159        } elsif ($language =~ /IT/) { 
    160                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/italian-speech-files'; 
    161                 $$parms{"webguiRepositoryURL"} = 'Error: repository not set up yet';           
     160                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/italian-speech-files'; 
     161                $parms->{"webguiRepositoryURL"} = 'Error: repository not set up yet';          
    162162        } elsif ($language =~ /NL/) { 
    163                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/dutch'; 
     163                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/dutch'; 
    164164                #$$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr';  # for testing 
    165                 $$parms{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/Dutch/Trunk/Audio/Original'; 
     165                $parms->{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/Dutch/Trunk/Audio/Original'; 
    166166        } elsif ($language =~ /RU/) { 
    167                 $$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/russian'; 
     167                $parms->{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/russian'; 
    168168                #$$parms{"webguiUploadURL"} = 'http://www.voxforge.org/home/downloads/speech/voxforgeivr';  # for testing                
    169                 $$parms{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/Russian/Trunk/Audio/Original';                 
     169                $parms->{"webguiRepositoryURL"} = 'http://www.repository.voxforge1.org/downloads/Russian/Trunk/Audio/Original';                
    170170                 
    171171        } else {