- Timestamp:
- 07/03/09 12:02:57 (1 year ago)
- Files:
-
- trunk/external-tools/mvc_installer/bin/midgard2-install (modified) (2 diffs)
- trunk/external-tools/mvc_installer/lib/config.php (modified) (1 diff)
- trunk/external-tools/mvc_installer/lib/errors.php (modified) (5 diffs)
- trunk/external-tools/mvc_installer/lib/exporter/git.php (modified) (1 diff)
- trunk/external-tools/mvc_installer/lib/helpers.php (modified) (1 diff)
- trunk/external-tools/mvc_installer/lib/installer.php (modified) (1 diff)
- trunk/external-tools/mvc_installer/lib/installer/mvc.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/external-tools/mvc_installer/bin/midgard2-install
r22771 r22776 20 20 function midgard2_installer_cli_exception_handler($e) 21 21 { 22 fwrite(STDERR, "\n{$e}\n\n"); 22 fwrite(STDERR, "\n{$e}\n"); 23 // Output debug data if set 24 if (isset($e->debug_data)) 25 { 26 ob_start(); 27 var_dump($e->debug_data); 28 $debug_r = ob_get_contents(); 29 ob_end_clean(); 30 fwrite(STDERR, "\nDEBUG DATA:\n{$debug_r}"); 31 } 32 fwrite(STDERR, "\n"); 23 33 $code = $e->getCode(); 24 34 // Final sanity-check for the exit code, make *sure* we do not exit with status 0 for exceptions … … 67 77 /* 68 78 $exporter = midgard2_installer_exporter::get('git'); 69 $exporter->create_temp_dir(); 70 //echo '$exporter->get_path()=' . $exporter->get_path() . "\n"; 79 echo $exporter->export('file:///home/rambo/svn/midcom/midcom_core/') . "\n"; 71 80 $exporter->error_cleanup(); 72 81 */ 73 82 83 $installer = midgard2_installer_installer::get('mvc'); 84 $installer->install('file:///home/rambo/svn/midcom/midcom_core/'); 85 $installer->error_cleanup(); 86 87 88 74 89 ?> trunk/external-tools/mvc_installer/lib/config.php
r22770 r22776 21 21 'git_executable' => 'git', 22 22 'mgdschema_dir' => '/usr/share/midgard/schema', 23 'static_dir' => '/usr/share/php/midcom/static', 23 'static_dir' => '/usr/share/php/midgardmvc/static', 24 'mvc_components_dir' => '/usr/share/php/midgardmvc', 24 25 ); 25 26 } trunk/external-tools/mvc_installer/lib/errors.php
r22769 r22776 30 30 define('MGD2INST_ERROR_CONFIG_VALUE', 8); 31 31 /** 32 * External CLI tool exited with error 33 */ 34 define('MGD2INST_ERROR_CLI_EXIT', 9); 35 /** 32 36 * Unknown library level error, preferably make a more specific error code 33 37 * … … 41 45 class midgard2_installer_runtime_exception extends RuntimeException 42 46 { 47 var $debug_data = null; 48 43 49 /** 44 50 * Overload constructor to make both message and code mandatory … … 46 52 * Also according to MidCOM tradition, set code first. 47 53 */ 48 public function __construct($code, $message )54 public function __construct($code, $message, $debug_data = null) 49 55 { 56 $this->debug_data = $debug_data; 50 57 // Disallow code 0 51 58 if ($code === 0) … … 58 65 class midgard2_installer_logic_exception extends LogicException 59 66 { 67 var $debug_data = null; 68 60 69 /** 61 70 * Overload constructor to make both message and code mandatory … … 63 72 * Also according to MidCOM tradition, set code first. 64 73 */ 65 public function __construct($code, $message )74 public function __construct($code, $message, $debug_data = null) 66 75 { 76 $this->debug_data = $debug_data; 67 77 // Disallow code 0 68 78 if ($code === 0) trunk/external-tools/mvc_installer/lib/exporter/git.php
r22770 r22776 18 18 } 19 19 20 /** 21 * Exports given GIT URI to temp directory 22 * 23 * @param string $uri, URI to exporty 24 * @return string path to temp directory 25 */ 20 26 public function export($uri) 21 27 { 22 throw new midgard2_installer_logic_exception(MGD2INST_ERROR_UNKNOWN, __CLASS__ . '::' . __FUNCTION__ . '() not implemented'); 28 $this->create_temp_dir(); 29 try 30 { 31 $cmd = $this->config->get('git_executable') . ' clone ' . escapeshellarg($uri) . ' ' . escapeshellarg($this->temp_path); 32 // The git command will create this path (hopefully) 33 rmdir($this->temp_path); 34 midgard2_installer_helpers::exec($cmd); 35 } 36 catch (exception $e) 37 { 38 $this->error_cleanup(); 39 throw $e; 40 } 41 return $this->temp_path; 23 42 } 24 43 } trunk/external-tools/mvc_installer/lib/helpers.php
r22769 r22776 25 25 */ 26 26 $command = 'which ' . escapeshellarg($executable); 27 try 28 { 29 midgard2_installer_helpers::exec($command); 30 } 31 catch (midgard2_installer_runtime_exception $e) 32 { 33 unset($command); 34 if ($e->getCode !== MGD2INST_ERROR_CLI_EXIT) 35 { 36 throw $e; 37 } 38 unset($e); 39 return false; 40 } 41 unset($command); 42 return true; 43 } 44 45 /** 46 * Wrapper for exec, checks exit codes etc 47 * 48 * @param string $command to execute 49 * @param int $expect exit code to expect 50 * @return array output of the exec (NOTE: throws exception if the command fails) 51 */ 52 static function exec($command, $expect = 0) 53 { 54 // Redirect stderr if not already redirected 55 if (strpos($command, '2>') === false) 56 { 57 $command .= ' 2>&1'; 58 } 27 59 $code = 1; 28 60 $output = array(); 29 61 exec($command, $output, $code); 30 if ($code !== 0)62 if ($code !== $expect) 31 63 { 32 // TODO: Log error 33 unset($command, $output, $code); 34 return false; 64 throw new midgard2_installer_runtime_exception(MGD2INST_ERROR_CLI_EXIT, "Command '{$command}' exited with code {$code}", $output); 35 65 } 36 unset($command, $output, $code); 37 38 return true; 66 return $output; 39 67 } 40 68 trunk/external-tools/mvc_installer/lib/installer.php
r22771 r22776 25 25 26 26 /** 27 * Default constructor for now 28 */ 29 function __construct() {} 27 * Reference to config object 28 */ 29 protected $config = null; 30 31 /** 32 * Load config instance when constructig 33 */ 34 function __construct() 35 { 36 $this->config = midgard2_installer_config::get_instance(); 37 } 30 38 31 39 /** trunk/external-tools/mvc_installer/lib/installer/mvc.php
r22771 r22776 17 17 } 18 18 19 /** 20 * Installs given uri 21 * 22 * @param string $uri, URI to install 23 * 24 * Throws exceptions on failures 25 */ 19 26 public function install($uri) 20 27 { 21 throw new midgard2_installer_logic_exception(MGD2INST_ERROR_UNKNOWN, __CLASS__ . '::' . __FUNCTION__ . '() not implemented'); 28 try 29 { 30 $parsed = midgard2_installer_parser::parse($uri); 31 $exporter = midgard2_installer_exporter::get($parsed['exporter']); 32 $exported_path = $exporter->export($parsed['uri']); 33 34 } 35 catch (exception $e) 36 { 37 $this->error_cleanup(); 38 throw $e; 39 } 22 40 } 23 41 }
