diff --git a/README.md b/README.md index 9d2be23..e48131c 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,29 @@ 因为是众多工具的集合,懒人福音,故取名为`lan`,意为`懒`。 +## 更新日志 + +### 2023.2.26 + +- `time`命令更名为`valid`命令,新增`SourceSizeLimit`参数,在检查时间戳的基础上追加代码文件大小检查 +- 更新`demo` + +### 2022.11.5 + +- 新增`已知缺席考生`特性,优化`clean`命令的结果描述 +- 新增`gen`命令,原先`config`命令移至到`gen`的子命令下,同时新增`countdown`和`share`子命令,用于生成`倒计时html模板`和`打开共享文件夹源代码`文件 +- 修复了重复执行`md5`命令时,输出文件内容异常的情况 +- 更新`demo` + +### 2022.10.28 + +- 修复了`moss`命令时相对路径解析错误的问题 +- 修改了`md5`命令默认保存文件名 + +### 2022.10.15 + +- v0.1版发布 + ## 流程 1. 召集考点负责人开会,各考点确定学校和试室的缩写,方便后面汇总。 @@ -104,8 +127,8 @@ chmod +x lan ./lan check # 生成md5码文件,并下发 ./lan md5 -# 检查文件修改时间 -./lan time +# 检查文件修改时间和文件大小 +./lan valid # 查重 ./lan moss ``` @@ -193,10 +216,10 @@ Md5File : md5文件名,非必要不更改 该操作会将`CodePath`的所有文件生成一份`md5`表单,配合[checker](https://github.com/xfoxfu/checker)使用, -### 修改时间检查 +### 修改时间和文件大小检查 ```bash -./lan time +./lan valid ``` 配置说明: @@ -205,10 +228,11 @@ Md5File : md5文件名,非必要不更改 CodePath : 待检查的文件夹路径 StartTime : 比赛开始时间 EndTime : 比赛结束时间 +SourceSizeLimit : 文件最大大小(单位:byte) AbnormalLog : 修改时间异常的学生清单 ``` -该操作会将`CodePath`的所有修改时间不在比赛时间内的文件列一份清单,保存在`AbnormalLog`中。 +该操作会将`CodePath`的所有修改时间不在比赛时间内以及大小超出限制的文件列一份清单,保存在`AbnormalLog`中。 ### 查重 @@ -241,7 +265,7 @@ ReviewNumberResult : 显示的结果数 ./lan clean 304 raw_304 --problems=expr,live,number,power --extensions=.cpp,.c,.pas --ignoreexts=.txt,.in,.out,.ans,.pdf,.exe ./lan check 304 --room=304 --namelist=namelist.csv ./lan md5 304 -./lan time 304 --starttime="2021-11-20 08:30:00" --endtime="2021-11-17 13:00:00" +./lan valid 304 --starttime="2021-11-20 08:30:00" --endtime="2021-11-17 13:00:00" --sizelimit=102400 ./lan moss 304 --problem=expr --language=cc --maxlimit=10 --numberresult=250 --userid=xxxx ``` diff --git a/cmd/config.go b/cmd/config.go index 8cea49a..8a1afc0 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -20,9 +20,10 @@ CodePath = "304" Room = "304" NameList = "namelist.csv" -# use in time command +# use in valid command StartTime = "2021-11-17 08:30:00" EndTime = "2021-11-17 13:00:00" +SourceSizeLimit = 102400 # byte # use in clean command SourcePath = "raw_304" diff --git a/cmd/md5_test.go b/cmd/md5_test.go index 07fc006..25d1013 100644 --- a/cmd/md5_test.go +++ b/cmd/md5_test.go @@ -38,7 +38,7 @@ func Test_md5Command(t *testing.T) { args: []string{"md5", codePath}, err: nil, wantFile: "checker.hash", - md5: "3176a9c52bbba19dbc113b59067e9e82", + md5: "c7d36d0efb61c31c8372c24ab8464af8", want: `GD-00018,expr,06c81b60f732b5e676f5094c9574d6eb GD-00018,live,13a0063b0e624ca25f6aaec813ef9bb6 GD-00018,number,c5b8cdc8deabd20422a3762c1ee855d2 @@ -53,7 +53,7 @@ GD-00129,expr,6a8e5c7a4c0eb6197d2de77a8f663d89 GD-00129,live,abcbb58bf383db2954ca669288cbed0a GD-00129,number,ae2cd346028e80ea22de88d711e47ee7 GD-00129,power,3828e142aaa229ab94a711d510cbe6a2 -GD-00139,expr,b5f9dc19c1e093d35c31ab0002cab3b5 +GD-00139,expr,4d28fd9af924b970ba4739fdc2175f96 GD-00139,live,1c0a55027ce93cb3d4db976b740e50b8 GD-00139,number,2e30638f33f913145e4e129eac238163 GD-00139,power,6a733844e618c38f366f9a149a6c68a0 @@ -65,7 +65,7 @@ GD-00139,power,6a733844e618c38f366f9a149a6c68a0 err: nil, md5File: "qwq.hash", wantFile: "qwq.hash", - md5: "3176a9c52bbba19dbc113b59067e9e82", + md5: "c7d36d0efb61c31c8372c24ab8464af8", want: `GD-00018,expr,06c81b60f732b5e676f5094c9574d6eb GD-00018,live,13a0063b0e624ca25f6aaec813ef9bb6 GD-00018,number,c5b8cdc8deabd20422a3762c1ee855d2 @@ -80,7 +80,7 @@ GD-00129,expr,6a8e5c7a4c0eb6197d2de77a8f663d89 GD-00129,live,abcbb58bf383db2954ca669288cbed0a GD-00129,number,ae2cd346028e80ea22de88d711e47ee7 GD-00129,power,3828e142aaa229ab94a711d510cbe6a2 -GD-00139,expr,b5f9dc19c1e093d35c31ab0002cab3b5 +GD-00139,expr,4d28fd9af924b970ba4739fdc2175f96 GD-00139,live,1c0a55027ce93cb3d4db976b740e50b8 GD-00139,number,2e30638f33f913145e4e129eac238163 GD-00139,power,6a733844e618c38f366f9a149a6c68a0 diff --git a/cmd/time.go b/cmd/valid.go similarity index 68% rename from cmd/time.go rename to cmd/valid.go index 24de286..9ae6d7b 100644 --- a/cmd/time.go +++ b/cmd/valid.go @@ -19,12 +19,13 @@ import ( ) var ( - startTimeStr string - endTimeStr string - abnormalLog string - startTime time.Time - endTime time.Time - abnormalList []Data + startTimeStr string + endTimeStr string + abnormalLog string + sourceSizeLimit int64 + startTime time.Time + endTime time.Time + abnormalList []Data ) func visit(path string, info fs.DirEntry, err error) error { @@ -45,7 +46,7 @@ func visit(path string, info fs.DirEntry, err error) error { } else { log.WithField("path", path).Debug(fileInfo.ModTime().Format(TimeTemplate)) - if fileInfo.ModTime().Before(startTime) || fileInfo.ModTime().After(endTime) { + if fileInfo.ModTime().Before(startTime) || fileInfo.ModTime().After(endTime) || fileInfo.Size() > sourceSizeLimit { abnor, err := ResolvePath(path[codePathLen+1:]) if err != nil { log.Error(err) @@ -53,6 +54,7 @@ func visit(path string, info fs.DirEntry, err error) error { } abnor.ModifyTime = fileInfo.ModTime() + abnor.Size = fileInfo.Size() log.Warn(abnor.String()) abnormalList = append(abnormalList, abnor) } @@ -60,11 +62,11 @@ func visit(path string, info fs.DirEntry, err error) error { return nil } -// timeCmd represents the time command -var timeCmd = &cobra.Command{ - Use: "time ", - Short: "Check modify time of code", - Long: `Check whether the modify time of code is in the competition during.`, +// validCmd represents the time command +var validCmd = &cobra.Command{ + Use: "valid ", + Short: "Check modify time and size of code", + Long: `Check whether the modify of code is in the competition during and the size of code is in limit.`, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { codePath = viper.GetString("CodePath") @@ -82,10 +84,12 @@ var timeCmd = &cobra.Command{ viper.BindPFlag("StartTime", cmd.Flags().Lookup("starttime")) viper.BindPFlag("EndTime", cmd.Flags().Lookup("endtime")) viper.BindPFlag("AbnormalLog", cmd.Flags().Lookup("abnormallog")) + viper.BindPFlag("SourceSizeLimit", cmd.Flags().Lookup("sizelimit")) startTimeStr = viper.GetString("StartTime") endTimeStr = viper.GetString("EndTime") abnormalLog = viper.GetString("AbnormalLog") + sourceSizeLimit = viper.GetInt64("SourceSizeLimit") loc, err := time.LoadLocation("Asia/Shanghai") if err != nil { @@ -101,6 +105,7 @@ var timeCmd = &cobra.Command{ log.Info("StartTime: ", startTime.Format(TimeTemplate)) log.Info("EndTime: ", endTime.Format(TimeTemplate)) log.Info("AbnormalLog: ", abnormalLog) + log.Info("SourceSizeLimit: ", sourceSizeLimit) }, Run: func(cmd *cobra.Command, args []string) { abnormalList = []Data{} @@ -120,9 +125,10 @@ var timeCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(timeCmd) + rootCmd.AddCommand(validCmd) - timeCmd.Flags().StringVarP(&startTimeStr, "starttime", "s", "0000-00-00 00:00:00", "Start Time of competition") - timeCmd.Flags().StringVarP(&endTimeStr, "endtime", "e", "9999-12-31 23:59:59", "End Time of competition") - timeCmd.Flags().StringVarP(&abnormalLog, "abnormallog", "a", "abnormal.log", "List of exception modification times") + validCmd.Flags().StringVarP(&startTimeStr, "starttime", "s", "0000-00-00 00:00:00", "Start Time of competition") + validCmd.Flags().StringVarP(&endTimeStr, "endtime", "e", "9999-12-31 23:59:59", "End Time of competition") + validCmd.Flags().Int64Var(&sourceSizeLimit, "sizelimit", 1024 * 100, "Source Code size limit") + validCmd.Flags().StringVarP(&abnormalLog, "abnormallog", "a", "abnormal.log", "List of exception modification times") } diff --git a/cmd/time_test.go b/cmd/valid_test.go similarity index 86% rename from cmd/time_test.go rename to cmd/valid_test.go index d501003..952b78b 100644 --- a/cmd/time_test.go +++ b/cmd/valid_test.go @@ -13,7 +13,7 @@ import ( "github.com/matryer/is" ) -func Test_timeCommand(t *testing.T) { +func Test_validCommand(t *testing.T) { is := is.New(t) codePath = filepath.Join(testPath, "clean_304") @@ -29,27 +29,27 @@ func Test_timeCommand(t *testing.T) { }{ { name: "case 1", - args: []string{"time"}, + args: []string{"valid"}, err: errors.New("Requires args of Code Path"), }, { name: "case 2", - args: []string{"time", codePath}, + args: []string{"valid", codePath}, err: nil, startTimeStr: "2021-11-17 08:30:00", endTimeStr: "2021-11-17 13:00:00", - abnormalNumber: 1, + abnormalNumber: 2, want: "abnormal.log", }, { name: "case 3", - args: []string{"time", codePath}, + args: []string{"valid", codePath}, err: nil, startTimeStr: "2021-11-17 08:30:00", endTimeStr: "2021-11-17 13:00:00", - abnormalNumber: 1, + abnormalNumber: 2, abnormalLog: "qwq.log", want: "qwq.log", }, diff --git a/utils/data.go b/utils/data.go index d1c5ef4..776c866 100644 --- a/utils/data.go +++ b/utils/data.go @@ -18,13 +18,14 @@ type Data struct { Extension string FileName string Md5 string + Size int64 ModifyTime time.Time } func (s *Data) String() string { - return fmt.Sprintf("[%s %s]: %s", s.Name, s.FileName, s.ModifyTime.Format(TimeTemplate)) + return fmt.Sprintf("[%s %s]: %s %.2fkb", s.Name, s.FileName, s.ModifyTime.Format(TimeTemplate), float64(s.Size) / 1024) } func (s *Data) Output() string { - return fmt.Sprintf("%s的%s修改时间为%s;", s.Name, s.FileName, s.ModifyTime.Format(TimeTemplate)) + return fmt.Sprintf("%s的%s修改时间为%s,大小为%.2fkb;", s.Name, s.FileName, s.ModifyTime.Format(TimeTemplate), float64(s.Size) / 1024) }