From b198365b87b630278066b740054a9032f4d9868b Mon Sep 17 00:00:00 2001 From: Nayeon Keum Date: Fri, 29 Sep 2023 17:37:14 +0900 Subject: [PATCH] [feat/#97] Add: C and CPP available for assignment --- resources/images/control-ubuntu/Dockerfile | 2 +- resources/images/professor-ubuntu/Dockerfile | 2 +- .../professor-ubuntu/server/getValueAndTime_c.sh | 12 ++++++++++++ .../professor-ubuntu/server/getValueAndTime_cpp.sh | 12 ++++++++++++ ...getValueAndTime.sh => getValueAndTime_python.sh} | 3 ++- resources/images/professor-ubuntu/server/main.py | 13 ++++++++++++- resources/images/student-ubuntu/Dockerfile | 2 +- 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 resources/images/professor-ubuntu/server/getValueAndTime_c.sh create mode 100644 resources/images/professor-ubuntu/server/getValueAndTime_cpp.sh rename resources/images/professor-ubuntu/server/{getValueAndTime.sh => getValueAndTime_python.sh} (99%) diff --git a/resources/images/control-ubuntu/Dockerfile b/resources/images/control-ubuntu/Dockerfile index 42cfded..dd68c11 100644 --- a/resources/images/control-ubuntu/Dockerfile +++ b/resources/images/control-ubuntu/Dockerfile @@ -19,7 +19,7 @@ RUN apt-get dist-upgrade RUN echo "deb http://archive.ubuntu.com/ubuntu vivid main restricted universe" >> /etc/apt/sources.list # libffi-dev -RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc cron dnsutils tzdata +RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc g++ cron dnsutils tzdata ## TZ ENV TZ=Asia/Seoul diff --git a/resources/images/professor-ubuntu/Dockerfile b/resources/images/professor-ubuntu/Dockerfile index feeb7ea..8ec82a5 100644 --- a/resources/images/professor-ubuntu/Dockerfile +++ b/resources/images/professor-ubuntu/Dockerfile @@ -18,7 +18,7 @@ RUN apt-get autoclean RUN apt-get dist-upgrade RUN echo "deb http://archive.ubuntu.com/ubuntu vivid main restricted universe" >> /etc/apt/sources.list # libffi-dev -RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc cron tzdata +RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc g++ cron tzdata ## TZ ENV TZ=Asia/Seoul diff --git a/resources/images/professor-ubuntu/server/getValueAndTime_c.sh b/resources/images/professor-ubuntu/server/getValueAndTime_c.sh new file mode 100644 index 0000000..7193d38 --- /dev/null +++ b/resources/images/professor-ubuntu/server/getValueAndTime_c.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +start=`date +%s.%N` + +/usr/bin/gcc $1 -o $2/test.out +$2/test.out > values.txt + +finish=`date +%s.%N` + + +diff=$( echo "$finish - $start" | bc -l ) +/usr/bin/echo $diff > time.txt \ No newline at end of file diff --git a/resources/images/professor-ubuntu/server/getValueAndTime_cpp.sh b/resources/images/professor-ubuntu/server/getValueAndTime_cpp.sh new file mode 100644 index 0000000..8fd679a --- /dev/null +++ b/resources/images/professor-ubuntu/server/getValueAndTime_cpp.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +start=`date +%s.%N` + +/usr/bin/g++ -o $2/test $1 +$2/test > values.txt + +finish=`date +%s.%N` + + +diff=$( echo "$finish - $start" | bc -l ) +/usr/bin/echo $diff > time.txt \ No newline at end of file diff --git a/resources/images/professor-ubuntu/server/getValueAndTime.sh b/resources/images/professor-ubuntu/server/getValueAndTime_python.sh similarity index 99% rename from resources/images/professor-ubuntu/server/getValueAndTime.sh rename to resources/images/professor-ubuntu/server/getValueAndTime_python.sh index 08bf02a..2ad5de1 100644 --- a/resources/images/professor-ubuntu/server/getValueAndTime.sh +++ b/resources/images/professor-ubuntu/server/getValueAndTime_python.sh @@ -5,6 +5,7 @@ start=`date +%s.%N` /usr/bin/python3 $1 > values.txt finish=`date +%s.%N` -diff=$( echo "$finish - $start" | bc -l ) + +diff=$( echo "$finish - $start" | bc -l ) /usr/bin/echo $diff > time.txt \ No newline at end of file diff --git a/resources/images/professor-ubuntu/server/main.py b/resources/images/professor-ubuntu/server/main.py index e1470a8..d7e76c4 100644 --- a/resources/images/professor-ubuntu/server/main.py +++ b/resources/images/professor-ubuntu/server/main.py @@ -86,7 +86,18 @@ async def get_assignment(id: str, assignment_id: str): content = f.read() return_dict["content"] = content f.close() - os.system(f"/bin/bash {curr_path}/getValueAndTime.sh {file_path}") + # Complie differs by extension + if file_path.split(".")[-1] == "py": + os.system( + f"/bin/bash {curr_path}/getValueAndTime_python.sh {file_path}") + elif file_path.split(".")[-1] == "c": + os.system( + f"/bin/bash {curr_path}/getValueAndTime_c.sh {file_path}") + elif file_path.split(".")[-1] == "cpp": + os.system( + f"/bin/bash {curr_path}/getValueAndTime_cpp.sh {file_path}") + else: + print("지원되지 않는 파일 형식입니다.") f = open(f"{curr_path}/values.txt", "r") values = f.read() return_dict["answer"] = values diff --git a/resources/images/student-ubuntu/Dockerfile b/resources/images/student-ubuntu/Dockerfile index 5f1c03a..9fe42e4 100644 --- a/resources/images/student-ubuntu/Dockerfile +++ b/resources/images/student-ubuntu/Dockerfile @@ -19,7 +19,7 @@ RUN apt-get dist-upgrade RUN echo "deb http://archive.ubuntu.com/ubuntu vivid main restricted universe" >> /etc/apt/sources.list # libffi-dev -RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc tzdata tree shc +RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc g++ tzdata tree shc ## TZ ENV TZ=Asia/Seoul