Skip to content

Commit

Permalink
Support Component file.
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Feb 27, 2012
1 parent 94a5202 commit 7cacda3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
88 changes: 67 additions & 21 deletions RecipeShell.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?php
App::uses('Shell', 'Console');

// recipe type
define('RECIPE_TYPE_PLUGIN', 'plugin');
define('RECIPE_TYPE_COMPONENT', 'component');

// recipe archive
define('RECIPE_ARCHIVE_TARBALL', 'tarball');
define('RECIPE_ARCHIVE_FILE', 'file');

class RecipeShell extends Shell {

public $tasks = array();
Expand All @@ -15,8 +23,6 @@ class RecipeShell extends Shell {
*/
public function startup(){
parent::startup();
define('RECIPE_TYPE_PLUGIN', 'plugin');
define('RECIPE_ARCHIVE_TARBALL', 'tarball');
}

/**
Expand Down Expand Up @@ -167,20 +173,14 @@ private function choice($key){
*
*/
private function install($key){
$url = $this->ingredients[$key]['url'];
$type = $this->ingredients[$key]['type'];
$archive = $this->ingredients[$key]['archive'];
$pluginName = $this->ingredients[$key]['pluginName'];

$pluginPath = APP . DS . 'Plugin' . DS;

switch ($archive) {
case RECIPE_ARCHIVE_TARBALL:
$filename = 'temp.tar.gz';
$tarballName = $this->ingredients[$key]['tarballName'];
$cmd = 'cd ' . $pluginPath . ';wget ' . $url . ' --no-check-certificate -O ' . $filename . ';tar zxvf ' . $filename . ';mv ' . $tarballName . ' ' . $pluginName . ';';
exec($cmd);
unlink($pluginPath . $filename);
$this->_tarball($key);
break;
case RECIPE_ARCHIVE_FILE:
$this->_file($key);
break;
default:
break;
Expand All @@ -189,19 +189,65 @@ private function install($key){
$this->_stop();
}

/**
* _tarball
*
*/
private function _tarball($key){
$name = $this->ingredients[$key]['name'];
$url = $this->ingredients[$key]['url'];
$type = $this->ingredients[$key]['type'];
$archive = $this->ingredients[$key]['archive'];
$pluginPath = APP . DS . 'Plugin' . DS;
$componentPath = APP . DS . 'Controller/Component' . DS;

switch($type) {
case RECIPE_TYPE_PLUGIN:
$fileName = 'temp.tar.gz';
$pluginName = $name;
$tarballName = $this->ingredients[$key]['tarballName'];
$cmd = 'cd ' . $pluginPath . ';wget ' . $url . ' --no-check-certificate -O ' . $fileName . ';tar zxvf ' . $fileName . ';mv ' . $tarballName . ' ' . $pluginName . ';';
exec($cmd);
unlink($pluginPath . $fileName);
break;
}
}

/**
* _file
*
*/
private function _file($key){
$name = $this->ingredients[$key]['name'];
$url = $this->ingredients[$key]['url'];
$type = $this->ingredients[$key]['type'];
$archive = $this->ingredients[$key]['archive'];
$pluginPath = APP . DS . 'Plugin' . DS;
$componentPath = APP . DS . 'Controller/Component' . DS;

switch($type) {
case RECIPE_TYPE_COMPONENT:
$filePath = $componentPath . $name. '.php';
$cmd = 'wget ' . $url . ' --no-check-certificate -O ' . $filePath;
exec($cmd);
unlink($fileName);
break;
}
}

public function getOptionParser() {
$name = $this->name;
$parser = new ConsoleOptionParser($name, false);
$parser->addOption('recipe', array(
'short' => 'r',
'help' => __d('cake_console', 'Set recipe file'),
'boolean' => true
));
'short' => 'r',
'help' => __d('cake_console', 'Set recipe file'),
'boolean' => true
));
$parser->addOption('ingredients', array(
'short' => 'i',
'help' => __d('cake_console', 'Set ingredients file'),
'boolean' => true
));
'short' => 'i',
'help' => __d('cake_console', 'Set ingredients file'),
'boolean' => true
));
return $parser;
}

Expand All @@ -213,4 +259,4 @@ public function getOptionParser() {
public function help() {

}
}
}
7 changes: 7 additions & 0 deletions ingredients.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,11 @@
'archive' => RECIPE_ARCHIVE_TARBALL,
'tarballName' => 'hiromi2424-Collectionable-*',
),
'transition' => array('name' => 'TransitionComponent',
'description' => 'Transition Component',
'author' => 'hiromi2424',
'type' => RECIPE_TYPE_COMPONENT,
'url' => 'https://raw.github.com/hiromi2424/TransitionComponent/cake2/controllers/components/transition.php',
'archive' => RECIPE_ARCHIVE_FILE,
),
);

0 comments on commit 7cacda3

Please sign in to comment.