gwynne          Sun Oct 26 23:09:41 2008 UTC

  Modified files:              
    /SVNROOT    run-conversion.php 
  Log:
  Rewrote conversion script to use Console_CommandLine and verbosity levels.
  
http://cvs.php.net/viewvc.cgi/SVNROOT/run-conversion.php?r1=1.1&r2=1.2&diff_format=u
Index: SVNROOT/run-conversion.php
diff -u SVNROOT/run-conversion.php:1.1 SVNROOT/run-conversion.php:1.2
--- SVNROOT/run-conversion.php:1.1      Fri Oct 24 02:45:27 2008
+++ SVNROOT/run-conversion.php  Sun Oct 26 23:09:41 2008
@@ -1,46 +1,97 @@
 <?php
 
-$version = '$Rev$';
+$version = '$Revision: 1.2 $';
 
-print "PHP Group CVS->SVN respository conversion version {$version}.\n";
-print "Started at " . date(DATE_RFC2822) . "\n";
+require_once 'Console/CommandLine.php';
 
-$CVSROOT = "/home/repository";
-$SVNROOT = "/home/repository-svn";
-
-$do_cvs2svn = TRUE;
-$do_svnrm = TRUE;
-$do_reorg = TRUE;
+$cmdline_parser = new Console_CommandLine(array(
+    'description' => 'PHP Group CVS->SVN respository converter',
+    'version' => $version,
+));
+$cmdline_parser->addOption('verbose', array(
+    'short_name' => '-v',
+    'long_name' => '--verbose',
+    'default' => 1,
+    'description' => 'Verbosity of output. Specify multiple times to increase 
verbosity.',
+    'action' => 'Counter'));
+$cmdline_parser->addOption('cvsroot', array(
+    'short_name' => '-c',
+    'long_name' => '--cvsroot',
+    'default' => '/home/repository',
+    'description' => 'Specify the CVS repository to operate on.',
+    'action' => 'StoreString'));
+$cmdline_parser->addOption('svnroot', array(
+    'short_name' => '-s',
+    'long_name' => '--svnroot',
+    'default' => '/home/repository-svn',
+    'description' => 'Specify the SVN repository to create.',
+    'action' => 'StoreString'));
+$cmdline_parser->addOption('pass', array(
+    'short_name' => '-p',
+    'long_name' => '--pass',
+    'default' => NULL,
+    'description' => 'Which pass to run. One of: svncreate, cvs2svn, svnrm, 
reorg. If not specified, all passes will run.',
+    'action' => 'StoreString',
+    'choices' => array('svncreate', 'cvs2svn', 'svnrm', 'reorg')));
+
+try {
+    $result = $cmdline_parser->parse();
+    $options = $result->options;
+} catch (Exception $ex) {
+    $parser->displayError($ex->getMessage());
+    exit(1);
+}
 
