Exemplo n.º 1
0
func deleteDept() {
	dept, err := model.LoadDept(dbconn.Host, dbconn.Port)
	if err != nil {
		panic(fmt.Sprintf("department does not exist %v", err))
	}

	dept.Delete()
	return
}
Exemplo n.º 2
0
func Serve(dbhost string, dbport string, key []byte, isTesting bool) {

	_dept, err := model.LoadDept(dbhost, dbport)
	if err != nil {
		panic(err)
	}
	dept = _dept

	capServer = caps.NewCryptCapServer("/caps/", key, key)
	capServer.HandleFunc(dataKey, dataHandler)
	capServer.HandleFunc(materialKey, materialHandler)
	capServer.HandleFunc(fetchCommentsKey, fetchCommentsHandler)
	capServer.HandleFunc(postCommentKey, postCommentHandler)
	capServer.HandleFunc(setHighlightKey, setHighlightHandler)
	capServer.HandleFunc(delHighlightKey, delHighlightHandler)
	capServer.HandleFunc(setScoreKey, setScoreHandler)

	http.HandleFunc("/caps/", util.ProtectHandler(capServer.CapHandler()))
	http.HandleFunc("/login", util.ProtectHandler(loginHandler))

	log.Printf("Starting server ...")
	if isTesting {
		// Simple sanity check for the user: look for the www/ directory.
		fi, err := os.Lstat("www")
		if err != nil {
			fmt.Printf("Could not find the ./www directory.\n")
			return
		}
		if !fi.IsDir() {
			fmt.Printf("Expected ./www to be a directory.\n")
			return
		}

		http.Handle("/", http.FileServer(http.Dir("www")))
		http.ListenAndServe(":8080", nil)
	} else {
		l, err := net.Listen("tcp", "127.0.0.1:9111")
		if err != nil {
			panic(err)
		}
		err = fcgi.Serve(l, http.DefaultServeMux)
		if err != nil {
			panic(err)
		}
	}
}
Exemplo n.º 3
0
func ImportCSV(dbhost, dbport, csvFile string) {
	f, err := os.Open(csvFile)
	if err != nil {
		log.Fatalf("Could not open %v\n%v\n", csvFile, err)
		os.Exit(1)
	}

	r := csv.NewReader(f)
	// These settings are needed to parse what the administration sends us.
	r.TrailingComma = true
	r.FieldsPerRecord = -1

	lines, err := r.ReadAll()
	if err != nil {
		log.Fatalf("Error parsing %v\n%v\n", csvFile, err)
		os.Exit(1)
	}

	if isHeaderOK(lines[0]) == false {
		log.Fatalf("Unexpected header row in %v", csvFile)
		os.Exit(1)
	}

	dept, err := model.LoadDept(dbhost, dbport)
	if err != nil {
		log.Fatalf("Could not load department.\n%v\n", err)
		os.Exit(1)
	}

	for _, row := range lines[1:] {
		app := rowToStruct(row)
		err = dept.NewApplication(app)
		if err != nil {
			log.Printf("Error creating application %v.\n%v\n", app, err)
		}
	}

	log.Printf("%v records in %v", len(lines), csvFile)
}
Exemplo n.º 4
0
var cmdNewDept = &Command{
	Run: func(args []string) {
		_, err := model.NewDept(dbconn.Host, dbconn.Port)
		if err != nil {
			panic(err)
		}
	},
	Short: "create a new, empty department",
}

var cmdNewReviewer = &Command{
	Short: "create a new reviewer account",
	Usage: `USERNAME PASSWORD "Full Name"`,
	Run: func(args []string) {
		dept, err := model.LoadDept(dbconn.Host, dbconn.Port)
		if err != nil {
			panic(err)
		}
		dept.NewReviewer(model.ReviewerId(args[0]), args[2], args[1])
		if err != nil {
			panic(err)
		}
	},
}

var cmdLoadApps = &Command{
	Short: "load applicant information",
	Usage: `DEPT_PATH`,
	Run: func(args []string) {
		src, err := ioutil.ReadFile(args[0])