Changeset 22776 for trunk

Show
Ignore:
Timestamp:
07/03/09 12:02:57 (9 months ago)
Author:
rambo
Message:

some export code, refs #1196

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/external-tools/mvc_installer/bin/midgard2-install

    r22771 r22776  
    2020function midgard2_installer_cli_exception_handler($e) 
    2121{ 
    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"); 
    2333    $code = $e->getCode(); 
    2434    // Final sanity-check for the exit code, make *sure* we do not exit with status 0 for exceptions 
     
    6777/* 
    6878$exporter = midgard2_installer_exporter::get('git'); 
    69 $exporter->create_temp_dir(); 
    70 //echo '$exporter->get_path()=' . $exporter->get_path() . "\n"; 
     79echo $exporter->export('file:///home/rambo/svn/midcom/midcom_core/') . "\n"; 
    7180$exporter->error_cleanup(); 
    7281*/ 
    7382 
     83$installer = midgard2_installer_installer::get('mvc'); 
     84$installer->install('file:///home/rambo/svn/midcom/midcom_core/'); 
     85$installer->error_cleanup(); 
     86 
     87 
     88 
    7489?> 
  • trunk/external-tools/mvc_installer/lib/config.php

    r22770 r22776  
    2121            'git_executable' => 'git', 
    2222            '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', 
    2425        ); 
    2526    } 
  • trunk/external-tools/mvc_installer/lib/errors.php

    r22769 r22776  
    3030define('MGD2INST_ERROR_CONFIG_VALUE', 8); 
    3131/** 
     32 * External CLI tool exited with error 
     33 */ 
     34define('MGD2INST_ERROR_CLI_EXIT', 9); 
     35/** 
    3236 * Unknown library level error, preferably make a more specific error code 
    3337 * 
     
    4145class midgard2_installer_runtime_exception extends RuntimeException 
    4246{ 
     47    var $debug_data = null; 
     48 
    4349    /** 
    4450     * Overload constructor to make both message and code mandatory 
     
    4652     * Also according to MidCOM tradition, set code first. 
    4753     */ 
    48     public function __construct($code, $message
     54    public function __construct($code, $message, $debug_data = null
    4955    { 
     56        $this->debug_data = $debug_data; 
    5057        // Disallow code 0 
    5158        if ($code === 0) 
     
    5865class midgard2_installer_logic_exception extends LogicException 
    5966{ 
     67    var $debug_data = null; 
     68 
    6069    /** 
    6170     * Overload constructor to make both message and code mandatory 
     
    6372     * Also according to MidCOM tradition, set code first. 
    6473     */ 
    65     public function __construct($code, $message
     74    public function __construct($code, $message, $debug_data = null
    6675    { 
     76        $this->debug_data = $debug_data; 
    6777        // Disallow code 0 
    6878        if ($code === 0) 
  • trunk/external-tools/mvc_installer/lib/exporter/git.php

    r22770 r22776  
    1818    } 
    1919 
     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     */ 
    2026    public function export($uri) 
    2127    { 
    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; 
    2342    } 
    2443} 
  • trunk/external-tools/mvc_installer/lib/helpers.php

    r22769 r22776  
    2525         */ 
    2626        $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        } 
    2759        $code = 1; 
    2860        $output = array(); 
    2961        exec($command, $output, $code); 
    30         if ($code !== 0
     62        if ($code !== $expect
    3163        { 
    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); 
    3565        } 
    36         unset($command, $output, $code); 
    37  
    38         return true; 
     66        return $output; 
    3967    } 
    4068 
  • trunk/external-tools/mvc_installer/lib/installer.php

    r22771 r22776  
    2525 
    2626    /** 
    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    } 
    3038 
    3139    /** 
  • trunk/external-tools/mvc_installer/lib/installer/mvc.php

    r22771 r22776  
    1717    } 
    1818 
     19    /** 
     20     * Installs given uri 
     21     * 
     22     * @param string $uri, URI to install 
     23     *  
     24     * Throws exceptions on failures 
     25     */ 
    1926    public function install($uri) 
    2027    { 
    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        } 
    2240    } 
    2341}