From fe1b87f9d68a92463a11e0b0477674b3f98ab35d Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 7 May 2019 10:10:36 +0800 Subject: [PATCH 1/8] '..' --- app/controllers/welcome_controller.rb | 15 ++- ...13619_add_local_giturl_to_local_shixuns.rb | 5 + local_shixuns.sql | 92 +++++++++++++++++++ localmysql.sh | 3 + 4 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190507013619_add_local_giturl_to_local_shixuns.rb create mode 100644 local_shixuns.sql create mode 100644 localmysql.sh diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c9d41c0a..da87917b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -53,7 +53,8 @@ class WelcomeController < ApplicationController local_shixun = LocalShixun.create!(name: shixun.name, description: shixun.description, user_id: User.current.id, status: 0, trainee: shixun.trainee, webssh: shixun.webssh, multi_webssh: shixun.multi_webssh, can_copy: shixun.can_copy, identifier: generate_identifier, shixun_id: shixun.id, - use_scope: shixun.use_scope, visits: 1, evaluate_script: shixun.evaluate_script) + use_scope: shixun.use_scope, visits: 1, evaluate_script: shixun.evaluate_script, + local_giturl: shixun.git_url) # 同步镜像 if shixun.mirror_repositories.present? @@ -97,10 +98,10 @@ class WelcomeController < ApplicationController end end end - render :json => {status: 0, message: "同步成功"} + render :json => {status: 0, message: "success"} rescue Exception => e logger.error("shixun_local_in ##{e.message}") - render :json => {status: -1, message: "同步失败,#{e.message}"} + render :json => {status: -1, message: "error,#{e.message}"} raise ActiveRecord::Rollback end @@ -147,6 +148,14 @@ class WelcomeController < ApplicationController raise "版本库创建失败" if shixun.gpid.blank? # 若和gitlab没同步成功,则抛出异常 g = Gitlab.client shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) + local_git_path = local_shixun.local_giturl.split('/').last if local_shixun.local_giturl.present? + new_giturl = "http://educoder:xinhu1ji2qu3@"+g.project(shixun.gpid).http_url_to_repo.split('//').last + system("cd tmp/repositories/#{local_git_path}") + system("git remote remove origin") + system("git remote add origin #{new_giturl}") + system("git add .") + system("git commit -m 'first commit'") + system("git push origin master") # 同步关卡信息 local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id) diff --git a/db/migrate/20190507013619_add_local_giturl_to_local_shixuns.rb b/db/migrate/20190507013619_add_local_giturl_to_local_shixuns.rb new file mode 100644 index 00000000..83589808 --- /dev/null +++ b/db/migrate/20190507013619_add_local_giturl_to_local_shixuns.rb @@ -0,0 +1,5 @@ +class AddLocalGiturlToLocalShixuns < ActiveRecord::Migration + def change + add_column :local_shixuns, :local_giturl, :string + end +end diff --git a/local_shixuns.sql b/local_shixuns.sql new file mode 100644 index 00000000..be372e01 --- /dev/null +++ b/local_shixuns.sql @@ -0,0 +1,92 @@ +-- MySQL dump 10.13 Distrib 5.5.42, for Win64 (x86) +-- +-- Host: localhost Database: 20180311 +-- ------------------------------------------------------ +-- Server version 5.5.42 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `local_shixuns` +-- + +DROP TABLE IF EXISTS `local_shixuns`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `local_shixuns` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `description` text COLLATE utf8_unicode_ci, + `user_id` int(11) DEFAULT NULL, + `gpid` int(11) DEFAULT NULL, + `visits` int(11) DEFAULT NULL, + `status` int(11) DEFAULT NULL, + `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `authentication` text COLLATE utf8_unicode_ci, + `identifier` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `propaedeutics` text COLLATE utf8_unicode_ci, + `trainee` int(11) DEFAULT NULL, + `major_id` int(11) DEFAULT NULL, + `webssh` int(11) DEFAULT NULL, + `homepage_show` tinyint(1) DEFAULT NULL, + `hidden` tinyint(1) DEFAULT NULL, + `fork_from` int(11) DEFAULT NULL, + `can_copy` tinyint(1) DEFAULT NULL, + `modifiy_tim` datetime DEFAULT NULL, + `reset_time` datetime DEFAULT NULL, + `closer_id` int(11) DEFAULT NULL, + `end_time` datetime DEFAULT NULL, + `git_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `vnc` tinyint(1) DEFAULT NULL, + `myshixuns_count` int(11) DEFAULT NULL, + `challenges_count` int(11) DEFAULT NULL, + `use_scope` int(11) DEFAULT NULL, + `evaluate_script` text COLLATE utf8_unicode_ci, + `mirror_script_id` int(11) DEFAULT NULL, + `image_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `code_hidden` tinyint(1) DEFAULT NULL, + `task_pass` tinyint(1) DEFAULT NULL, + `exec_time` int(11) DEFAULT NULL, + `test_set_permission` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `sigle_training` tinyint(1) DEFAULT NULL, + `hide_code` tinyint(1) DEFAULT NULL, + `multi_webssh` tinyint(1) DEFAULT NULL, + `excute_time` int(11) DEFAULT NULL, + `averge_star` int(11) DEFAULT NULL, + `forbid_copy` int(11) DEFAULT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + `shixun_id` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `local_shixuns` +-- + +LOCK TABLES `local_shixuns` WRITE; +/*!40000 ALTER TABLE `local_shixuns` DISABLE KEYS */; +INSERT INTO `local_shixuns` VALUES (1,'单链表的学习与应用(I)','链表(Linked List)是一种通用的数据结构,主要用于表示和管理数量不确定的数据。链表可有效解决数组(Array)在动态数据管理方面的不足。\r\n\r\n本实训项目的主要内容是基于Java语言开发一个具有基本功能的单链表,从六个方面介绍链表相关知识,并设置了六个关卡在线考察大家的链表编程能力。\r\n![](/attachments/download/169299)',2,NULL,1,0,NULL,NULL,'bifnvguo',NULL,1,NULL,0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,'#!/bin/bash\n#工作空间\ncd WORKSPACE\n#用户打开的文件名,之所以传过来这个,是因为可以从这个里面提取出来执行文件名\nchallengeProgramNames=(\"src/step1/ListNodeTest.java\" \"src/step2/ListNodeTest.java\" \"src/step3/LinkedListTest.java\" \"src/step4/LinkedListTest.java\" \"src/step5/LinkedListTest.java\" \"src/step6/LinkedListTest.java\")\n#执行文件名\nsourceClassNames=(\"step1.ListNodeTest\" \"step2.ListNodeTest\" \"step3.LinkedListTest\" \"step4.LinkedListTest\" \"step5.LinkedListTest\" \"step6.LinkedListTest\")\ninput=$2;OLD_IFS=\"$IFS\"; IFS=,; ins=($input);IFS=\"$OLD_IFS\"\n\n#限制每个shell连接所能写文件的最大容量,100M\necho \'ulimit -f 10000\' >>/root/.bashrc ; source /root/.bashrc\n\ncompile(){\n #编译命令,有的语言是没有编译过程,这个时候默认编译成功\n compileCommand=\"javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/\"\n #取当前关卡的编译文件\n challengeProgramName=${challengeProgramNames[$1 - 1]}\n #当前关卡,作为参数传进来\n challengeStage=$1\n #删除上一次编译生成的文件,防止对本次编译造成影响\n rm -f ./target/step$challengeStage/*.class &> /dev/null\n \n # 获取编译结果(此处编译无输出则说明编译通过,否则输出编译错误信息,请按实训实际情况调整)\n compileResult=$($compileCommand $challengeProgramName 2>&1 | base64)\n if [ -z \"$compileResult\" ]; then\n compileResult=$(echo -n \"compile successfully\" | base64)\n fi\n\n}\ncompile $1\n\n\nexecute(){\n #执行命令\n executeCommand=\"java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/\"\n #执行文件名\n sourceClassName=${sourceClassNames[$1 - 1]}\n challengeStage=$1\n \n output=\'\'\n i=0\n while [[ i -lt ${#ins[*]} ]]; do\n #执行,并拼接执行结果\n result=$(echo \"${ins[$i]}\" | base64 -d | $executeCommand $sourceClassName 2>&1 | base64)\n #拼接输出结果\n output=$output\\\"$result\\\",\n let i++\n done\n output=\"[${output%?}]\"\n}\n\nexecute $1\n\n#return result in json format\nreturnResult(){\n result=\"{\\\"compileResult\\\":\\\"$compileResult\\\",\\\"out\\\":$output}\"\n echo $result\n}\n#拼装成最终的json格式,echo输出得到最后结果\nreturnResult\n\n',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,'2019-05-07 08:40:18','2019-05-07 08:40:18',50),(2,'MySQL数据库编程开发实训(基础篇)','数据库(Database,DB)是一种建立在计算机存储设备上的,按照某种结构来组织、存储和管理数据的集合。数据库管理系统(Database Management System,DBMS)是对数据库进行访问,完成数据存储、检索、管理和处理的软件。\r\n\r\nMySQL是目前最流行的关系型DBMS,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL具有性能高、成本低、可靠性好、开放源码等特点,广泛应用于网站开发和移动应用开发,在科学研究中的应用也极其广泛。\r\n\r\n本项目将从数据库连接,数据库实例与数据表的创建,数据记录的查询、插入、删除与更新、数据库应用等几个方面进行介绍,结合流行的JDBC技术,共设置了七个关卡在线考察大家的数据库访问编程能力。后续大家可以通过进阶学习来了解和掌握更高级更复杂的用法。\r\n\r\n![](/attachments/download/169466)',2,NULL,1,0,NULL,NULL,'els2pthi',NULL,1,NULL,1,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,'#!/bin/bash\ncd WORKSPACE\n\nchallengeProgramNames=(\"src/step1/MySQLWithJDBCTest.java\" \"src/step2/CreateTableTest.java\" \"src/step3/QueryRecordTest.java\" \"src/step4/InsertTableTest.java\" \"src/step5/DeleteRecordTest.java\" \"src/step6/UpdateRecordTest.java\" \"src/step7/TransferTableTest.java\")\nsourceClassNames=(\"step1.MySQLWithJDBCTest\" \"step2.CreateTableTest\" \"step3.QueryRecordTest\" \"step4.InsertTableTest\" \"step5.DeleteRecordTest\" \"step6.UpdateRecordTest\" \"step7.TransferTableTest\")\ninput=$2;OLD_IFS=\"$IFS\"; IFS=,; ins=($input);IFS=\"$OLD_IFS\"\n\necho \'ulimit -f 10000\' >>/root/.bashrc ; source /root/.bashrc\n\ncompile(){\n compileCommand=\"javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/\"\n challengeProgramName=${challengeProgramNames[$1 - 1]}\n challengeStage=$1\n #remove the .class files that last time remains\n rm -f ./target/step$challengeStage/*.class &> /dev/null\n\n # 获取编译结果(此处编译无输出则说明编译通过,否则输出编译错误信息,请按实训实际情况调整)\n compileResult=$($compileCommand $challengeProgramName 2>&1 | base64)\n if [ -z \"$compileResult\" ]; then\n compileResult=$(echo -n \"compile successfully\" | base64)\n fi\n}\ncompile $1\n\n\nexecute(){\n executeCommand=\"java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/\"\n sourceClassName=${sourceClassNames[$1 - 1]}\n challengeStage=$1\n \n #get the loop times(looptimes = the num of testdataset)\n output=\'\'\n i=0\n while [[ i -lt ${#ins[*]} ]]; do\n #执行,并拼接执行结果\n result=$(echo \"${ins[$i]}\" | base64 -d | $executeCommand $sourceClassName 2>&1 | base64)\n #拼接输出结果\n output=$output\\\"$result\\\",\n let i++\n done\n output=\"[${output%?}]\"\n}\n\nexecute $1\n\n#return result in json format\nreturnResult(){\n result=\"{\\\"compileResult\\\":\\\"$compileResult\\\",\\\"out\\\":$output}\"\n echo $result\n}\n#拼装成最终的json格式,echo输出得到最后结果\nreturnResult\n\n',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,'2019-05-07 08:40:18','2019-05-07 08:40:18',41); +/*!40000 ALTER TABLE `local_shixuns` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-05-07 8:57:56 diff --git a/localmysql.sh b/localmysql.sh new file mode 100644 index 00000000..15c5577a --- /dev/null +++ b/localmysql.sh @@ -0,0 +1,3 @@ +mysql -uroot -p1234; +use 20180311; +source local_shixuns.sql \ No newline at end of file From e6b3b6b5358a87e150378ed0b97e366a2c043e15 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 7 May 2019 10:19:19 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=88=B0=E7=BA=BF?= =?UTF-8?q?=E4=B8=8A=E4=BB=93=E5=BA=93=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index da87917b..e727d92b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -154,7 +154,7 @@ class WelcomeController < ApplicationController system("git remote remove origin") system("git remote add origin #{new_giturl}") system("git add .") - system("git commit -m 'first commit'") + system("git commit -m '..'") system("git push origin master") # 同步关卡信息 From 41e0cf8950a2dfd7755213fd35c9a599c197415a Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 7 May 2019 10:21:23 +0800 Subject: [PATCH 3/8] .. --- local_shixuns.sql | 92 ----------------------------------------------- localmysql.sh | 3 -- 2 files changed, 95 deletions(-) delete mode 100644 local_shixuns.sql delete mode 100644 localmysql.sh diff --git a/local_shixuns.sql b/local_shixuns.sql deleted file mode 100644 index be372e01..00000000 --- a/local_shixuns.sql +++ /dev/null @@ -1,92 +0,0 @@ --- MySQL dump 10.13 Distrib 5.5.42, for Win64 (x86) --- --- Host: localhost Database: 20180311 --- ------------------------------------------------------ --- Server version 5.5.42 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `local_shixuns` --- - -DROP TABLE IF EXISTS `local_shixuns`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `local_shixuns` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `description` text COLLATE utf8_unicode_ci, - `user_id` int(11) DEFAULT NULL, - `gpid` int(11) DEFAULT NULL, - `visits` int(11) DEFAULT NULL, - `status` int(11) DEFAULT NULL, - `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `authentication` text COLLATE utf8_unicode_ci, - `identifier` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `propaedeutics` text COLLATE utf8_unicode_ci, - `trainee` int(11) DEFAULT NULL, - `major_id` int(11) DEFAULT NULL, - `webssh` int(11) DEFAULT NULL, - `homepage_show` tinyint(1) DEFAULT NULL, - `hidden` tinyint(1) DEFAULT NULL, - `fork_from` int(11) DEFAULT NULL, - `can_copy` tinyint(1) DEFAULT NULL, - `modifiy_tim` datetime DEFAULT NULL, - `reset_time` datetime DEFAULT NULL, - `closer_id` int(11) DEFAULT NULL, - `end_time` datetime DEFAULT NULL, - `git_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `vnc` tinyint(1) DEFAULT NULL, - `myshixuns_count` int(11) DEFAULT NULL, - `challenges_count` int(11) DEFAULT NULL, - `use_scope` int(11) DEFAULT NULL, - `evaluate_script` text COLLATE utf8_unicode_ci, - `mirror_script_id` int(11) DEFAULT NULL, - `image_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `code_hidden` tinyint(1) DEFAULT NULL, - `task_pass` tinyint(1) DEFAULT NULL, - `exec_time` int(11) DEFAULT NULL, - `test_set_permission` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `sigle_training` tinyint(1) DEFAULT NULL, - `hide_code` tinyint(1) DEFAULT NULL, - `multi_webssh` tinyint(1) DEFAULT NULL, - `excute_time` int(11) DEFAULT NULL, - `averge_star` int(11) DEFAULT NULL, - `forbid_copy` int(11) DEFAULT NULL, - `created_at` datetime NOT NULL, - `updated_at` datetime NOT NULL, - `shixun_id` int(11) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `local_shixuns` --- - -LOCK TABLES `local_shixuns` WRITE; -/*!40000 ALTER TABLE `local_shixuns` DISABLE KEYS */; -INSERT INTO `local_shixuns` VALUES (1,'单链表的学习与应用(I)','链表(Linked List)是一种通用的数据结构,主要用于表示和管理数量不确定的数据。链表可有效解决数组(Array)在动态数据管理方面的不足。\r\n\r\n本实训项目的主要内容是基于Java语言开发一个具有基本功能的单链表,从六个方面介绍链表相关知识,并设置了六个关卡在线考察大家的链表编程能力。\r\n![](/attachments/download/169299)',2,NULL,1,0,NULL,NULL,'bifnvguo',NULL,1,NULL,0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,'#!/bin/bash\n#工作空间\ncd WORKSPACE\n#用户打开的文件名,之所以传过来这个,是因为可以从这个里面提取出来执行文件名\nchallengeProgramNames=(\"src/step1/ListNodeTest.java\" \"src/step2/ListNodeTest.java\" \"src/step3/LinkedListTest.java\" \"src/step4/LinkedListTest.java\" \"src/step5/LinkedListTest.java\" \"src/step6/LinkedListTest.java\")\n#执行文件名\nsourceClassNames=(\"step1.ListNodeTest\" \"step2.ListNodeTest\" \"step3.LinkedListTest\" \"step4.LinkedListTest\" \"step5.LinkedListTest\" \"step6.LinkedListTest\")\ninput=$2;OLD_IFS=\"$IFS\"; IFS=,; ins=($input);IFS=\"$OLD_IFS\"\n\n#限制每个shell连接所能写文件的最大容量,100M\necho \'ulimit -f 10000\' >>/root/.bashrc ; source /root/.bashrc\n\ncompile(){\n #编译命令,有的语言是没有编译过程,这个时候默认编译成功\n compileCommand=\"javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/\"\n #取当前关卡的编译文件\n challengeProgramName=${challengeProgramNames[$1 - 1]}\n #当前关卡,作为参数传进来\n challengeStage=$1\n #删除上一次编译生成的文件,防止对本次编译造成影响\n rm -f ./target/step$challengeStage/*.class &> /dev/null\n \n # 获取编译结果(此处编译无输出则说明编译通过,否则输出编译错误信息,请按实训实际情况调整)\n compileResult=$($compileCommand $challengeProgramName 2>&1 | base64)\n if [ -z \"$compileResult\" ]; then\n compileResult=$(echo -n \"compile successfully\" | base64)\n fi\n\n}\ncompile $1\n\n\nexecute(){\n #执行命令\n executeCommand=\"java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/\"\n #执行文件名\n sourceClassName=${sourceClassNames[$1 - 1]}\n challengeStage=$1\n \n output=\'\'\n i=0\n while [[ i -lt ${#ins[*]} ]]; do\n #执行,并拼接执行结果\n result=$(echo \"${ins[$i]}\" | base64 -d | $executeCommand $sourceClassName 2>&1 | base64)\n #拼接输出结果\n output=$output\\\"$result\\\",\n let i++\n done\n output=\"[${output%?}]\"\n}\n\nexecute $1\n\n#return result in json format\nreturnResult(){\n result=\"{\\\"compileResult\\\":\\\"$compileResult\\\",\\\"out\\\":$output}\"\n echo $result\n}\n#拼装成最终的json格式,echo输出得到最后结果\nreturnResult\n\n',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,'2019-05-07 08:40:18','2019-05-07 08:40:18',50),(2,'MySQL数据库编程开发实训(基础篇)','数据库(Database,DB)是一种建立在计算机存储设备上的,按照某种结构来组织、存储和管理数据的集合。数据库管理系统(Database Management System,DBMS)是对数据库进行访问,完成数据存储、检索、管理和处理的软件。\r\n\r\nMySQL是目前最流行的关系型DBMS,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL具有性能高、成本低、可靠性好、开放源码等特点,广泛应用于网站开发和移动应用开发,在科学研究中的应用也极其广泛。\r\n\r\n本项目将从数据库连接,数据库实例与数据表的创建,数据记录的查询、插入、删除与更新、数据库应用等几个方面进行介绍,结合流行的JDBC技术,共设置了七个关卡在线考察大家的数据库访问编程能力。后续大家可以通过进阶学习来了解和掌握更高级更复杂的用法。\r\n\r\n![](/attachments/download/169466)',2,NULL,1,0,NULL,NULL,'els2pthi',NULL,1,NULL,1,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,'#!/bin/bash\ncd WORKSPACE\n\nchallengeProgramNames=(\"src/step1/MySQLWithJDBCTest.java\" \"src/step2/CreateTableTest.java\" \"src/step3/QueryRecordTest.java\" \"src/step4/InsertTableTest.java\" \"src/step5/DeleteRecordTest.java\" \"src/step6/UpdateRecordTest.java\" \"src/step7/TransferTableTest.java\")\nsourceClassNames=(\"step1.MySQLWithJDBCTest\" \"step2.CreateTableTest\" \"step3.QueryRecordTest\" \"step4.InsertTableTest\" \"step5.DeleteRecordTest\" \"step6.UpdateRecordTest\" \"step7.TransferTableTest\")\ninput=$2;OLD_IFS=\"$IFS\"; IFS=,; ins=($input);IFS=\"$OLD_IFS\"\n\necho \'ulimit -f 10000\' >>/root/.bashrc ; source /root/.bashrc\n\ncompile(){\n compileCommand=\"javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/\"\n challengeProgramName=${challengeProgramNames[$1 - 1]}\n challengeStage=$1\n #remove the .class files that last time remains\n rm -f ./target/step$challengeStage/*.class &> /dev/null\n\n # 获取编译结果(此处编译无输出则说明编译通过,否则输出编译错误信息,请按实训实际情况调整)\n compileResult=$($compileCommand $challengeProgramName 2>&1 | base64)\n if [ -z \"$compileResult\" ]; then\n compileResult=$(echo -n \"compile successfully\" | base64)\n fi\n}\ncompile $1\n\n\nexecute(){\n executeCommand=\"java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/\"\n sourceClassName=${sourceClassNames[$1 - 1]}\n challengeStage=$1\n \n #get the loop times(looptimes = the num of testdataset)\n output=\'\'\n i=0\n while [[ i -lt ${#ins[*]} ]]; do\n #执行,并拼接执行结果\n result=$(echo \"${ins[$i]}\" | base64 -d | $executeCommand $sourceClassName 2>&1 | base64)\n #拼接输出结果\n output=$output\\\"$result\\\",\n let i++\n done\n output=\"[${output%?}]\"\n}\n\nexecute $1\n\n#return result in json format\nreturnResult(){\n result=\"{\\\"compileResult\\\":\\\"$compileResult\\\",\\\"out\\\":$output}\"\n echo $result\n}\n#拼装成最终的json格式,echo输出得到最后结果\nreturnResult\n\n',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,'2019-05-07 08:40:18','2019-05-07 08:40:18',41); -/*!40000 ALTER TABLE `local_shixuns` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2019-05-07 8:57:56 diff --git a/localmysql.sh b/localmysql.sh deleted file mode 100644 index 15c5577a..00000000 --- a/localmysql.sh +++ /dev/null @@ -1,3 +0,0 @@ -mysql -uroot -p1234; -use 20180311; -source local_shixuns.sql \ No newline at end of file From 593ee71e79f76235d209631fe10ed86e22e061e5 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 7 May 2019 10:55:18 +0800 Subject: [PATCH 4/8] .. --- app/controllers/welcome_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index e727d92b..44d4fb12 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -150,12 +150,15 @@ class WelcomeController < ApplicationController shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) local_git_path = local_shixun.local_giturl.split('/').last if local_shixun.local_giturl.present? new_giturl = "http://educoder:xinhu1ji2qu3@"+g.project(shixun.gpid).http_url_to_repo.split('//').last - system("cd tmp/repositories/#{local_git_path}") - system("git remote remove origin") - system("git remote add origin #{new_giturl}") - system("git add .") - system("git commit -m '..'") - system("git push origin master") + if system("cd tmp/repositories/#{local_git_path};") + system("git remote remove origin") + system("git remote add origin #{new_giturl}") + system("git add .") + system("git commit -m '..'") + system("git push origin master") + end + + # http://Hjqreturn:xinhu1ji2qu3@bdgit.educoder.net/Hjqreturn/pgfqe6ch8.git (fetch) # 同步关卡信息 local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id) From e3af858ecc249f2932b8441b1389a1bc3daa5547 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 7 May 2019 11:00:39 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E7=BA=BF=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 44d4fb12..91cba4ab 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -150,13 +150,8 @@ class WelcomeController < ApplicationController shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) local_git_path = local_shixun.local_giturl.split('/').last if local_shixun.local_giturl.present? new_giturl = "http://educoder:xinhu1ji2qu3@"+g.project(shixun.gpid).http_url_to_repo.split('//').last - if system("cd tmp/repositories/#{local_git_path};") - system("git remote remove origin") - system("git remote add origin #{new_giturl}") - system("git add .") - system("git commit -m '..'") - system("git push origin master") - end + system("cd tmp/repositories/#{local_git_path};git remote remove origin;git remote add origin #{new_giturl}; + git add .;git commit -m '..';git push origin master") # http://Hjqreturn:xinhu1ji2qu3@bdgit.educoder.net/Hjqreturn/pgfqe6ch8.git (fetch) From c71677710d47a9bd24a596f582172431c4566c65 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 7 May 2019 11:17:17 +0800 Subject: [PATCH 6/8] .. --- app/controllers/welcome_controller.rb | 7 +++++-- ...507031028_add_type_name_to_local_mirror_repositories.rb | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 91cba4ab..9ce1905f 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -59,7 +59,9 @@ class WelcomeController < ApplicationController # 同步镜像 if shixun.mirror_repositories.present? shixun.mirror_repositories.each do |mirror| - LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id) + # 本地版的mirror id和线上的可能不一样,所以按名字取,然后再存 + # local_mirror = MirrorRepository.where(type_name: mirror.type_name).first.try(:id) + LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id, type_name: mirror.type_name) end end @@ -124,7 +126,8 @@ class WelcomeController < ApplicationController local_mirrors = LocalMirrorRepository.where(local_shixun_id: local_shixun.id) if local_mirrors.present? local_mirrors.each do |local_mirror| - ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror.mirror_repository_id) + local_mirror_new = MirrorRepository.where(type_name: local_mirror.try(:type_name)).first + ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror_new.id) end end diff --git a/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb b/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb new file mode 100644 index 00000000..ce6ff3b3 --- /dev/null +++ b/db/migrate/20190507031028_add_type_name_to_local_mirror_repositories.rb @@ -0,0 +1,5 @@ +class AddTypeNameToLocalMirrorRepositories < ActiveRecord::Migration + def change + add_column :local_mirror_repositories, :type_name, :string + end +end From 5950eb66d6c84b4b7c9a0f5f5d6cce326c3ceef7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 7 May 2019 11:35:21 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 9ce1905f..4feaa3d0 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -153,8 +153,12 @@ class WelcomeController < ApplicationController shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) local_git_path = local_shixun.local_giturl.split('/').last if local_shixun.local_giturl.present? new_giturl = "http://educoder:xinhu1ji2qu3@"+g.project(shixun.gpid).http_url_to_repo.split('//').last - system("cd tmp/repositories/#{local_git_path};git remote remove origin;git remote add origin #{new_giturl}; + # 如果有目录才执行 + if system("cd tmp/repositories/#{local_git_path}") + system("cd tmp/repositories/#{local_git_path};git remote remove origin;git remote add origin #{new_giturl}; git add .;git commit -m '..';git push origin master") + end + # http://Hjqreturn:xinhu1ji2qu3@bdgit.educoder.net/Hjqreturn/pgfqe6ch8.git (fetch) From 745597348d340aa01b9b32f4d902bdfbd877f267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Tue, 7 May 2019 12:45:09 +0800 Subject: [PATCH 8/8] b --- app/views/common/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/common/index.html.erb b/app/views/common/index.html.erb index 0d7f90fd..d99476a6 100644 --- a/app/views/common/index.html.erb +++ b/app/views/common/index.html.erb @@ -1 +1 @@ -Educoder
\ No newline at end of file +Educoder
\ No newline at end of file