Changes on console feedback colors. Example of User Tasks.

This commit is contained in:
Andrs Montaez
2011-11-23 09:38:52 -02:00
parent d6166a674d
commit e5f0fe9cfa
13 changed files with 174 additions and 93 deletions
+4 -4
View File
@@ -4,10 +4,10 @@ class Mage_Task_BuiltIn_Deployment_Rsync
{
public function getName()
{
return 'Rsync (built-in)';
return 'Rsync [built-in]';
}
public function run($config)
public function run()
{
$ignores = array(
'--exclude .git',
@@ -18,8 +18,8 @@ class Mage_Task_BuiltIn_Deployment_Rsync
$command = 'rsync -avz '
. implode(' ', $ignores) .' '
. $config['deploy']['deploy-from'] . ' '
. $config['deploy']['user'] . '@' . $config['deploy']['host'] . ':' . $config['deploy']['deploy-to'];
. $this->_config['deploy']['deploy-from'] . ' '
. $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $this->_config['deploy']['deploy-to'];
$result = $this->_runLocalCommand($command);
+18 -3
View File
@@ -2,14 +2,29 @@
class Mage_Task_BuiltIn_Scm_Update
extends Mage_Task_TaskAbstract
{
private $_name = 'SCM Update [built-in]';
public function getName()
{
return 'SCM Update (built-in)';
return $this->_name;
}
public function run($config)
public function init()
{
switch ($config['scm']['type']) {
switch ($this->_config['scm']['type']) {
case 'git':
$this->_name = 'SCM Update (GIT) [built-in]';
break;
case 'svn':
$this->_name = 'SCM Update (Subversion) [built-in]';
break;
}
}
public function run()
{
switch ($this->_config['scm']['type']) {
case 'git':
$command = 'git pull';
break;
+15 -9
View File
@@ -7,30 +7,36 @@ class Mage_Task_Deploy
{
$this->_config = $config;
foreach ($config->getHosts() as $host)
{
foreach ($config->getHosts() as $host) {
$taskConfig = $config->getConfig($host);
$tasks = 0;
$completedTasks = 0;
Mage_Console::output(PHP_TAB . 'Deploying to ' . $host . PHP_EOL);
Mage_Console::output('Deploying to <dark_gray>' . $host . '</dark_gray>');
foreach ($config->getTasks() as $taskName) {
$tasks++;
$task = Mage_Task_Factory::get($taskName);
$task = Mage_Task_Factory::get($taskName, $taskConfig);
$task->init();
Mage_Console::output(PHP_TAB . PHP_TAB . 'Running ' . $task->getName() . ' ... ');
$result = $task->run($taskConfig);
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
$result = $task->run();
if ($result == true) {
Mage_Console::output(PHP_TAB . 'OK' . PHP_EOL);
Mage_Console::output('<green>OK</green>');
$completedTasks++;
} else {
Mage_Console::output(PHP_TAB . 'FAIL' . PHP_EOL);
Mage_Console::output('<red>FAIL</red>');
}
}
if ($completedTasks == $tasks) {
$tasksColor = 'green';
} else {
$tasksColor = 'red';
}
Mage_Console::output(PHP_TAB . 'Deployment to ' . $host . ' compted: ' . $completedTasks . '/' . $tasks . ' tasks done.' . PHP_EOL . PHP_EOL);
Mage_Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.' . PHP_EOL . PHP_EOL);
}
}
+16 -4
View File
@@ -7,10 +7,22 @@ class Mage_Task_Factory
* @param string $taskName
* @return Mage_Task_TaskAbstract
*/
public static function get($taskName)
public static function get($taskName, $taskConfig)
{
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
$className = 'Mage_Task_BuiltIn_' . $taskName;
return new $className;
$instance = null;
if (strpos($taskName, '/') === false) {
Mage_Autoload::loadUserTask($taskName);
$className = 'Task_' . ucfirst($taskName);
$instance = new $className($taskConfig);
} else {
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
$className = 'Mage_Task_BuiltIn_' . $taskName;
$instance = new $className($taskConfig);
}
assert($instance instanceOf Mage_Task_TaskAbstract);
return $instance;
}
}
+20 -4
View File
@@ -1,17 +1,33 @@
<?php
abstract class Mage_Task_TaskAbstract
{
protected $_config = null;
public abstract function getName();
public abstract function run($config);
public abstract function run();
protected function _runLocalCommand($command)
public final function __construct($config)
{
$this->_config = $config;
}
public function init()
{
}
protected final function _runLocalCommand($command)
{
return Mage_Console::executeCommand($command);
}
protected function _runRemoteCommand($command)
protected final function _runRemoteCommand($command)
{
$localCommand = 'ssh '
. $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ' '
. '"cd ' . $this->_config['deploy']['deploy-to'] . ' && '
. $command . '"';
return $this->_runLocalCommand($localCommand);
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
class Mage_Task_Update
{
private $_config = null;
public function run(Mage_Config $config)
{
$this->_config = $config;
$taskConfig = $config->getConfig();
$task = Mage_Task_Factory::get('scm/update', $taskConfig);
$task->init();
Mage_Console::output( PHP_TAB . 'Updating application via ' . $task->getName() . ' ... ');
$result = $task->run();
if ($result == true) {
Mage_Console::output(PHP_TAB . 'OK' . PHP_EOL);
} else {
Mage_Console::output(PHP_TAB . 'FAIL' . PHP_EOL);
}
}
}