Index: CVSROOT/log-new.tcl =================================================================== RCS file: /usr/local/cvsroot/CVSROOT/log-new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ CVSROOT/log-new.tcl 9 Oct 2002 15:02:40 -0000 1.1 @@ -0,0 +1,234 @@ +#!/usr/bin/tclsh + +proc usage {} { + puts "log.tcl - a cvs commit logging script for OpenACS by Roberto Mello +Usage: log.tcl -e openacs_user -l logfile -d datasource -u db_user -f forum_name ?-s? + + -e OpenACS user's e-mail address that will own the post + -l File to append log to + -d AOLserver-style data source (e.g. ::mydb, localhost:5432:mydb) + -u Database user to connect as + -f Forum name to post to + -s Do not show cvs status (Not implemented) + +Report bugs to rmello@fslc.usu.edu" +} + + +package require nstcl-database +::nstcl::load_driver postgres +set dostatus 0 +# +# parse command line arguments +# there's probably a better way to do this in Tcl +# +set files [list] + +if { [llength $argv] > 12 } { + puts stderr "Wrong number of arguments." + puts [usage] + exit 1 +} + +for { set i 0 } { $i < [llength $argv] } { set i [expr $i + 2] } { + set arg [lindex $argv $i] + switch -- $arg { + "-e" { set email "[lindex $argv [expr $i + 1]]" } + "-u" { set user "[lindex $argv [expr $i + 1]]" } + "-l" { + set logfile [lindex $argv [expr $i + 1]] + global logfile + } + "-d" { set datasource [lindex $argv [expr $i + 1]] } + "-f" { set forum [lindex $argv [expr $i + 1]] } + "-s" { set dostatus 0 } + default { + if { [info exists donefiles] } { + puts stderr "Too many arguments!\n[usage]" + exit 1 + } else { + set donefiles 1 + set files [split $arg] + global donefiles + } + } + } + +} + +if { ![info exists email] || ![info exists logfile] || \ + ![info exists datasource] || ![info exists forum] || ![info exists user] } { + puts stderr "Missing required arguments.\n[usage]" + exit 1 +} + +# the first argument is the module location relative to $CVSROOT +# +set modulepath [lindex $files 0] +set files [lrange $files 1 end] + +#set mailcmd "| mail -s \"\[openacs-cvs\] $modulepath\"" + +# localtime will be a list with something like "Wed Aug 07 20:05:20 MDT 2002" +# +set localtime [join [clock format [clock seconds]]] +#set months [list null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec] + +# get a login name for the guy doing the commit.... +# +global env +set cvsroot $env(CVSROOT) + +if { [catch {set login $env(CVSUSER)} errmsg] } { + set login [exec "whoami"] +} + +# Pretty subject +if { [llength $files] > 1 } { + set pretty_files "files" +} else { + set pretty_files "file" +} + +set subject "$modulepath - $login ([llength $files] $pretty_files)" + +# open log file for appending +# +if { [ catch {open $logfile "a"} OUT ] } { + puts stderr "Could not open($logfile) !" + exit 1 +} + +# print out the log Header +# +puts $OUT "\n" +puts $OUT "****************************************\n"; +puts $OUT "Date:\t$localtime \n"; +puts $OUT "Author:\t$login\n\n"; + +append content " +
+Author:\t$login\n";
+
+# print the stuff from logmsg that comes in on stdin to the logfile
+# It comes in like this, and we want to  modified files and log message:
+#
+# Update of /cvsroot/foobar
+# In directory ny04.openforce.net:/tmp/cvs-serv22374
+#
+# Modified Files:
+#         bar ...
+#         shebang ...
+# Log Message:
+# oteuo foeuho
+# oetturte tnroeui
+#
+while { [gets stdin from_stdin] != -1 } {
+	if { [string equal -length 14 $from_stdin "Modified Files"] } {
+		append content "$from_stdin\n"
+
+		while { [gets stdin from_stdin] != -1 } {
+			if { ![string equal -length 11 $from_stdin "Log Message"] } {
+				append content "$from_stdin\n"
+			} else {
+				break 
+			}
+		}
+		# What we now have in from_stdin is 'Log Message:'
+		append content "$from_stdin\n"
+		while { [gets stdin from_stdin] != -1 } {
+			append content "$from_stdin\n"
+		}
+	} else {
+		append content "$from_stdin\n"
+	}
+}
+		
+puts $OUT "$from_stdin\n"
+
+# after log information, do an 'cvs -Qq status -v' on each file in the arguments.
+#
+if { $dostatus != 0 } {
+	foreach file $files {                                                                                                                                               
+		if { [string equal $file "-"] } {
+			puts $OUT "\[input file was '-'\]"
+			append content "\n\[input file was '-'\]"
+			break	
+		}
+		set RCS [exec "cvs" "-nQq" "status" "-v" "$file"]
+		puts $OUT $RCS
+		append content "\n$RCS"
+	}
+}
+append content "\n
" + +# enter this post into forums. If this is the first commit +# of the day, put it in a new thread. Otherwise, append to +# today's thread. +# +if { [catch { ::nstcl::configure_pool -default -immediately postgres main 1 $datasource $user } errmsg] } { + puts stderr "Could not connect to database: $errmsg" + exit 1 +} + +puts "Inserting to forum $forum" + +set user_id_sql " SELECT party_id + FROM parties + WHERE email = '$email'" +set forum_id_sql " SELECT forum_id + FROM forums_forums_enabled + WHERE name = '$forum'" + +if { [catch {::nstcl::db_string uid $user_id_sql} user_id] } { + puts stderr "Couldn't find user_id for '$email'" + exit 1 +} + +if { [catch {::nstcl::db_string fid $forum_id_sql} forum_id] } { + puts stderr "Couldn't find forum_id for '$forum'" + exit 1 +} + +set n_threads_sql " SELECT COUNT(*) + FROM forums_messages + WHERE forum_id = $forum_id + AND user_id = $user_id + AND to_date(posting_date, 'YYYY-MM-DD') = CURRENT_DATE" + +set n_threads_today [::nstcl::db_string nthreads $n_threads_sql] + +if { $n_threads_today > 0 } { + # One thread today already. + set parent_id_sql " SELECT message_id + FROM forums_messages + WHERE forum_id = $forum_id + AND user_id = $user_id + AND to_date(posting_date, 'YYYY-MM-DD') = CURRENT_DATE + AND parent_id IS NULL" + + set parent_id [::nstcl::db_string pid $parent_id_sql] + set message_sql "SELECT forums_message__new(NULL, 'forums_message', $forum_id, '[::nstcl::DoubleApos $subject]', '[::nstcl::DoubleApos $content]', 't', $user_id, now(), 'approved', $parent_id, now(), $user_id, '127.0.0.1', $forum_id)" + if { [catch {::nstcl::db_string mid $message_sql} message_id] } { + puts stderr "Could not insert reply in the database: $message_id" + exit 1 + } +} else { + # New thread + set message_sql "SELECT forums_message__new(NULL, 'forums_message', $forum_id, '[::nstcl::DoubleApos $subject]', '[::nstcl::DoubleApos $content]', 't', $user_id, now(), 'approved', NULL, now(), $user_id, '127.0.0.1', $forum_id)" + if { [catch {::nstcl::db_string mid $message_sql} message_id] } { + puts stderr "Could not insert new message in the database: $message_id" + exit 1 + } +} + +if { [catch {close $OUT} errmsg] } { + puts stderr "Write to $logfile failed" + exit 1 +} + + +## must exit cleanly +## +exit 0 + Index: CVSROOT/loginfo =================================================================== RCS file: /usr/local/cvsroot/CVSROOT/loginfo,v diff -u -r1.2 -r1.3 --- CVSROOT/loginfo 30 May 2002 19:10:14 -0000 1.2 +++ CVSROOT/loginfo 9 Oct 2002 15:02:40 -0000 1.3 @@ -25,3 +25,6 @@ # or #DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog ALL /cvsroot/CVSROOT/log.pl -f /cvsroot/CVSROOT/commitlog -m openacs-cvs-list@openacs.org %s + +# RBM: 2002-08-30: Add cvs-to-forums script invocation +ALL /cvsroot/CVSROOT/log-new.tcl -l /cvsroot/CVSROOT/commitlog -e cvs@openacs.org -d ::openacs.org-dev -u nsadmin -f "CVS Commits" %s