[31427] trunk/base/portmgr/jobs/PortIndex2MySQL.tcl

jmpp at macports.org jmpp at macports.org
Thu Nov 22 16:29:21 PST 2007


Revision: 31427
          http://trac.macosforge.org/projects/macports/changeset/31427
Author:   jmpp at macports.org
Date:     2007-11-22 16:29:20 -0800 (Thu, 22 Nov 2007)

Log Message:
-----------

 * Rework the script to execute less expensive stuff first and thus bail out early with minimal fuss if needed;
 * Resort to puts(n) rather than ui_error for error reporting before we initialize macports1.0 through mportinit;
 * Catch around the sourcing and loading of the macports1.0 files & Tcl package, report error if needed;
 * Provide an absolute example path for the password file;
 * Do not use 'IF NOT EXISTS' when creating the log table if we are dropping it right before: if the table creation instruction fails, we might want to know about it;

Modified Paths:
--------------
    trunk/base/portmgr/jobs/PortIndex2MySQL.tcl

Modified: trunk/base/portmgr/jobs/PortIndex2MySQL.tcl
===================================================================
--- trunk/base/portmgr/jobs/PortIndex2MySQL.tcl	2007-11-22 22:53:37 UTC (rev 31426)
+++ trunk/base/portmgr/jobs/PortIndex2MySQL.tcl	2007-11-23 00:29:20 UTC (rev 31427)
@@ -58,12 +58,6 @@
 #####
 
 
-# Load macports1.0 so that we can use some of its procs and the portinfo array.
-catch {source \
-    [file join "@TCL_PACKAGE_DIR@" macports1.0 macports_fastload.tcl]}
-package require macports
-
-
 # Runtime information log file and reciepient.
 set runlog "/tmp/portsdb.log"
 set runlog_fd [open $runlog w+]
@@ -73,6 +67,7 @@
 set subject "PortIndex2MySQL run failure on $DATE"
 set SPAM_LOVERS macports-dev at lists.macosforge.org
 
+
 # House keeping on exit.
 proc cleanup {args} {
     foreach file_to_clean $args {
@@ -96,6 +91,32 @@
 }
 
 
+# We first initialize the runlog with a proper mail subject.
+puts $runlog_fd "Subject: $subject"
+
+# Check if there are any stray sibling jobs before moving on, bail in such case.
+if {[file exists $lockfile]} {
+    puts $runlog_fd "PortIndex2MySQL lock file found, is another job running?" 
+    terminate 1
+} else {
+    set lockfile_fd [open $lockfile a]
+}
+
+
+# Load macports1.0 so that we can use some of its procs and the portinfo array.
+if {[catch { source [file join "@TCL_PACKAGE_DIR@" macports1.0 macports_fastload.tcl] } errstr]} {
+    puts $runlog_fd "${::errorInfo}"
+    puts $runlog_fd "Failed to locate the macports1.0 Tcl package file: $errstr"
+    cleanup lockfile
+    terminate 1
+}
+if {[catch { package require macports } errstr]} {
+    puts $runlog_fd "${::errorInfo}"
+    puts $runlog_fd "Failed to load the macports1.0 Tcl package: $errstr"
+    cleanup lockfile
+    terminate 1
+}
+
 # UI instantiation to route information/error messages wherever we want.
 proc ui_channels {priority} {
     global runlog_fd
@@ -130,40 +151,18 @@
     }
 }
 
-
-# We first initialize the runlog with a proper mail subject:
-puts $runlog_fd "Subject: $subject"
-
-# Check if there are any stray sibling jobs before moving on, bail in such case.
-if {[file exists $lockfile]} {
-    ui_error "PortIndex2MySQL lock file found, is another job running?"
-    terminate 1
-} else {
-    set lockfile_fd [open $lockfile a]
-}
-
-
 # Initialize macports1.0 and its UI, in order to find the sources.conf file
 # (which is what will point us to the PortIndex we're gonna use) and use
 # the runtime information.
 array set ui_options {ports_verbose yes}
 if {[catch {mportinit ui_options} errstr]} {
-    ui_error "${::errorInfo}"
-    ui_error "Failed to initialize MacPorts, $errstr"
+    puts $runlog_fd "${::errorInfo}"
+    puts $runlog_fd "Failed to initialize MacPorts: $errstr"
     cleanup lockfile
     terminate 1
 }
 
-# Call the selfupdate procedure to make sure the MacPorts installation
-# is up-to-date and with a fresh ports tree.
-if {[catch {macports::selfupdate} errstr]} {
-    ui_error "${::errorInfo}"
-    ui_error "Failed to update the ports tree, $errstr"
-    cleanup lockfile
-    terminate 1
-}
 
-
 # Procedure to catch the database password from a protected file.
 proc getpasswd {passwdfile} {
     if {[catch {open $passwdfile r} passwdfile_fd]} {
@@ -188,11 +187,10 @@
 set dbcmd [macports::findBinary mysql5]
 set dbhost localhost
 set dbuser macports
-set passwdfile "./password_file"
+set passwdfile "/opt/local/share/macports/resources/portmgr/password_file"
 set dbpasswd [getpasswd $passwdfile]
 set dbname macports
 
-
 # Flat text file to which sql statements are written.
 if {[catch {open $sqlfile w+} sqlfile_fd]} {
     ui_error "${::errorCode}: $sqlfile_fd"
@@ -200,6 +198,25 @@
     terminate 1
 }
 
+
+# Call the selfupdate procedure to make sure the MacPorts installation
+# is up-to-date and with a fresh ports tree.
+if {[catch {macports::selfupdate} errstr]} {
+    ui_error "${::errorInfo}"
+    ui_error "Failed to update the ports tree, $errstr"
+    cleanup lockfile
+    terminate 1
+}
+
+# Load every port in the index through a search that matches everything.
+if {[catch {set ports [mportsearch ".+"]} errstr]} {
+    ui_error "${::errorInfo}"
+    ui_error "port search failed: $errstr"
+    cleanup sqlfile lockfile
+    terminate 1
+}
+
+
 # SQL string escaping.
 proc sql_escape {str} {
     regsub -all -- {'} $str {\\'} str
@@ -211,7 +228,7 @@
 # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
 # Do we need any other?
 puts $sqlfile_fd "DROP TABLE IF EXISTS log;"
-puts $sqlfile_fd "CREATE TABLE IF NOT EXISTS log (activity VARCHAR(255), activity_time TIMESTAMP(14));"
+puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP(14));"
 puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW());"
 
 puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;"
@@ -233,14 +250,6 @@
 puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255));"
 
 
-# Load every port in the index through a search that matches everything.
-if {[catch {set ports [mportsearch ".+"]} errstr]} {
-    ui_error "${::errorInfo}"
-    ui_error "port search failed: $errstr"
-    cleanup sqlfile lockfile
-    terminate 1
-}
-
 # Iterate over each matching port, extracting its information from the
 # portinfo array.
 foreach {name array} $ports {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20071122/d86802c4/attachment.html


More information about the macports-changes mailing list