[102688] users/larryv/base/src/macports1.0/macports_index.tcl
larryv at macports.org
larryv at macports.org
Wed Feb 6 15:40:06 PST 2013
Revision: 102688
https://trac.macports.org/changeset/102688
Author: larryv at macports.org
Date: 2013-02-06 15:40:06 -0800 (Wed, 06 Feb 2013)
Log Message:
-----------
[sandbox] macports_index.tcl: Change tabs to spaces.
Modified Paths:
--------------
users/larryv/base/src/macports1.0/macports_index.tcl
Modified: users/larryv/base/src/macports1.0/macports_index.tcl
===================================================================
--- users/larryv/base/src/macports1.0/macports_index.tcl 2013-02-06 22:30:37 UTC (rev 102687)
+++ users/larryv/base/src/macports1.0/macports_index.tcl 2013-02-06 23:40:06 UTC (rev 102688)
@@ -35,18 +35,19 @@
package provide macports_index 1.0
namespace eval macports::index {
- variable has_sqlite {}
+ variable has_sqlite {}
}
proc macports::index::init {} {
- global macports::index::has_sqlite macports::prefix
- if {$macports::index::has_sqlite == 1 ||
- [file exists ${macports::prefix}/lib/tclsqlite.dylib]} {
- load ${macports::prefix}/lib/tclsqlite.dylib Sqlite
- set macports::index::has_sqlite 1
- } else {
- return -code error "Sqlite must be installed to use a remote index. Use the tclsqlite port."
- }
+ global macports::index::has_sqlite macports::prefix
+ if {$macports::index::has_sqlite == 1 ||
+ [file exists ${macports::prefix}/lib/tclsqlite.dylib]
+ } then {
+ load ${macports::prefix}/lib/tclsqlite.dylib Sqlite
+ set macports::index::has_sqlite 1
+ } else {
+ return -code error "Sqlite must be installed to use a remote index. Use the tclsqlite port."
+ }
}
proc macports::index::get_path {source} {
@@ -71,98 +72,98 @@
# url - the url of the remote index to synchronize with
proc macports::index::sync {portdbpath url} {
- macports::index::init
+ macports::index::init
- set indexpath [macports::index::get_path $url]
- if {[catch {file mkdir $indexpath} result]} {
- return -code error "$indexpath could not be created: $result"
- }
+ set indexpath [macports::index::get_path $url]
+ if {[catch {file mkdir $indexpath} result]} {
+ return -code error "$indexpath could not be created: $result"
+ }
- set oldpath [pwd]
- cd $indexpath
-
- # We actually use http:// as the transport mechanism
- set url [regsub -- {^mports} $url {http}]
+ set oldpath [pwd]
+ cd $indexpath
- # If the database didn't exist, initialize it.
- # The schema is available on the server in the initialize.sql file.
- if {![file exists [file join $indexpath database.sqlite]]} {
- puts "Initializing portindex"
- exec curl --silent -O "$url/index/initialize.sql"
- # XXX detect curl failures
-
- set fd [open initialize.sql r]
- set sql {}
- while {[gets $fd line] >= 0} {
- append sql " $line\n"
- }
- close $fd
- # Database file has the name database.sqlite
- sqlite DB database.sqlite
- DB eval $sql
- DB eval "CREATE TABLE priv_data (keyword text, value int);"
- DB eval "INSERT INTO priv_data (keyword, value) VALUES ('last_index', 1);"
- DB eval "INSERT INTO priv_data (keyword, value) VALUES ('last_trans', 0);"
- DB close
- }
+ # We actually use http:// as the transport mechanism
+ set url [regsub -- {^mports} $url {http}]
- # Database file has the name database.sqlite
- sqlite DB database.sqlite
+ # If the database didn't exist, initialize it.
+ # The schema is available on the server in the initialize.sql file.
+ if {![file exists [file join $indexpath database.sqlite]]} {
+ puts "Initializing portindex"
+ exec curl --silent -O "$url/index/initialize.sql"
+ # XXX detect curl failures
- ##
- # Download any new files
- ##
+ set fd [open initialize.sql r]
+ set sql {}
+ while {[gets $fd line] >= 0} {
+ append sql " $line\n"
+ }
+ close $fd
+ # Database file has the name database.sqlite
+ sqlite DB database.sqlite
+ DB eval $sql
+ DB eval "CREATE TABLE priv_data (keyword text, value int);"
+ DB eval "INSERT INTO priv_data (keyword, value) VALUES ('last_index', 1);"
+ DB eval "INSERT INTO priv_data (keyword, value) VALUES ('last_trans', 0);"
+ DB close
+ }
- # Get the last downloaded file index out of the database.
- set start_index [DB eval "SELECT value FROM priv_data WHERE keyword='last_index';"]
+ # Database file has the name database.sqlite
+ sqlite DB database.sqlite
- # Get the current high-water mark from the server.
- exec curl --silent -O "$url/index/.last_index"
- # XXX detect curl failures
- set fd [open ".last_index" r]
- gets $fd last_index
- # XXX should validate the contents of $last_index
- close $fd
- # Re-fetch the last file we fetched (transactions may have
- # been appended to it) and any new files.
- for {set i $start_index} {$i <= $last_index} {incr i} {
- puts "Fetching portindex-$i"
- exec curl --silent -O "$url/index/portindex-$i.sql"
- # XXX detect curl failures
- DB eval "UPDATE priv_data SET value=$i WHERE keyword='last_index';\n"
- }
+ ##
+ # Download any new files
+ ##
- ##
- # Replay the transactions
- ##
+ # Get the last downloaded file index out of the database.
+ set start_index [DB eval "SELECT value FROM priv_data WHERE keyword='last_index';"]
- # Get the last transaction ID out of the database.
- set last_trans [DB eval "SELECT value FROM priv_data WHERE keyword='last_trans';"]
+ # Get the current high-water mark from the server.
+ exec curl --silent -O "$url/index/.last_index"
+ # XXX detect curl failures
+ set fd [open ".last_index" r]
+ gets $fd last_index
+ # XXX should validate the contents of $last_index
+ close $fd
+ # Re-fetch the last file we fetched (transactions may have
+ # been appended to it) and any new files.
+ for {set i $start_index} {$i <= $last_index} {incr i} {
+ puts "Fetching portindex-$i"
+ exec curl --silent -O "$url/index/portindex-$i.sql"
+ # XXX detect curl failures
+ DB eval "UPDATE priv_data SET value=$i WHERE keyword='last_index';\n"
+ }
- # Iterate through the files we just downloaded
- for {set i $start_index} {$i <= $last_index} {incr i} {
- puts "Processing portindex-$i"
- set fd [open "portindex-$i.sql" r]
- set sql {}
- while {[gets $fd line] >= 0} {
- append sql " $line\n"
- if {[regexp -- {^-- END TRANSACTION #([0-9]+)} $line unused trans_id] == 1} {
- # If this is a transaction we have not seen before, commit it.
- # Also update the last transaction number.
- if {$trans_id > $last_trans} {
- set last_trans $trans_id
- append sql " UPDATE priv_data SET value=$last_trans WHERE keyword='last_trans';\n"
- DB eval $sql
- }
- set sql {}
- }
- }
- close $fd
- }
+ ##
+ # Replay the transactions
+ ##
- # Clean Up
- DB close
- cd $oldpath
+ # Get the last transaction ID out of the database.
+ set last_trans [DB eval "SELECT value FROM priv_data WHERE keyword='last_trans';"]
+
+ # Iterate through the files we just downloaded
+ for {set i $start_index} {$i <= $last_index} {incr i} {
+ puts "Processing portindex-$i"
+ set fd [open "portindex-$i.sql" r]
+ set sql {}
+ while {[gets $fd line] >= 0} {
+ append sql " $line\n"
+ if {[regexp -- {^-- END TRANSACTION #([0-9]+)} $line unused trans_id] == 1} {
+ # If this is a transaction we have not seen before, commit it.
+ # Also update the last transaction number.
+ if {$trans_id > $last_trans} {
+ set last_trans $trans_id
+ append sql " UPDATE priv_data SET value=$last_trans WHERE keyword='last_trans';\n"
+ DB eval $sql
+ }
+ set sql {}
+ }
+ }
+ close $fd
+ }
+
+ # Clean Up
+ DB close
+ cd $oldpath
}
# macports::index::search
@@ -179,96 +180,96 @@
# url - the url of the remote index to search
#
# attrs - an array of the attributes to search for
-# currently only "name" is supported.
+# currently only "name" is supported.
proc macports::index::search {portdbpath url attrslist} {
- macports::index::init
- set indexpath [macports::index::get_path $url]
+ macports::index::init
+ set indexpath [macports::index::get_path $url]
- if {![file exists $indexpath/database.sqlite]} {
- return -code error "Can't open index file for source $url. Have you synced your source indexes (port sync)?"
- }
+ if {![file exists $indexpath/database.sqlite]} {
+ return -code error "Can't open index file for source $url. Have you synced your source indexes (port sync)?"
+ }
- sqlite DB $indexpath/database.sqlite
- # Map some functions into the SQL namespace
- DB function regexp regexp
-
- # The guts of the search logic.
- # Precedence is as follows:
- # - If a name, version, and revision is specified return that single port.
- # - If a name and version is specified, return the highest revision
- # - If only a name is specified, return the highest revision of
- # all distinct name, version combinations.
- # - NOTE: it is an error to specify a revision without a version.
+ sqlite DB $indexpath/database.sqlite
+ # Map some functions into the SQL namespace
+ DB function regexp regexp
- set pids [list]
- array set attrs $attrslist
- if {[info exists attrs(name)]} {
- set name $attrs(name)
+ # The guts of the search logic.
+ # Precedence is as follows:
+ # - If a name, version, and revision is specified return that single port.
+ # - If a name and version is specified, return the highest revision
+ # - If only a name is specified, return the highest revision of
+ # all distinct name, version combinations.
+ # - NOTE: it is an error to specify a revision without a version.
- # If version was not specified, find all distinct versions;
- # otherwise use the specified version.
- if {![info exists attrs(version)]} {
- set sql "SELECT version FROM ports WHERE regexp('--','$name',name) GROUP BY version ORDER BY version DESC"
- set versions [DB eval $sql]
- } else {
- set versions [list $attrs(version)]
- }
-
- # If revision was not specified, find the highest revision;
- # otherwise use the specified revision.
- if {![info exists attrs(revision)]} {
- foreach version $versions {
- set sql "SELECT max(revision) FROM ports WHERE regexp('--','$name',name) AND version LIKE '$version'"
- set revisions($version) [DB eval $sql]
- }
- } else {
- set revisions($version) $attrs(revision)
- }
-
- foreach version $versions {
- set sql "SELECT pid FROM ports WHERE regexp('--','$name',name) AND version LIKE '$version' AND revision LIKE '$revisions($version)'"
- lappend pids [DB eval $sql]
- }
- }
-
- # Historically mportsearch has returned a serialized list of arrays.
- # This is kinda gross and really needs to change to a more opaque
- # data type in the future, but to ease the transition we're it the old
- # way here. For each port that matched the query, build up an array
- # from the keywords table and append it to the list.
+ set pids [list]
+ array set attrs $attrslist
+ if {[info exists attrs(name)]} {
+ set name $attrs(name)
- set result [list]
+ # If version was not specified, find all distinct versions;
+ # otherwise use the specified version.
+ if {![info exists attrs(version)]} {
+ set sql "SELECT version FROM ports WHERE regexp('--','$name',name) GROUP BY version ORDER BY version DESC"
+ set versions [DB eval $sql]
+ } else {
+ set versions [list $attrs(version)]
+ }
- foreach pid $pids {
- set portinfo [list]
- set primary_key [DB eval "SELECT name,version,revision FROM ports WHERE pid=$pid"]
- set name [lindex $primary_key 0]
- set version [lindex $primary_key 1]
- set revision [lindex $primary_key 2]
- lappend portinfo name $name
- lappend portinfo version $version
- lappend portinfo revision $revision
-
- set auxiliary_keys [DB eval "SELECT keyword, value FROM keywords WHERE pid=$pid"]
- foreach {key value} $auxiliary_keys {
- # XXX - special case list types: categories, maintainers, master_sites
- lappend portinfo $key $value
- }
-
- # Craft a URL where the port can be found.
- lappend portinfo porturl $url/files/$name/$version/$revision/Portfile.tar.gz
-
- # Make a note of where this port came from.
- lappend portsource $url
-
- lappend result $name
- lappend result $portinfo
- }
+ # If revision was not specified, find the highest revision;
+ # otherwise use the specified revision.
+ if {![info exists attrs(revision)]} {
+ foreach version $versions {
+ set sql "SELECT max(revision) FROM ports WHERE regexp('--','$name',name) AND version LIKE '$version'"
+ set revisions($version) [DB eval $sql]
+ }
+ } else {
+ set revisions($version) $attrs(revision)
+ }
- DB close
+ foreach version $versions {
+ set sql "SELECT pid FROM ports WHERE regexp('--','$name',name) AND version LIKE '$version' AND revision LIKE '$revisions($version)'"
+ lappend pids [DB eval $sql]
+ }
+ }
- return $result
+ # Historically mportsearch has returned a serialized list of arrays.
+ # This is kinda gross and really needs to change to a more opaque
+ # data type in the future, but to ease the transition we're it the old
+ # way here. For each port that matched the query, build up an array
+ # from the keywords table and append it to the list.
+
+ set result [list]
+
+ foreach pid $pids {
+ set portinfo [list]
+ set primary_key [DB eval "SELECT name,version,revision FROM ports WHERE pid=$pid"]
+ set name [lindex $primary_key 0]
+ set version [lindex $primary_key 1]
+ set revision [lindex $primary_key 2]
+ lappend portinfo name $name
+ lappend portinfo version $version
+ lappend portinfo revision $revision
+
+ set auxiliary_keys [DB eval "SELECT keyword, value FROM keywords WHERE pid=$pid"]
+ foreach {key value} $auxiliary_keys {
+ # XXX - special case list types: categories, maintainers, master_sites
+ lappend portinfo $key $value
+ }
+
+ # Craft a URL where the port can be found.
+ lappend portinfo porturl $url/files/$name/$version/$revision/Portfile.tar.gz
+
+ # Make a note of where this port came from.
+ lappend portsource $url
+
+ lappend result $name
+ lappend result $portinfo
+ }
+
+ DB close
+
+ return $result
}
@@ -288,92 +289,92 @@
# get the source URL and the Portfile.tar.gz md5 from this opaque handle.
proc macports::index::fetch_port {url destdir} {
- global macports::sources
-
- set portsource ""
- set portname ""
- set portversion ""
- set portrevision ""
-
- # Iterate through the sources, to see which one this port is coming from.
- # If the port is not coming from a known source, return an error (for now).
-
- set indexpath ""
- set fetchpath ""
- foreach source $sources {
- if {[regexp -- "^$source" $url] == 1} {
- set portsource $source
- set indexpath [macports::index::get_path $source]
-
- # Extract the relative portion of the url,
- # and append it to the indexpath, this is where
- # we will store the cached Portfile.
- set dir [file dirname [regsub -- "$source/?" $url {}]]
+ global macports::sources
- # XXX: crude hack to get port name and version, should realy come from opaque port handle.
- set portname [lindex [file split $dir] 1]
- set portversion [lindex [file split $dir] 2]
- set portrevision [lindex [file split $dir] 3]
+ set portsource ""
+ set portname ""
+ set portversion ""
+ set portrevision ""
- set fetchpath [file join $indexpath $dir]
- break
- }
- }
-
- if {$indexpath == "" || $fetchpath == ""} {
- return -code error "Port URL has unknown source: $url"
- }
-
- if {[catch {file mkdir $fetchpath} result]} {
- return -code error $result
- }
+ # Iterate through the sources, to see which one this port is coming from.
+ # If the port is not coming from a known source, return an error (for now).
- # If the portdir already exists, we don't bother extracting again.
-
- # Look to see if the file exists in our cache, if it does, attempt
- # to extract it into the temporary directory that we will build in.
- # If it does not exist, or if the tar extraction fails, then attempt
- # to fetch it again.
+ set indexpath ""
+ set fetchpath ""
+ foreach source $sources {
+ if {[regexp -- "^$source" $url] == 1} {
+ set portsource $source
+ set indexpath [macports::index::get_path $source]
+ # Extract the relative portion of the url,
+ # and append it to the indexpath, this is where
+ # we will store the cached Portfile.
+ set dir [file dirname [regsub -- "$source/?" $url {}]]
- set portdir [file join "$destdir" "$portname-$portversion"]
+ # XXX: crude hack to get port name and version, should realy come from opaque port handle.
+ set portname [lindex [file split $dir] 1]
+ set portversion [lindex [file split $dir] 2]
+ set portrevision [lindex [file split $dir] 3]
- if {[file exists $portdir]} {
- return $portdir
- }
-
- if {[catch {file mkdir $portdir} result]} {
- return -code error $result
- }
+ set fetchpath [file join $indexpath $dir]
+ break
+ }
+ }
- set fetchfile [file join $fetchpath [file tail $url]]
- set retries 2
- while {$retries > 0} {
- if {[file exists $fetchfile]} {
- set oldcwd [pwd]
- cd $portdir
-
- if {[catch {exec tar -zxf $fetchfile} result]} {
- return -code error "Could not unpack port file: $result"
- }
-
- set fd [open ".mports_source" w]
- puts $fd "source: $portsource"
- puts $fd "port: $portname"
- puts $fd "version: $portversion"
- puts $fd "revision: $portrevision"
- close $fd
-
- cd $oldcwd
- } else {
- # We actually use http:// as the transport mechanism
- set http_url [regsub -- {^mports} $url {http}]
- if {[catch {exec curl -L -s -S -o $fetchfile $http_url} result ]} {
- return -code error "Could not download port from remote index: $result"
- }
- }
- incr retries -1
- }
-
- return $portdir
+ if {$indexpath == "" || $fetchpath == ""} {
+ return -code error "Port URL has unknown source: $url"
+ }
+
+ if {[catch {file mkdir $fetchpath} result]} {
+ return -code error $result
+ }
+
+ # If the portdir already exists, we don't bother extracting again.
+
+ # Look to see if the file exists in our cache, if it does, attempt
+ # to extract it into the temporary directory that we will build in.
+ # If it does not exist, or if the tar extraction fails, then attempt
+ # to fetch it again.
+
+
+ set portdir [file join "$destdir" "$portname-$portversion"]
+
+ if {[file exists $portdir]} {
+ return $portdir
+ }
+
+ if {[catch {file mkdir $portdir} result]} {
+ return -code error $result
+ }
+
+ set fetchfile [file join $fetchpath [file tail $url]]
+ set retries 2
+ while {$retries > 0} {
+ if {[file exists $fetchfile]} {
+ set oldcwd [pwd]
+ cd $portdir
+
+ if {[catch {exec tar -zxf $fetchfile} result]} {
+ return -code error "Could not unpack port file: $result"
+ }
+
+ set fd [open ".mports_source" w]
+ puts $fd "source: $portsource"
+ puts $fd "port: $portname"
+ puts $fd "version: $portversion"
+ puts $fd "revision: $portrevision"
+ close $fd
+
+ cd $oldcwd
+ } else {
+ # We actually use http:// as the transport mechanism
+ set http_url [regsub -- {^mports} $url {http}]
+ if {[catch {exec curl -L -s -S -o $fetchfile $http_url} result ]} {
+ return -code error "Could not download port from remote index: $result"
+ }
+ }
+ incr retries -1
+ }
+
+ return $portdir
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130206/459b44d8/attachment-0001.html>
More information about the macports-changes
mailing list