Moving taskman shell related stuff here

This commit is contained in:
Pavel Shevaev 2022-06-06 18:36:42 +03:00
parent ac6b8d710d
commit 44d935a1bf
1 changed files with 44 additions and 2 deletions

View File

@ -373,6 +373,48 @@ function recurse_copy($src, $dst, $dir_perms = 0777, $copy_mode = COPY_MODE_BUIL
closedir($dir); closedir($dir);
} }
function shell($cmd, &$out=null)
{
shell_try($cmd, $ret, $out);
if($ret != 0)
throw new TaskmanException("Shell execution error(exit code $ret)");
}
function shell_try($cmd, &$ret=null, &$out=null)
{
msg(" shell: $cmd\n");
msg(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
if(func_num_args() < 3)
system($cmd, $ret);
else
_execute_proc_cmd($cmd, $ret, $out);
}
function _execute_proc_cmd($cmd, &$ret, &$out)
{
//TODO: do we really need to redirect error stream?
$proc = popen("$cmd 2>&1", 'r');
$log = '';
//TODO: how can this be?
if(is_string($proc))
{
$log = $proc;
_log($log, 1);
}
else
{
while($logline = fgets($proc))
{
$log .= $logline;
_log($logline, 1);
}
}
$out = explode("\n", $log);
$ret = pclose($proc);
}
function _ensure_copy_file($src, $dst, $copy_mode = COPY_MODE_BUILTIN, $mtime_check = false) function _ensure_copy_file($src, $dst, $copy_mode = COPY_MODE_BUILTIN, $mtime_check = false)
{ {
if($mtime_check && file_exists($dst) && filemtime($src) <= filemtime($dst)) if($mtime_check && file_exists($dst) && filemtime($src) <= filemtime($dst))
@ -856,9 +898,9 @@ function replace_text_in_file($search_pattern, $replace_pattern, $from_file, $to
function gamectl_get_props_as_php_code() function gamectl_get_props_as_php_code()
{ {
$props = props(); $props = props();
$props_str = "<?php\n"; $props_str = "<?php\nnamespace taskman;\n";
foreach($props as $k => $v) foreach($props as $k => $v)
$props_str .= "taskman_propset('$k', " . var_export($v, true). ");\n"; $props_str .= "set('$k', " . var_export($v, true). ");\n";
return $props_str; return $props_str;
} }