Can pass multiple students files (concatenate them)

This commit is contained in:
nemunaire 2021-09-24 09:54:25 +02:00
parent e9cc2e1331
commit e486ad0c1b
1 changed files with 27 additions and 9 deletions

36
main.go
View File

@ -205,11 +205,22 @@ func ServeJSONStudent(w http.ResponseWriter, r *http.Request) {
}
}
type arrayFlags []string
func (i *arrayFlags) String() string {
return fmt.Sprintf("%v", *i)
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func main() {
var studentsFile string
var studentsFiles arrayFlags
var bind = flag.String("bind", "0.0.0.0:8081", "Bind port/socket")
flag.StringVar(&studentsFile, "students", "./students.csv", "Path to a CSV file containing in the third column the name of the directory to look for")
flag.Var(&studentsFiles, "students", "Path to a CSV file containing in the third column the name of the directory to look for (can be repeated multiple times)")
flag.StringVar(&rendusDir, "path", "./rendu/", "Path to the submissions directory (each subdirectory is a project)")
flag.StringVar(&title, "title", "Rendus VIRLI", "Title of the page")
flag.Parse()
@ -234,14 +245,21 @@ func main() {
// Read and parse students list
log.Println("Reading students files...")
if studentsFile, err = filepath.Abs(studentsFile); err != nil {
log.Fatal(err)
} else if fi, err := os.Open(studentsFile); err != nil {
log.Fatal(err)
} else {
r := csv.NewReader(bufio.NewReader(fi))
if students, err = r.ReadAll(); err != nil {
for _, studentsFile := range studentsFiles {
log.Println("Reading", studentsFile, "...")
if studentsFile, err = filepath.Abs(studentsFile); err != nil {
log.Fatal(err)
} else if fi, err := os.Open(studentsFile); err != nil {
log.Fatal(err)
} else {
var nstudents [][]string
r := csv.NewReader(bufio.NewReader(fi))
if nstudents, err = r.ReadAll(); err != nil {
log.Fatal(err)
}
students = append(students, nstudents...)
}
}
log.Println(len(students), "students loaded.")