-function is_option($optName, $arg, &$value)
+function v($level, $message)
 {
-    if (strncmp($arg, $optName, strlen($optName)) == 0) {
-        if (!is_null($value)) {
-            $value = substr($arg, strlen($optName) + 1);
-        }
-        return true;
+    if ($GLOBALS['options']['verbose'] >= $level) {
+        print $message;
     }
-    return false;
 }
 
-foreach ($argv as $i => $arg) {
-    if (is_option("--cvsroot", $arg, $value)) {
-        $CVSROOT = $value;
-    } else if (is_option("--svnroot", $arg, $value)) {
-        $SVNROOT = $value;
-    } else if (is_option("--cvs2svn", $arg, $value)) {
-        $do_cvs2svn = ($value == 'true');
-    } else if (is_option("--svnrm", $arg, $value)) {
-        $do_svnrm = ($value == 'true');
-    } else if (is_option("--reorg", $arg, $value)) {
-        $do_reorg = ($value == 'true');
+function error($message, $status = 1)
+{
+    print $message;
+    exit($status);
+}
+
+if (!is_dir($options['cvsroot']) || !is_readable($options['cvsroot']) || 
!is_executable($options['cvsroot'])) {
+    error("CVS root directory must exist, be a directory, and be readable and 
searchable.\n");
+}
+
+if (is_null($options['pass']) || $options['pass'] == 'svncreate') {
+    if (file_exists($options['svnroot'])) {
+        error("SVN root directory can not exist if running the svncreate 
pass.\n");
+    }
+    if (!is_dir(dirname($options['svnroot'])) || 
!is_writable(dirname($options['svnroot']))) {
+        error("SVN root directory parent must exist, be a directory, and be 
writable if running the svncreate pass.\n");
+    }
+} else if (!is_dir($options['svnroot']) || !is_writable($options['svnroot'])) {
+    error("SVN root directory must exist and be writeable if not running the 
svncreate pass.\n");
+}
+       
+v(1, "PHP Group CVS->SVN respository conversion.\n");
+v(1, "Started at " . date(DATE_RFC2822) . "\n");
+
+if (is_null($options['pass']) || $options['pass'] == 'svncreate') {
+    v(1, "Running svncreate pass...\n");
+    
+    $command = "exec svnadmin create {$options['svnroot']} 2>&1";
+    v(2, "Running: '{$command}'...");
+    exec($command, $output, $exitstatus);
+    if ($exitstatus != 0) {
+        error("\nAn error occurred. Exit status was {$exitstatus}. Output:\n" 
. implode("\n", $output) . "\n", $exitstatus);
     }
+    v(2, " done.\n");
+    v(3, "Output:\n" . implode("\n", $output) . "\n");
 }
 
-if ($do_cvs2svn) {
-    print "Running cvs2svn...\n";
+if (is_null($options['pass']) || $options['pass'] == 'cvs2svn') {
+    v(1, "Running cvs2svn pass...\n");
     
-    $cvs2svn_process = proc_open("cvs2svn --options=phpsvn.options", array(
+    $command = "exec cvs2svn --options=phpsvn.options";
+    v(2, "Running: '{$command} > ./phpsvn.conversion.out 2>&php'...");
+    $cvs2svn_process = proc_open($command, array(
             0 => array('pipe', 'r'),
             1 => array('file', './phpsvn.conversion.out', 'w'),
             2 => array('pipe', 'w'),
@@ -59,50 +110,53 @@
     proc_close($cvs2svn_process);
     
     if ($procinfo['exitcode'] != 0) {
-        print "Error executing cvs2svn. Error output is:\n{$errorText}\n";
-        exit($procinfo['exitcode']);
+        error("\nAn error occurred. Exit status was {$procinfo['exitcode']}. 
Output:\n{$errorText}\n", $procinfo['exitcode']);
     }
+    v(2, " done.\n");
+    v(3, "Output is in ./phpsvn.conversion.out.\n");
 }
 
-if ($do_svnrm) {
-    print "Running svn rm...\n";
+if (is_null($options['pass']) || $options['pass'] == 'svnrm') {
+    v(1, "Running svnrm pass...\n");
     
-    exec("svn rm -m \"[SVN CONVERSION] Removing .svn directories that break 
SVN checkout.\" " .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/tests/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/tests/events/.svn 
" .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/tests/html/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/docs/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/branches/shin/examples/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/tests/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/tests/events/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/tests/html/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/docs/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/examples/.svn " .
-            "file:///{$SVNROOT}/pear/Selenium/tags/start/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/tests/.svn 
" .
-            
"file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/tests/events/.svn " .
-            
"file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/tests/html/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/docs/.svn 
" .
-            
"file:///{$SVNROOT}/pear/Testing_Selenium/branches/shin/examples/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/tests/.svn " .
-            
"file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/tests/events/.svn " .
-            
"file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/tests/html/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/docs/.svn " .
-            "file:///{$SVNROOT}/pear/Testing_Selenium/tags/start/examples/.svn 
2>&1", $svnrm_output, $exitstatus);
+    $command = "exec svn rm -m \"[SVN CONVERSION] Removing .svn directories 
that break SVN checkout.\" " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/tests/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/tests/events/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/tests/html/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/docs/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/branches/shin/examples/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/tags/start/tests/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/tags/start/tests/events/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/tags/start/tests/html/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/tags/start/docs/.svn " .
+                
"file:///{$options['svnroot']}/pear/Selenium/tags/start/examples/.svn " .
+                "file:///{$options['svnroot']}/pear/Selenium/tags/start/.svn " 
.
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/.svn " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/tests/.svn " 
.
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/tests/events/.svn
 " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/tests/html/.svn
 " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/docs/.svn " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/branches/shin/examples/.svn
 " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/.svn " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/tests/.svn " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/tests/events/.svn
 " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/tests/html/.svn 
" .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/docs/.svn " .
+                
"file:///{$options['svnroot']}/pear/Testing_Selenium/tags/start/examples/.svn 
2>&1";
+    v(2, "Running: '{$command}'...");
+    exec($command, $output, $exitstatus);
     if ($exitstatus != 0) {
-        print "Error executing svn rm. Error output is:\n" . implode("\n", 
$svnrm_output) . "\n";
-        exit($exitstatus);
+        error("\nAn error occurred. Exit status was {$exitstatus}. Output:\n" 
. implode("\n", $output) . "\n", $exitstatus);
     }
+    v(2, " done.\n");
+    v(3, "Output:\n" . implode("\n", $output) . "\n");
 }
 
-if ($do_reorg) {
-    print "If this were implemented yet, a series of svn cp, svn rm, and svn 
mv commands would follow. It isn't, so they don't. Sorry.\n";
-    exit(1);
+if (is_null($options['pass']) || $options['pass'] == 'reorg') {
+    error("If this were implemented yet, a series of svn cp, svn rm, and svn 
mv commands would follow. It isn't, so they don't. Sorry.\n");
 }
 
-print "Finished at " . date(DATE_RFC2822) . "\n";
+v(1, "Finished at " . date(DATE_RFC2822) . "\n");
 
 ?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to