fork
该项目到本地;push
到远端自己对应的分支;思路
代码
#!/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" # 返回每个学生的成绩
# 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
if [ ! -d $1 ]; then
echo -e "Cloning the Repository: \033[1;31m$1\033[m.";
#git clone $1;
fi
# 2.1 check if the repository($2) was correctly cloned.
RepoName=`echo ${1##*/} | cut -d "." -f 1`;
echo "the Repository name is \033[1;31m$RepoName\033[m.";
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 $RepoName;
# 列举本地分支,筛选学生建立的『SEXXX』分支,删除当前分支前的星号 "*"" ,及空格
git branch --list | grep -ai 'se' | sed 's/[\* ]//g' > "../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 ";
## add some scripts ...
ls;
## return score of current branch (student's work)
score=60;
# 2.2.3 write score to a structure which records all students scores. OK
echo "$bra,$score" >> ../$ResultFile
done < ../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 Checker_1.sh
source Checker_2.sh
...
source Checker_n.sh
# 2. 汇总得分 (wi 为每一项的权重)
TotalScore=score_1*w1+score_2*w2+...+score_n*wn
# 3. 输出汇总分 TotalScore
export TotalScore
思路
代码示例
#!/bin/sh
# Checker_1.sh
# usage Checker_1.sh filename
# 思路:
# 1. 检查待测文件是否存在
# 2. 静态检查源代码,给一个评测分 S
#
# Input: filename -- Program under test(review)
# Output:score_i -- export score_i
#
#################################################
# 0. Global variable for export
score_1=0 # here i=1
# 1. check Usage
if [ $# -lt 1 ]; then
echo "Usage:";
echo "\033[1;31m $0 \033[m\033[1;32m filename\033[m.";
echo "Such as:";
echo "\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
if [[ ! -f $1 ]]; then # 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=score
fi
# 3. export global variable
export score_1
还可以有其他审查项目,需要老师(助教)自己编写检查器,比如可以:
原文:https://www.cnblogs.com/juking/p/9733978.html