Browse Source

Added the Install feature.

1.0
Andrs Montaez 13 years ago
parent
commit
1349f296c0
  1. 20
      Mage/Console.php
  2. 50
      Mage/Task/Install.php
  3. 4
      bin/mage.php

20
Mage/Console.php

@ -6,6 +6,7 @@ class Mage_Console
private $_actionOptions = null;
private $_environment = null;
private static $_log = null;
private static $_logEnabled = true;
public function setArgs($args)
{
@ -24,6 +25,9 @@ class Mage_Console
} else if ($this->_args[0] == 'add') {
$this->_action = 'add';
} else if ($this->_args[0] == 'install') {
$this->_action = 'install';
} else if ($this->_args[0] == 'init') {
$this->_action = 'init';
}
@ -73,6 +77,13 @@ class Mage_Console
public function run()
{
// Disable Loging
if ($this->getAction() == 'install') {
self::$_logEnabled = false;
}
Mage_Console::output('Starting <blue>Magallanes</blue>', 0, 2);
$config = new Mage_Config;
$config->loadEnvironment($this->getEnvironment());
$config->loadSCM();
@ -88,6 +99,11 @@ class Mage_Console
$task->run($config);
break;
case 'install';
$task = new Mage_Task_Install;
$task->run();
break;
case 'init';
$task = new Mage_Task_Init;
$task->run();
@ -102,10 +118,13 @@ class Mage_Console
}
break;
}
Mage_Console::output('Finished <blue>Magallanes</blue>', 0, 2);
}
public static function log($message, $continuation = false)
{
if (self::$_logEnabled) {
if (self::$_log == null) {
self::$_log = fopen('.mage/logs/log-' . date('Ymd-His') . '.log', 'w');
}
@ -113,4 +132,5 @@ class Mage_Console
$message = date('Y-m-d H:i:s -- ') . $message;
fwrite(self::$_log, $message . PHP_EOL);
}
}
}

50
Mage/Task/Install.php

@ -0,0 +1,50 @@
<?php
class Mage_Task_Install
{
public function run ()
{
Mage_Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
$this->_recursiveCopy('./', '/opt/magallanes');
chmod('/opt/magallanes/bin/mage', 0755);
if (!file_exists('/usr/bin/mage')) {
symlink('/opt/magallanes/bin/mage', '/usr/bin/mage');
}
Mage_Console::output('<light_green>Success!</light_green>', 0, 2);
}
private function _recursiveCopy ($from, $to)
{
if (is_dir($from)) {
mkdir($to);
$files = scandir($from);
if (count($files) > 0) {
foreach ($files as $file) {
if (strpos($file, '.') === 0) {
continue;
}
if (is_dir($from . DIRECTORY_SEPARATOR . $file)) {
$this->_recursiveCopy(
$from . DIRECTORY_SEPARATOR . $file,
$to . DIRECTORY_SEPARATOR . $file
);
} else {
copy(
$from . DIRECTORY_SEPARATOR . $file,
$to . DIRECTORY_SEPARATOR . $file
);
}
}
}
return true;
} elseif (is_file($from)) {
return copy($from, $to);
} else {
return false;
}
}
}

4
bin/mage.php

@ -24,12 +24,8 @@ $baseDir = dirname(dirname(__FILE__));
require_once $baseDir . '/Mage/Autoload.php';
spl_autoload_register(array('Mage_Autoload', 'autoload'));
Mage_Console::output('Starting <blue>Magallanes</blue>', 0, 2);
$console = new Mage_Console;
$console->setArgs($argv);
$console->parse();
$console->run();
Mage_Console::output('Finished <blue>Magallanes</blue>', 0, 2);

Loading…
Cancel
Save