r 输出 html 文件路径,Beyond Compare 命令行生成目录下所有文件比对的Html网页report...

MAC环境下,使用Beyond Compare命令行生成两个文件夹差异的html,按目录递归生成。

#1. 创建compare

#2. 创建compare/old

#3. compare/new

#4. sh tree.sh ~/Desktop/compare

#5. 生成 ~/Desktop/report

#环境初始化

function init()

{

echo "#########环境初始化#########################"

WORK_DIR=$(cd $(dirname $0); pwd)

#echo $WORK_DIR

BasePath=$1

BasePathLength=${#BasePath}

#命令行是否/结尾问题

FINAL=${BasePath:0-1}

#echo "FINAL:"$FINAL

#echo "BasePath...:"$BasePath

if [ ${FINAL} == "/" ]; then

#命令行是/结尾

BasePath=${BasePath:0:$BasePathLength-1}

#echo "BasePath......:"$BasePath

BaseOldPath="$1old"

BaseNewPath="$1new"

echo "YES"

else

#命令行否/结尾

BaseOldPath="$1/old"

BaseNewPath="$1/new"

echo "NO"

fi

BaseReportPath=$WORK_DIR/report

#生成report目录

if [ ! -d $BaseReportPath ]; then

echo "新建目录"

mkdir $BaseReportPath

else

echo "目录存在,重新生成"

rm -rf $BaseReportPath

mkdir $BaseReportPath

fi

#检查目录

if [ -d $BaseReportPath ]; then

echo "report目录创建成功"

else

echo "report目录创建失败,退出"

exit

fi

BasePatchPath=$WORK_DIR/diff_to_html

echo "强制写入比对配置文件"

echo "text-report layout:side-by-side &

options:display-all,line-numbers,display-context &

output-to:%3 output-options:html-color %1 %2" > $BasePatchPath

if [ -f $BasePatchPath ]; then

echo "临时写入比对配置文件成功"

else

echo "临时写入比对配置文件失败,退出"

exit

fi

BaseEmptyPath=$WORK_DIR/empty

echo "" > $BaseEmptyPath

echo "##########路径参数###########"

echo "BasePath...............:$BasePath"

echo "BaseOldPath............:$BaseOldPath"

echo "BaseNewPath............:$BaseNewPath"

echo "BaseReportPath.........:$BaseReportPath"

echo "BasePatchPath..........:$BasePatchPath"

echo "BaseEmptyPath..........:$BaseEmptyPath"

echo "#####################"

echo "#########环境初始化 ok############################"

}

#目录检查

# BasePath...............:~/Desktop/compare

# BaseOldPath............:~/Desktop/compare/old

# BaseNewPath............:~/Desktop/compare/new

function checkCompareDir(){

echo "##############checkCompareDir start########################"

if [ ! -d $BasePath ]; then

echo $BasePath"目录不存在,请检查!"

exit 0

fi

if [ ! -d $BaseOldPath ]; then

echo $BaseOldPath"子目录不存在,请检查!"

exit 0

fi

if [ ! -d $BaseNewPath ]; then

echo $BaseNewPath"子目录不存在,请检查!"

exit 0

fi

echo "##############checkCompareDir end########################"

}

function listFiles()

{

#1st param, the dir name

for file in `ls $1`;

do

#echo "path....:$1/$file"

if [ -d "$1/$file" ]; then

# echo "$2$file"

# echo "$1/$file"

#递归

listFiles "$1/$file"

else

#比较文件A

compareFileAPath=$1/$file

#echo "compareFileAPath..............:$compareFileAPath"

if [[ "${compareFileAPath}" =~ $BaseNewPath ]]; then

#echo "compareFileAPath is new"

compareFileBPath=$compareFileAPath

compareFileAPath=${compareFileBPath/$BaseNewPath/$BaseOldPath}

if [ ! -d $compareFileAPath ]; then

echo "A path不存在"

fulldir=$1

#临时html路径,compareFileAPath替换BaseOldPath赋值BaseReportPath

tempHtmlPath=${compareFileBPath/$BaseNewPath/$BaseReportPath}

# echo "tempHtmlPath....................:$tempHtmlPath"

#html文件路径,tempHtmlPath拼接.html

htmlPath=$tempHtmlPath.html

# echo "htmlPath......................:$htmlPath"

#替换生成Html文件对应的目录

htmldir=${fulldir/$BaseNewPath/$BaseReportPath}

#echo "htmldir......................:$htmldir"

#如果Html文件夹不存在,创建对应文件夹

if [ ! -d $htmldir ]; then

#echo "create.....:$htmldir"

mkdir $htmldir

fi

fi

else

echo "#old############"

fulldir=$1

# echo "fulldir..............:$fulldir"

#比较文件B,compareFileAPath替换BaseOldPath赋值BaseNewPath

compareFileBPath=${compareFileAPath/$BaseOldPath/$BaseNewPath}

# echo "compareFileBPath..............:$compareFileBPath"

#临时html路径,compareFileAPath替换BaseOldPath赋值BaseReportPath

tempHtmlPath=${compareFileBPath/$BaseNewPath/$BaseReportPath}

# echo "tempHtmlPath....................:$tempHtmlPath"

#html文件路径,tempHtmlPath拼接.html

htmlPath=$tempHtmlPath.html

# echo "htmlPath......................:$htmlPath"

#替换生成Html文件对应的目录

htmldir=${fulldir/$BaseNewPath/$BaseReportPath}

# echo "htmldir......................:$htmldir"

#如果Html文件夹不存在,创建对应文件夹

if [ ! -d $htmldir ]; then

echo "create.....:$htmldir"

mkdir $htmldir

fi

fi

echo "#################file compare start#####################"

if [ -f $compareFileBPath ]; then

#echo "compare aciton...B存在:$compareFileBPath"

if [ ! -f $compareFileAPath ]; then

echo "#################NEW#####################"

bcompare -silent @$BasePatchPath $BaseEmptyPath $compareFileBPath $htmlPath

else

#A存在

echo "#################UPDATE#####################"

#echo "compare aciton...$compareFileAPath"

# echo "compareFileAPath.......:$compareFileAPath"

# echo "compareFileBPath.......:$compareFileBPath"

if [[ "${compareFileAPath}" =~ $BaseOldPath ]]; then

bcompare -silent @$BasePatchPath $compareFileAPath $compareFileBPath $htmlPath

fi

fi

fi

echo "###################file compare end#########################"

fi

done

}

#清理函数

function clear(){

#echo "删除比对配置文件"

rm -rf $BasePatchPath

rm -rf $BaseEmptyPath

}

#######main run

init $1

checkCompareDir

listFiles $BasePath

clear

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值