fork
該項目到本地;
push
到遠端本身對應的分支;思路html
代碼git
#!/bin/sh # Filename: CheckFramework.sh # # Usage checkRepo.sh git_repo_url # # Algorithm: # 1. clone git_repo to local directory # 2. checkout to each branch (of every student) # 3. testing and evaluating each program written by students. # 4. return result (csv 格式) # # Input: git_repo_url # output: result.csv # ###################################################################### # 0. Global variants ResultFile="result.csv" ; # 返回每一個學生的成績 WorkSpace=`pwd`; export WorkSpace; # 輸出當前工做路徑:WorkSpace # 1. check repo_url if [ $# -lt 1 ]; then echo "Usage:"; echo "\033[1;31m $0 \033[m\033[1;32m gitRepo_url\033[m."; echo "Such as:"; echo "\033[1;31m $0\033[m\033[1;32m https://gitee.com/se16/HelloWorld.git \033[m"; exit; fi # 2. git clone repository $1 # 2.0 if the repository have been cloned before, remove (delete) the repository and re-clone it. RepoName=`echo ${1##*/} | cut -d "." -f 1`; echo "the Repository name is \033[1;31m$RepoName\033[m."; if [ -d $RepoName ]; then echo "deleting the directory named $RepoName"; rm -rf $RepoName; # debug # fi # clone the Repository. echo -e "Cloning the Repository: \033[1;31m$1\033[m."; git clone $1; # 第一次 # 2.1 check if the repository($2) was correctly cloned. if [ ! -d $RepoName ]; then # incorrect repository! echo "Cloning repository ${1##*/} \033[1;31mfailed\033[m. Check it's url, please!"; exit; fi # 2.2 successfully cloned the repository. Now change working directory to sub-directory named $RepoName # step1 : checkout to $bra, # step2 : and check the homeworks one by one, give evaluation score of each homework. # (use an function outsides) # step3 : output result. # 2.2.0 delete previous result.csv if [[ -f $ResultFile ]]; then #statements rm result.csv; fi echo -e "Processing homeworks in each branch named SEXXX"; cd $WorkSpace/$RepoName; # 列舉本地分支,篩選學生創建的『SEXXX』分支,刪除當前分支前的星號 "*"" ,及空格 git branch --all | cut -d "/" -f 3| grep -ai 'se' | sed 's/[\* ]//g'> $WorkSpace/branches.txt; count=0; while read bra; do let count=count+1; # 2.2.1 checkout ; OK git checkout -q $bra; # -q --quiet # suppress progress reporting # 2.2.2 run test script, and return a score of current branch(student). Dev echo "\n-e NO.\033[1;31m$count\033[m. Reviewing homeworks of student NO. \033[1;32m$bra ...\033[m "; # call CheckersCaller : driver , and export TotalScore # echo $WorkSpace; source $WorkSpace/CheckersCaller.sh; # return score of current branch (student's work) score=$TotalScore; # 2.2.3 write score to a structure which records all students scores. OK echo "$bra,$score" >> $WorkSpace/$ResultFile done < $WorkSpace/branches.txt echo "\nFinished";
CheckersCaller.sh
須要對 score 的彙總作微調 (包括:權重、彙總項目)source Checker_i.sh
,調用不一樣的檢查器;Checker_i.sh
輸出 對應的檢查項目得分 score_i
;wi
, 對全部檢查項目得分加權(wi),獲得彙總得分 TotalScore
;TotalScore
。(export TotalScore
)#!/bin/sh # Filename: CheckersCaller.sh # # Usage: CheckersCaller.sh # # Algorithm: # 1. call checkers which export a set of scores # 2. summation:sum the scores to TotalScore # 3. export TotalScore # # Input:Null # Output:TotalScore -- summation of each score_i. # ##################################################### TotalScore=0 # 1. 調用一組Checker_i.sh 腳本, 獲得一組輸出 score_i (單項得分) source $WorkSpace/Checker_1.sh "*.c"; let s1=score_1; source $WorkSpace/Checker_1.sh "*.cpp"; let s2=score_1; source $WorkSpace/Checker_1.sh "*.py"; let s3=score_1; # ... # source Checker_n.sh # 2. 彙總得分 (wi 爲每一項的權重) # let TotalScore=score_1*w1+score_2*w2+...+score_n*wn let TotalScore=s1+s2+s3; echo "TotalScore : $TotalScore"; # 3. 輸出彙總分 TotalScore export TotalScore;
思路shell
代碼示例框架
#!/bin/sh # Checker_1.sh # # Usage Checker_1.sh filename # # Algorithm : # 1. check the file (SUT) existence # 2. Review or test SUT, give an evaluation score (score) # 3. export score_i (score_i equals to evaluation result.) # # Input: filename -- software under test(review)SUT # Output:score_i -- export score_i # ################################################# # 0. Global variable for export score_1=0 # here i=1 # 1. checker_i Usage if [ $# -lt 1 ]; then echo "Usage:"; echo " \033[1;31m $0 \033[m\033[1;32m filename\033[m."; echo "eg. \033[1;31m $0\033[m\033[1;32m HelloWord.c \033[m"; exit; fi # 2. Does file $1 exist? s_temp is the evaluation full_filename=""; full_filename=`find . -name $1`; #if [[ ! -f $1 ]]; then # file does not exist if [[ ${#full_filename} == 0 ]]; then # file does not exist echo "File \033[1;32m$1\033[m does\033[1;31m not exist\033[m!"; s_temp=0; else # in this block, you can call other tools or write scripts for evaluating # call foreign tools or scripts # return a score # ...... s_temp=`$WorkSpace/tools/sloccount/c_count $full_filename | sed -n '$p'`; # sed -n '$p'取最後一行數據 echo "Lines of $full_filename is $s_temp"; fi # 3. export global variable let score_1=s_temp; export score_1
還能夠有其餘審查項目,須要老師(助教)本身編寫檢查器,好比能夠:ide
..\workspace -- |-- CheckFramework.sh |-- CheckersCaller.sh |-- Checker_1.sh |-- Checker_2.sh |-- .... ... |-- Checker_n.sh |-- \toos\-- |-- \sloccount\ ..... # 一組代碼行計數工具, 這些工具供給 檢查器 ``Checker_i.sh``使用 |-- \*********\ ..... # 其餘軟件度量工具 |-- ..... # |-- RepositoriesName # clone 到本地的遠程倉庫 |-- result.csv # 檢查得分,與分支名對應 (不一樣的學生對應不一樣的分支) |-- branches.txt # 臨時文件,存放學生分支 (不一樣的學生對應不一樣的分支,命名規則 SEXXX ,XXX 學號後三位