Compare commits
11 Commits
f744f3d924
...
d178d52aa6
Author | SHA1 | Date | |
---|---|---|---|
|
d178d52aa6 | ||
|
2f7c7b676c | ||
|
3ee13c2670 | ||
|
1a837f46dd | ||
|
6ee83b4b82 | ||
|
42bba9d1be | ||
|
8f803e6c06 | ||
|
fe2e8b11a3 | ||
|
8301ee83d3 | ||
|
b08e3df595 | ||
|
cb579dc369 |
546
cmpUtil.php
546
cmpUtil.php
@@ -8,6 +8,7 @@
|
|||||||
var $gitCommit = "";
|
var $gitCommit = "";
|
||||||
var $gitComment = "";
|
var $gitComment = "";
|
||||||
|
|
||||||
|
var $maxFileSize = 104856;
|
||||||
|
|
||||||
function toArray($obj) {
|
function toArray($obj) {
|
||||||
$re = array();
|
$re = array();
|
||||||
@@ -149,7 +150,7 @@
|
|||||||
false , // bool $use_include_path
|
false , // bool $use_include_path
|
||||||
null , // ?resource $context
|
null , // ?resource $context
|
||||||
0 , // int $offset
|
0 , // int $offset
|
||||||
$this->parm["maxFileSize"] , // ?int $length
|
$this->maxFileSize , // ?int $length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +164,12 @@
|
|||||||
|
|
||||||
$obj = $this->decodeJSON($raw, 1);
|
$obj = $this->decodeJSON($raw, 1);
|
||||||
|
|
||||||
|
if(is_array($obj)) {
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
if(!$obj) {
|
if(!$obj) {
|
||||||
$this->e("Invalid JSON '$file'");
|
$this->e("Invalid JSON file '$file'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,16 +198,28 @@
|
|||||||
|
|
||||||
$this->appendConf($obj);
|
$this->appendConf($obj);
|
||||||
|
|
||||||
if(@$this->parm["timezone"]) {
|
if(isset($this->parm["timezone"]) && $this->parm["timezone"]) {
|
||||||
$this->d("Set timezone '" . $this->parm["timezone"] . "'");
|
$this->d("Set timezone '" . $this->parm["timezone"] . "'");
|
||||||
date_default_timezone_set($this->parm["timezone"]);
|
date_default_timezone_set($this->parm["timezone"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!@$this->parm["maxFileSize"])
|
do {
|
||||||
$this->parm["maxFileSize"] = 1048576;
|
if(!isset($this->parm["maxFileSize"]))
|
||||||
$this->d("Set maxFileSize '" . $this->parm["maxFileSize"] . "'");
|
break;
|
||||||
|
|
||||||
if(is_array(@$this->parm["php_ini"])) {
|
if(!$this->parm["maxFileSize"])
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!is_numeric($this->parm["maxFileSize"])) {
|
||||||
|
$this->d("Not numeric maxFileSize");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maxFileSize = 1*$this->parm["maxFileSize"];
|
||||||
|
$this->d("Set maxFileSize '" . $this->maxFileSize . "'");
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
if(isset($this->parm["php_ini"]) && is_array($this->parm["php_ini"])) {
|
||||||
foreach($this->parm["php_ini"] as $k => $v) {
|
foreach($this->parm["php_ini"] as $k => $v) {
|
||||||
ini_set($k, $v);
|
ini_set($k, $v);
|
||||||
}
|
}
|
||||||
@@ -249,8 +266,7 @@
|
|||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cmpShellEscStr($str) {
|
||||||
function cmpShellEscArr($cmaRaw) {
|
|
||||||
$ttr = array(
|
$ttr = array(
|
||||||
"\t" => "\\\t", "\$" => "\\\$",
|
"\t" => "\\\t", "\$" => "\\\$",
|
||||||
"\\" => "\\\\", "\"" => "\\\"",
|
"\\" => "\\\\", "\"" => "\\\"",
|
||||||
@@ -265,30 +281,241 @@
|
|||||||
"?" => "\\?" , "!" => "\\!"
|
"?" => "\\?" , "!" => "\\!"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(!is_array($str))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!isset($str[0]))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if($str[0] != "asis") {
|
||||||
|
$this->d("Unknown modifier '".$str[0]."'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($str[1]) || !$str[1]) {
|
||||||
|
$this->d("Invalid string '".$str[1]."'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str[1];
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
return strtr($str, $ttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmpShellEscArr($cmaRaw) {
|
||||||
$cmaEsc = array();
|
$cmaEsc = array();
|
||||||
|
|
||||||
for($i = 0; $i < count($cmaRaw); $i++) {
|
for($i = 0; $i < count($cmaRaw); $i++) {
|
||||||
if(@$cmaRaw[$i][0] == "asis") {
|
$str = $this->cmpShellEscStr($cmaRaw[$i]);
|
||||||
$cmaEsc[] = $cmaRaw[$i][1];
|
|
||||||
continue;
|
if(!$str) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmaEsc[] = strtr($cmaRaw[$i], $ttr);
|
$cmaEsc[] = $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cmaEsc;
|
return $cmaEsc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmpShellEscStr($cmaRaw) {
|
function cmpShellEsc($cmaRaw) {
|
||||||
|
if(is_array($cmaRaw)) {
|
||||||
$cmaEsc = $this->cmpShellEscArr($cmaRaw);
|
$cmaEsc = $this->cmpShellEscArr($cmaRaw);
|
||||||
|
|
||||||
return join(" ", $cmaEsc);
|
return join(" ", $cmaEsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmpSysExec($cmaRaw, $opt = []) {
|
return $this->cmpShellEscStr($cmaRaw);
|
||||||
$cmdStr = $this->cmpShellEscStr($cmaRaw);
|
}
|
||||||
|
|
||||||
if(!@$opt["silent"]) {
|
function cmpSysExecEventString(&$prs, &$buf, &$opt) {
|
||||||
|
$fs = "/\n/";
|
||||||
|
|
||||||
|
if(isset($opt["eventStringDelimer"]) && $opt["eventStringDelimer"])
|
||||||
|
$fs = $opt["eventStringDelimer"];
|
||||||
|
|
||||||
|
$a = preg_split($fs, $buf);
|
||||||
|
|
||||||
|
if(!$a) {
|
||||||
|
$this->d("Can't split buffer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$c = count($a) - 1;
|
||||||
|
|
||||||
|
if($c < 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for($i = 0; $i < $c; $i++) {
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"])
|
||||||
|
$this->d($prs["streamCurrent"] . ": " . $a[$i]);
|
||||||
|
|
||||||
|
if($prs["streamCurrent"] == "stdout") {
|
||||||
|
if(isset($opt["eventStringStdOut"]) && $opt["eventStringStdOut"]) {
|
||||||
|
($opt["eventStringStdOut"]["call"])($a[$i], $prs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($prs["streamCurrent"] == "stderr") {
|
||||||
|
if(isset($opt["eventStringStdErr"]) && $opt["eventStringStdErr"]) {
|
||||||
|
($opt["eventStringStdErr"]["call"])($a[$i], $prs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->d("Stream tail: " . $a[$c]);
|
||||||
|
$buf = $a[$c];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmpSysExecEventListenner(&$ppsAll, &$opt) {
|
||||||
|
$prs = array();
|
||||||
|
|
||||||
|
while(!feof($ppsAll[1])) {
|
||||||
|
$read = [ $ppsAll[1], $ppsAll[2] ];
|
||||||
|
$write = null;
|
||||||
|
$except = null;
|
||||||
|
|
||||||
|
// $this->d("Add stream event listenner");
|
||||||
|
$cnt = stream_select(
|
||||||
|
$read,
|
||||||
|
$write,
|
||||||
|
$except,
|
||||||
|
1, // seconds
|
||||||
|
0 // microseconds
|
||||||
|
);
|
||||||
|
|
||||||
|
if(false === $cnt) {
|
||||||
|
$this->d("stream_select err");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->d("Streams event count : " . $sel);
|
||||||
|
|
||||||
|
if(!$cnt) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = stream_get_contents($ppsAll[1]);
|
||||||
|
if($out) {
|
||||||
|
$prs["streamCurrent"] = "stdout";
|
||||||
|
|
||||||
|
if(!$this->cmpSysExecEventString($prs, $out, $opt))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$err = stream_get_contents($ppsAll[2]);
|
||||||
|
if($err) {
|
||||||
|
$prs["streamCurrent"] = "stderr";
|
||||||
|
|
||||||
|
if(!$this->cmpSysExecEventString($prs, $err, $opt))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// while
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmpSysExecEventSwo(&$ppsAll, &$opt) {
|
||||||
|
do {
|
||||||
|
if(!isset($opt["stdInEventAdd"]) || !$opt["stdInEventAdd"])
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!isset($opt["stdInEventAdd"]["call"])) {
|
||||||
|
$this->d("Unset callable stdInEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_callable($opt["stdInEventAdd"]["call"])) {
|
||||||
|
$this->d("Invalid callable stdInEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"])
|
||||||
|
$this->d("Call stdInEventAdd");
|
||||||
|
|
||||||
|
($opt["stdInEventAdd"]["call"]) (
|
||||||
|
$ppsAll[0],
|
||||||
|
$opt["stdInEventAdd"]
|
||||||
|
);
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(!isset($opt["stdOutEventAdd"]) || !$opt["stdOutEventAdd"])
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!isset($opt["stdOutEventAdd"]["call"])) {
|
||||||
|
$this->d("Unset callable stdOutEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_callable($opt["stdOutEventAdd"]["call"])) {
|
||||||
|
$this->d("Invalid callable stdOutEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"])
|
||||||
|
$this->d("Call stdOutEventAdd");
|
||||||
|
|
||||||
|
($opt["stdOutEventAdd" ]["call"]) (
|
||||||
|
$ppsAll[1],
|
||||||
|
$opt["stdOutEventAdd"]
|
||||||
|
);
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(!isset($opt["stdErrEventAdd"]) || !$opt["stdErrEventAdd"])
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!isset($opt["stdErrEventAdd"]["call"])) {
|
||||||
|
$this->d("Unset callable stdErrEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_callable($opt["stdErrEventAdd"]["call"])) {
|
||||||
|
$this->d("Invalid callable stdErrEventAdd");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"])
|
||||||
|
$this->d("Call stdErrEventAdd");
|
||||||
|
|
||||||
|
($opt["stdErrEventAdd"]["call"]) (
|
||||||
|
$ppsAll[2],
|
||||||
|
$opt["stdErrEventAdd"]
|
||||||
|
);
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(!isset($opt["eventWait"]) || !$opt["eventWait"])
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(!isset($opt["eventWait"]["call"])) {
|
||||||
|
$this->d("Unset callable eventWait");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_callable($opt["eventWait"]["call"])) {
|
||||||
|
$this->d("Invalid callable eventWait");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"])
|
||||||
|
$this->d("Call eventWait");
|
||||||
|
|
||||||
|
($opt["eventWait"]["call"])();
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmpSysExec($cmaRaw, $opt = []) {
|
||||||
|
$cmdStr = $this->cmpShellEsc($cmaRaw);
|
||||||
|
|
||||||
|
if(!isset($opt["silent"]) || !$opt["silent"]) {
|
||||||
$this->d("cmpSysExec: " . $cmdStr);
|
$this->d("cmpSysExec: " . $cmdStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +527,7 @@
|
|||||||
|
|
||||||
$workDir = "/tmp";
|
$workDir = "/tmp";
|
||||||
|
|
||||||
if(@$opt["workDir"])
|
if(isset($opt["workDir"]) && $opt["workDir"])
|
||||||
$workDir = $opt["workDir"];
|
$workDir = $opt["workDir"];
|
||||||
|
|
||||||
$envAll = null;
|
$envAll = null;
|
||||||
@@ -320,103 +547,52 @@
|
|||||||
$blk = $opt["blocking"];
|
$blk = $opt["blocking"];
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_set_blocking($ppsAll[1], $blk);
|
|
||||||
stream_set_blocking($ppsAll[2], $blk);
|
|
||||||
|
|
||||||
$retVal = 255;
|
$retVal = 255;
|
||||||
$out = "";
|
$out = "";
|
||||||
$err = "";
|
$err = "";
|
||||||
|
|
||||||
if($blk) {
|
if(isset($opt["eventString"]) && $opt["eventString"]) {
|
||||||
if(@$opt["stdin"]) {
|
stream_set_blocking($ppsAll[1], 0);
|
||||||
|
stream_set_blocking($ppsAll[2], 0);
|
||||||
|
|
||||||
|
if(isset($opt["stdin"]) && $opt["stdin"]) {
|
||||||
|
fwrite($ppsAll[0], $opt["stdin"]);
|
||||||
|
fclose($ppsAll[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cmpSysExecEventListenner($ppsAll, $opt);
|
||||||
|
}
|
||||||
|
else if($blk) {
|
||||||
|
stream_set_blocking($ppsAll[1], $blk);
|
||||||
|
stream_set_blocking($ppsAll[2], $blk);
|
||||||
|
|
||||||
|
if(isset($opt["stdin"]) && $opt["stdin"]) {
|
||||||
fwrite($ppsAll[0], $opt["stdin"]);
|
fwrite($ppsAll[0], $opt["stdin"]);
|
||||||
fclose($ppsAll[0]);
|
fclose($ppsAll[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = stream_get_contents($ppsAll[1], 1048576);
|
$out = stream_get_contents($ppsAll[1], 1048576);
|
||||||
$err = stream_get_contents($ppsAll[2], 1048576);
|
$err = stream_get_contents($ppsAll[2], 1048576);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stream_set_blocking($ppsAll[1], $blk);
|
||||||
|
stream_set_blocking($ppsAll[2], $blk);
|
||||||
|
|
||||||
|
// $this->d("Nonblock");
|
||||||
|
|
||||||
|
$this->cmpSysExecEventSwo($ppsAll, $opt);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// $this->d("Close all pipe");
|
||||||
|
|
||||||
fclose($ppsAll[1]);
|
fclose($ppsAll[1]);
|
||||||
fclose($ppsAll[2]);
|
fclose($ppsAll[2]);
|
||||||
}
|
|
||||||
else {
|
|
||||||
// $this->d("Nonblock");
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(!@$opt["stdInEventAdd"])
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(!is_callable(@$opt["stdInEventAdd"]["call"])) {
|
|
||||||
$this->d("Invalid callable stdInEventAdd");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!@$opt["silent"])
|
|
||||||
$this->d("Call stdInEventAdd");
|
|
||||||
|
|
||||||
($opt["stdInEventAdd"]["call"]) (
|
|
||||||
$ppsAll[0],
|
|
||||||
$opt["stdInEventAdd"]
|
|
||||||
);
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(!@$opt["stdOutEventAdd"])
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(!is_callable(@$opt["stdOutEventAdd"]["call"])) {
|
|
||||||
$this->d("Invalid callable stdOutEventAdd");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!@$opt["silent"])
|
|
||||||
$this->d("Call stdOutEventAdd");
|
|
||||||
|
|
||||||
($opt["stdOutEventAdd" ]["call"]) (
|
|
||||||
$ppsAll[1],
|
|
||||||
$opt["stdOutEventAdd"]
|
|
||||||
);
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(!@$opt["stdErrEventAdd"])
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(!is_callable(@$opt["stdErrEventAdd"]["call"])) {
|
|
||||||
$this->d("Invalid callable stdErrEventAdd");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!@$opt["silent"])
|
|
||||||
$this->d("Call stdErrEventAdd");
|
|
||||||
|
|
||||||
($opt["stdErrEventAdd"]["call"]) (
|
|
||||||
$ppsAll[2],
|
|
||||||
$opt["stdErrEventAdd"]
|
|
||||||
);
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(!@$opt["eventWait"])
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(!@$opt["silent"])
|
|
||||||
$this->d("Call eventWait");
|
|
||||||
|
|
||||||
if(!is_callable(@$opt["eventWait"]["call"])) {
|
|
||||||
$this->d("Invalid callable eventWait");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
($opt["eventWait"]["call"])();
|
|
||||||
} while(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$retVal = proc_close($prcRes);
|
$retVal = proc_close($prcRes);
|
||||||
|
|
||||||
|
|
||||||
if(!@$opt["return"] || @$opt["return"] == "full") {
|
if(!isset($opt["return"]) || !$opt["return"] || $opt["return"] == "full") {
|
||||||
return array(
|
return array(
|
||||||
"retval" => $retVal,
|
"retval" => $retVal,
|
||||||
"stdout" => $out,
|
"stdout" => $out,
|
||||||
@@ -426,12 +602,12 @@
|
|||||||
|
|
||||||
$val = 0;
|
$val = 0;
|
||||||
|
|
||||||
if(@$opt["retval"])
|
if(isset($opt["retval"]) && $opt["retval"])
|
||||||
$val = $opt["retval"];
|
$val = $opt["retval"];
|
||||||
|
|
||||||
if(!@$opt["noerror"]) {
|
if(!isset($opt["noerror"]) || !$opt["noerror"]) {
|
||||||
if($retVal !== $val) {
|
if($retVal !== $val) {
|
||||||
if(!@$opt["silent"]) {
|
if(!isset($opt["silent"]) || !$opt["silent"]) {
|
||||||
$this->d($err);
|
$this->d($err);
|
||||||
$this->d("Return code: " . $retVal);
|
$this->d("Return code: " . $retVal);
|
||||||
}
|
}
|
||||||
@@ -444,10 +620,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($opt["return"]) && $opt["return"]) {
|
||||||
switch(@$opt["return"]) {
|
switch(@$opt["return"]) {
|
||||||
case "retval":
|
case "retval":
|
||||||
return $retVal;
|
return 1*$retVal;
|
||||||
|
|
||||||
case "outstr":
|
case "outstr":
|
||||||
return $out;
|
return $out;
|
||||||
@@ -456,65 +632,151 @@
|
|||||||
default:
|
default:
|
||||||
return explode("\n", $out);
|
return explode("\n", $out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return explode("\n", $out);
|
return explode("\n", $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cmpSysExecTest() {
|
||||||
|
$a = array(
|
||||||
|
"ping" ,
|
||||||
|
"-c" ,
|
||||||
|
"4" ,
|
||||||
|
"127.0.0.1" ,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->d("Launch");
|
||||||
|
$this->d($a);
|
||||||
|
|
||||||
function getGitStatus() {
|
$this->cmpSysExec($a, array(
|
||||||
$ret = $this->fgExec("git status");
|
"silent" => false,
|
||||||
|
"eventString" => true,
|
||||||
// $this->d(join("\n", $ret));
|
"eventStringStdOut" => array("call" => [$this, "d"])
|
||||||
|
));
|
||||||
$out = trim($ret["output"], "\n \t\r");
|
|
||||||
|
|
||||||
if(!$out) {
|
|
||||||
$this->d($ret["stderr"][0]);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$lin = explode("\n", $out);
|
|
||||||
$cnt = count($lin);
|
|
||||||
|
|
||||||
if($lin[$cnt-1] == "nothing to commit, working tree clean") {
|
function getGitStatus($dir = ".") {
|
||||||
$this->gitStatus = "treeClean";
|
$a = array(
|
||||||
$this->d("Git tree clean");
|
"git", "status", "--porcelain"
|
||||||
} else {
|
);
|
||||||
$this->gitStatus = "treeModified";
|
|
||||||
$this->d("Last string: " . $lin[$cnt-1]);
|
$gitStatus = $this->cmpSysExec($a, ["workDir" => $dir]);
|
||||||
|
|
||||||
|
if($gitStatus["retval"]) {
|
||||||
|
$this->d("GIT have errors");
|
||||||
|
$this->d($gitStatus["stderr"]);
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
if(!$gitStatus["stdout"]) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGitLog1() {
|
$this->w("GIT have changes");
|
||||||
$ret = $this->fgExec("git log -1");
|
|
||||||
|
|
||||||
// $this->d(join("\n", $ret));
|
$arr = explode("\n", $gitStatus["stdout"]);
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
$out = trim($ret["output"], "\n \t\r");
|
for($i = 0; $i < count($arr); $i++) {
|
||||||
|
$arr[$i] = trim($arr[$i], "\n \r\t");
|
||||||
|
|
||||||
if(!$out) {
|
if(!$arr[$i])
|
||||||
$this->d($ret["stderr"][0]);
|
continue;
|
||||||
return false;
|
|
||||||
|
$ff = explode(" ", $arr[$i], 2);
|
||||||
|
|
||||||
|
$this->d("flag=" . $ff[0] . " file=" . $ff[1]);
|
||||||
|
|
||||||
|
$ret[] = $ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lin = explode("\n", $out);
|
// $this->d($ret);
|
||||||
$cnt = count($lin);
|
|
||||||
|
|
||||||
$wrd = explode(" ", $lin[0]);
|
return $ret;
|
||||||
$this->gitCommit = $wrd[1];
|
|
||||||
|
|
||||||
$this->gitComment = $lin[$cnt-1];
|
|
||||||
|
|
||||||
$wrd = explode(" ", $lin[2]);
|
|
||||||
array_shift($wrd);
|
|
||||||
$this->gitTimeStamp = strtotime(join(" ", $wrd));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGitLog1($dir = ".") {
|
||||||
|
// https://git-scm.com/docs/pretty-formats
|
||||||
|
$frmReq = array(
|
||||||
|
array("commitHash", "H" ),
|
||||||
|
array("commitDate", "ci"),
|
||||||
|
array("commitTStm", "ct"),
|
||||||
|
array("authorMail", "ae")
|
||||||
|
);
|
||||||
|
|
||||||
|
$frmArr = array();
|
||||||
|
|
||||||
|
for($i = 0; $i < count($frmReq); $i++)
|
||||||
|
$frmArr[] = "%" . $frmReq[$i][1];
|
||||||
|
|
||||||
|
$frmStr = join("%n", $frmArr);
|
||||||
|
|
||||||
|
$a = array(
|
||||||
|
"git", "log", "--pretty=format:$frmStr", "-1"
|
||||||
|
);
|
||||||
|
|
||||||
|
$gitCommit = $this->cmpSysExec($a, ["workDir" => $dir]);
|
||||||
|
|
||||||
|
if($gitCommit["retval"]) {
|
||||||
|
$this->d("GIT have errors");
|
||||||
|
$this->d($gitCommit["stderr"]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$b = explode("\n", $gitCommit["stdout"]);
|
||||||
|
|
||||||
|
$frmRet = array();
|
||||||
|
|
||||||
|
for($i = 0; $i < count($frmReq); $i++)
|
||||||
|
$frmRet[ $frmReq[$i][0] ] = $b[$i];
|
||||||
|
|
||||||
|
return $frmRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmpTraitInit($obj, $lvl = 0) {
|
||||||
|
$listTrait = class_uses($obj);
|
||||||
|
|
||||||
|
foreach($listTrait as $trait) {
|
||||||
|
$this->d("Used trait $trait");
|
||||||
|
|
||||||
|
do {
|
||||||
|
$traitRoot = OUT_PROJ_DIR . "/" . $trait;
|
||||||
|
$traitGit = $traitRoot . "/.git";
|
||||||
|
|
||||||
|
if(!is_dir($traitGit))
|
||||||
|
break;
|
||||||
|
|
||||||
|
$ret = $this->getGitStatus($traitRoot);
|
||||||
|
|
||||||
|
$ret = $this->getGitLog1($traitRoot);
|
||||||
|
|
||||||
|
$this->d($ret);
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
$this->cmpTraitInit($trait, $lvl+1);
|
||||||
|
|
||||||
|
$initMeth = $trait . "Init";
|
||||||
|
|
||||||
|
if(!method_exists($this, $initMeth)) {
|
||||||
|
// $this->d("No method $initMeth");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parm = null;
|
||||||
|
|
||||||
|
if(isset($this->parm[$trait])) {
|
||||||
|
// $this->d("Found parm");
|
||||||
|
$parm = $this->parm[$trait];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->swoSelfCall(array("func" => $initMeth, "parm" => $parm));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function isMD5($str) {
|
function isMD5($str) {
|
||||||
if(preg_match("/^[0-9a-f]{32}$/", $str))
|
if(preg_match("/^[0-9a-f]{32}$/", $str))
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user