Skip to content
Snippets Groups Projects
Commit db68fe2d authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #605 from greezybacon/feature/deploy-dry-run


Add a dry-run feature to unpack and deploy

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents db48ecf3 4e915ffe
No related branches found
No related tags found
No related merge requests found
......@@ -162,7 +162,7 @@ class Module {
$this->parseOptions();
if (isset($this->_options[$name]))
return $this->_options[$name];
elseif ($this->options[$name]->default)
elseif (isset($this->options[$name]) && $this->options[$name]->default)
return $this->options[$name]->default;
else
return $default;
......
......@@ -11,6 +11,15 @@ class Deployment extends Unpacker {
script to deploy changes made by you or upstream development to your
installation target";
function __construct() {
$this->options['dry-run'] = array('-t','--dry-run',
'action'=>'store_true',
'help'=>'Don\'t actually deploy new code. Just show the files
that would be copied');
# super(*args);
call_user_func_array(array('parent', '__construct'), func_get_args());
}
function find_root_folder() {
# Hop up to the root folder of this repo
$start = dirname(__file__);
......@@ -50,7 +59,8 @@ class Deployment extends Unpacker {
# Unpack the include folder
$this->unpackage("$root/include/{,.}*", $include, -1,
array("*/include/ost-config.php"));
if (!$upgrade && $include != "{$this->destination}/include")
if (!$options['dry-run'] && !$upgrade
&& $include != "{$this->destination}/include")
$this->change_include_dir($include);
}
}
......
......@@ -97,21 +97,23 @@ class Unpacker extends Module {
* to disable exclusions
*/
function unpackage($folder, $destination, $recurse=0, $exclude=false) {
$verbose = $this->getOption('verbose');
$dryrun = $this->getOption('dry-run', false);
$verbose = $this->getOption('verbose') || $dryrun;
if (substr($destination, -1) !== '/')
$destination .= '/';
foreach (glob($folder, GLOB_BRACE|GLOB_NOSORT) as $file) {
if ($this->exclude($exclude, $file))
continue;
if (is_file($file)) {
if (!is_dir($destination))
if (!is_dir($destination) && !$dryrun)
mkdir($destination, 0751, true);
$target = $destination . basename($file);
if (is_file($target) && md5_file($target) == md5_file($file))
if (is_file($target) && (md5_file($target) == md5_file($file)))
continue;
if ($verbose)
$this->stdout->write($target."\n");
copy($file, $target);
if (!$dryrun)
copy($file, $target);
}
}
if ($recurse) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment