diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-01-23 00:16:19 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-01-23 00:16:19 -0500 |
commit | 855fbfb9599c9a95c2c9a4b6f614cedc9f4de440 (patch) | |
tree | 93746bc9844d7dce44668d14e719a4295eacb106 | |
parent | 8f46ad9061bd15012593ba1fdbdf21fa87b2e27d (diff) | |
download | GradeBook-855fbfb9599c9a95c2c9a4b6f614cedc9f4de440.tar.gz GradeBook-855fbfb9599c9a95c2c9a4b6f614cedc9f4de440.zip |
added GradeBook db creation files
Ignore-this: 7f9fcf4b49c34ddfc5706829e469b691
darcs-hash:20110123051619-067c0-5e8a1924785b0e591cb7bb4f26a48bd3fbfedf29.gz
-rwxr-xr-x | AddDummyUsers2db.tcl | 51 | ||||
-rwxr-xr-x | CreateCourseGradeBook.tcl | 7 | ||||
-rwxr-xr-x | csv2GradeBook.tcl | 64 |
3 files changed, 116 insertions, 6 deletions
diff --git a/AddDummyUsers2db.tcl b/AddDummyUsers2db.tcl new file mode 100755 index 0000000..07c1e58 --- /dev/null +++ b/AddDummyUsers2db.tcl @@ -0,0 +1,51 @@ +#!/bin/sh +# (C) 2011 by Eugeniy Mikhailov, <evgmik@gmail.com> +# vim:set ft=tcl: \ +exec tclsh "$0" "$@" + +package require sqlite3 +package require md5 + +set class [lindex $argv 0] +if { $class eq "" } { + set class dummy_class +} + +set dbfile $class + +sqlite3 db $dbfile + +proc dbg {msg {level 1}} { + if { $level <=2 } { + set fid [open log a+] + puts $fid $msg + close $fid + } +} + +proc htmlErrorMsg { msg } { + puts "<div class=\"errormsg\">error: $msg</div>" +} + +proc AddUserNonWeb { first_name last_name user_name password_hash {group_name {guest}} {id_number {}} {section_num {} } } { + set eval_str [concat INSERT INTO GradesTable (FirstName, LastName, UserName, PasswordHash, GroupName, IdNum, SectionNum) VALUES('$first_name', '$last_name', '$user_name', '$password_hash', '$group_name', '$id_number', '$section_num')] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + + +#AddUserNonWeb first_name last_name user_name password_hash group_name id_number section_num i +# dummy users +AddUserNonWeb Ins "Instruch I" instructor [::md5::md5 -hex qwerty] instructor +AddUserNonWeb Ta "Taevich, I" ta [::md5::md5 -hex qwerty] ta +AddUserNonWeb Dan "Dandanovich" dan [::md5::md5 -hex qwerty] student +AddUserNonWeb Ale "Alevna" ale [::md5::md5 -hex qwerty] student +AddUserNonWeb Jon "Jonovich" jon [::md5::md5 -hex qwerty] student +AddUserNonWeb Ale "Alevna" ale {} student + + + +# vim: ts=2 sw=2 foldmethod=indent: diff --git a/CreateCourseGradeBook.tcl b/CreateCourseGradeBook.tcl index c0ddf2c..491e2d0 100755 --- a/CreateCourseGradeBook.tcl +++ b/CreateCourseGradeBook.tcl @@ -48,12 +48,7 @@ proc CreateGradesTable {db} { AddUserNonWeb {} {} _Col_Category_ {} inforow AddUserNonWeb {} {} _Max_Points_ {} inforow - # dummy users - AddUserNonWeb Ta "Taevich, I" ta [::md5::md5 -hex qwerty] ta - AddUserNonWeb Dan "Dandanovich" dan [::md5::md5 -hex qwerty] student - AddUserNonWeb Ale "Alevna" ale [::md5::md5 -hex qwerty] student - AddUserNonWeb Jon "Jonovich" jon [::md5::md5 -hex qwerty] student - AddUserNonWeb Ins "Instruch I" instructor [::md5::md5 -hex qwerty] instructor + #AddUserNonWeb Ins "Instruch I" instructor [::md5::md5 -hex qwerty] instructor # reasonable defaults for hidden columns set instructor_hidden_columns [list UserHiddenColums PasswordHash UserHiddenGroups IdNum] UpdateColValue4GroupNameNonWeb UserHiddenColums instructor $instructor_hidden_columns diff --git a/csv2GradeBook.tcl b/csv2GradeBook.tcl new file mode 100755 index 0000000..4fadb07 --- /dev/null +++ b/csv2GradeBook.tcl @@ -0,0 +1,64 @@ +#!/bin/sh +# (C) 2011 by Eugeniy Mikhailov, <evgmik@gmail.com> +# vim:set ft=tcl: \ +exec tclsh "$0" "$@" + +package require sqlite3 +package require md5 + +set class [lindex $argv 0] +if { $class eq "" } { + set class dummy_class +} + +set csvfile [lindex $argv 1] + +set dbfile $class + +sqlite3 db $dbfile + +proc dbg {msg {level 1}} { + if { $level <=2 } { + set fid [open log a+] + puts $fid $msg + close $fid + } +} + +proc htmlErrorMsg { msg } { + puts "<div class=\"errormsg\">error: $msg</div>" +} + +proc AddUserNonWeb { first_name last_name user_name password_hash {group_name {guest}} {id_number {}} {section_num {} } } { + set eval_str [concat INSERT INTO GradesTable (FirstName, LastName, UserName, PasswordHash, GroupName, IdNum, SectionNum) VALUES('$first_name', '$last_name', '$user_name', '$password_hash', '$group_name', '$id_number', '$section_num')] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + + +#AddUserNonWeb first_name last_name user_name password_hash group_name id_number section_num i +# dummy users + +# expect the csv file with following fields +# sid, FName, LName, Section, email + +set fp [open $csvfile r] +while {-1 != [gets $fp line]} { + #puts "The current line is '$line'." + set data [split $line ,] + set id [lindex $data 0] + set fname [lindex $data 1] + set lname [lindex $data 2] + set sect [lindex $data 3] + set email [lindex $data 4] + #puts "$fname $lname $email {} student $id $sect" + AddUserNonWeb $fname $lname $email {} student $id $sect +} + + + + +# vim: ts=2 sw=2 foldmethod=indent: |