|
@@ -1,12 +1,27 @@
|
|
|
<?php
|
|
|
-//记录普通日志
|
|
|
-function logInfo($content){
|
|
|
- file_put_contents(LOG_PATH, $content.PHP_EOL, FILE_APPEND);
|
|
|
+//记录信息日志
|
|
|
+function logInfo(){
|
|
|
+ $content = '[INFO]';
|
|
|
+ $args = func_get_args();
|
|
|
+ $argc = func_num_args();
|
|
|
+ for($i=0;$i<$argc;$i++){
|
|
|
+ $content .= $args[$i] . ' ';
|
|
|
+ }
|
|
|
+ $content .= PHP_EOL;
|
|
|
+ file_put_contents(LOG_PATH, $content, FILE_APPEND);
|
|
|
}
|
|
|
//记录错误日志
|
|
|
function logError($content){
|
|
|
- file_put_contents(LOG_PATH, $content.PHP_EOL, FILE_APPEND);
|
|
|
+ $content = '[ERR]';
|
|
|
+ $args = func_get_args();
|
|
|
+ $argc = func_num_args();
|
|
|
+ for($i=0;$i<$argc;$i++){
|
|
|
+ $content .= $args[$i] . ' ';
|
|
|
+ }
|
|
|
+ $content .= PHP_EOL;
|
|
|
+ file_put_contents(LOG_PATH, $content, FILE_APPEND);
|
|
|
}
|
|
|
+
|
|
|
//获取操作系统名称
|
|
|
function getOsName(){
|
|
|
if(substr(PHP_OS,0,3)==='WIN')
|
|
@@ -55,6 +70,64 @@ function pathJoin($base, $path) {
|
|
|
}
|
|
|
return $newPath;
|
|
|
}
|
|
|
+
|
|
|
+//枚举子目录
|
|
|
+function scanSubDir($dir,$exclude_names = array()){
|
|
|
+ $filelist = scandir($dir);
|
|
|
+ $subdirs = array();
|
|
|
+ foreach($filelist as $filename){
|
|
|
+ //过滤掉当前目录和上级目录
|
|
|
+ if($filename == "." || $filename ==".."){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //过滤掉排查的名称
|
|
|
+ if(in_array($filename,$exclude_names)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //判断是否是文件夹
|
|
|
+ $filepath = pathJoin($dir,$filename);
|
|
|
+ if(is_dir($filepath) ){
|
|
|
+ array_push($subdirs,$filename);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $subdirs;
|
|
|
+}
|
|
|
+
|
|
|
+//枚举所有仓库名
|
|
|
+function scanRepoNames($vendoDir){
|
|
|
+ $repos = array();
|
|
|
+ $users = scanSubDir($vendorDir);
|
|
|
+ foreach($users as $user){
|
|
|
+ $userdir = pathJoin($vendorDir,$user);
|
|
|
+ $names = scanSubDir($userdir);
|
|
|
+ foreach($names as $name){
|
|
|
+ array_push($repos,$user . '/' . $name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ array_push($repos,"."); //.名称表示顶层包,放最后
|
|
|
+ return $repos;
|
|
|
+}
|
|
|
+
|
|
|
+//解析所有仓库配置
|
|
|
+function loadRepoConfigs($vendorDir,$repoNames){
|
|
|
+ $configs = array();
|
|
|
+ foreach($repoNames as $repoName){
|
|
|
+ if($repoName == '.')
|
|
|
+ $cfgPath = pathJoin(dirname($vendorDir),'composer.json');
|
|
|
+ else
|
|
|
+ $cfgPath = pathJoin($vendorDir,$repoName,'composer.json');
|
|
|
+ $data = json_decode(file_get_contents($cfgPath), true);
|
|
|
+ if(!$data){
|
|
|
+ logError('invalid composer.json',$cfgPath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $configs[$repoName] = $data;
|
|
|
+ }
|
|
|
+ return $configs;
|
|
|
+}
|
|
|
+function getTotalUseSpace($repoConfigs){
|
|
|
+
|
|
|
+}
|
|
|
//.distribute路径
|
|
|
function getDistributeDir($vendorDir){
|
|
|
return pathJoin(dirname($vendorDir),'.distribute');
|