[28262] trunk/base/portmgr/PortIndex2MySQL.tcl

source_changes at macosforge.org source_changes at macosforge.org
Sun Aug 26 15:52:23 PDT 2007


Revision: 28262
          http://trac.macosforge.org/projects/macports/changeset/28262
Author:   jmpp at macports.org
Date:     2007-08-26 15:52:22 -0700 (Sun, 26 Aug 2007)

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

After a long time wihtout coming back to this, finally make the script work 100%!
(at least wrt populating the database ;-):

 * Remove the $dbcmdargs variable and pass each mysql arg separately to exec(n) at the end of the script,
   as the call doesn't work otherwise (without an eval in there at least);
 * semi-colon terminate each SQL statement written to the batch file (not too sure how the whole db populating
   thing was working without them!);
 * (sssshhhhhh! retab some tcl statements in the process);

This script is now operational and the only thing remaining to label it "production ready"
is some error catching and reporting, which I plan to implement through some macports1.0
UI initialization.

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

Modified: trunk/base/portmgr/PortIndex2MySQL.tcl
===================================================================
--- trunk/base/portmgr/PortIndex2MySQL.tcl	2007-08-26 21:25:25 UTC (rev 28261)
+++ trunk/base/portmgr/PortIndex2MySQL.tcl	2007-08-26 22:52:22 UTC (rev 28262)
@@ -82,11 +82,10 @@
 set sqlfile [file join /tmp ports.sql]
 set dbcmd [macports::findBinary mysql5]
 set dbhost 127.0.0.1
-set dbname macports
 set dbuser macports
 set passwdfile [file join . password_file]
 set dbpasswd [getpasswd $passwdfile]
-set dbcmdargs "-h $dbhost -u $dbuser -p$dbpasswd $dbname"
+set dbname macports
 
 # Flat text file to which sql statements are written.
 if {[catch {open $sqlfile w+} sqlfile_fd]} {
@@ -105,27 +104,27 @@
 
 # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
 # Do we need any other?
-puts $sqlfile_fd "DROP TABLE log"
-puts $sqlfile_fd "CREATE TABLE IF NOT EXISTS log (activity VARCHAR(255), activity_time TIMESTAMP(14))"
-puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW())"
+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 "INSERT INTO log VALUES ('update', NOW());"
 
-puts $sqlfile_fd "DROP TABLE portfiles"
-puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT)"
+puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;"
+puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT);"
 
-puts $sqlfile_fd "DROP TABLE IF EXISTS categories"
-puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER)"
+puts $sqlfile_fd "DROP TABLE IF EXISTS categories;"
+puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER);"
 
-puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers"
-puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER)"
+puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;"
+puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER);"
 
-puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies"
-puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255))"
+puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;"
+puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255));"
 
-puts $sqlfile_fd "DROP TABLE IF EXISTS variants"
-puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255))"
+puts $sqlfile_fd "DROP TABLE IF EXISTS variants;"
+puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255));"
 
-puts $sqlfile_fd "DROP TABLE IF EXISTS platforms"
-puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255))"
+puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;"
+puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255));"
 
 
 # Load every port in the index through a search matching everything.
@@ -189,45 +188,45 @@
 		set platforms ""
 	}
 
-	puts $sqlfile_fd "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description')"
+	puts $sqlfile_fd "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description');"
 
 	set primary 1
 	foreach category $categories {
-		set category [sql_escape $category]
-		puts $sqlfile_fd "INSERT INTO categories VALUES ('$portname', '$category', $primary)"
-		incr primary
+            set category [sql_escape $category]
+            puts $sqlfile_fd "INSERT INTO categories VALUES ('$portname', '$category', $primary);"
+            incr primary
 	}
 	
 	set primary 1
 	foreach maintainer $maintainers {
-		set maintainer [sql_escape $maintainer]
-		puts $sqlfile_fd "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary)"
-		incr primary
+            set maintainer [sql_escape $maintainer]
+            puts $sqlfile_fd "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary);"
+            incr primary
 	}
 
         foreach build_dep $depends_build {
             set build_dep [sql_escape $build_dep]
-            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$build_dep')"
+            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$build_dep');"
         }
 
 	foreach lib $depends_lib {
-		set lib [sql_escape $lib]
-		puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$lib')"
+            set lib [sql_escape $lib]
+            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$lib');"
 	}
 
         foreach run_dep $depends_run {
             set run_dep [sql_escape $run_dep]
-            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$run_dep')"
+            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$run_dep');"
         }
 
 	foreach variant $variants {
-		set variant [sql_escape $variant]
-		puts $sqlfile_fd "INSERT INTO variants VALUES ('$portname', '$variant')"
+            set variant [sql_escape $variant]
+            puts $sqlfile_fd "INSERT INTO variants VALUES ('$portname', '$variant');"
 	}
 
 	foreach platform $platforms {
-		set platform [sql_escape $platform]
-		puts $sqlfile_fd "INSERT INTO platforms VALUES ('$portname', '$platform')"
+            set platform [sql_escape $platform]
+            puts $sqlfile_fd "INSERT INTO platforms VALUES ('$portname', '$platform');"
 	}
 
 }
@@ -239,7 +238,7 @@
     ui_error "${::errorCode}: $errstr"
     exit 1
 }
-if {[catch {exec $dbcmd $dbcmdargs <@ $sqlfile_fd} errstr]} {
+if {[catch {exec -- $dbcmd --host=$dbhost --user=$dbuser --password=$dbpasswd --database=$dbname <@ $sqlfile_fd} errstr]} {
     ui_error "${::errorCode}: $errstr"
     exit 1
 }

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


More information about the macports-changes mailing list