source: branches/dp2mp-move/base/portmgr/packaging/PortIndex2MySQL.tcl @ 25426

Last change on this file since 25426 was 25426, checked in by jmpp@…, 13 years ago

This one too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1#!/usr/bin/env tclsh
2# PortIndex2MySQL.tcl
3# Kevin Van Vechten | kevin@opendarwin.org
4# 3-Oct-2002
5# $Id: PortIndex2MySQL.tcl 25426 2007-05-21 23:20:30Z jmpp@macports.org $
6#
7# Copyright (c) 2003 Apple Computer, Inc.
8# Copyright (c) 2002 Kevin Van Vechten.
9# All rights reserved.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
20#    may be used to endorse or promote products derived from this software
21#    without specific prior written permission.
22#
23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33# POSSIBILITY OF SUCH DAMAGE.
34
35
36catch {source \
37           [file join "@TCL_PACKAGE_DIR@" darwinports1.0 darwinports_fastload.tcl]}
38package require darwinports
39
40proc ui_prefix {priority} {
41        return ""
42}
43
44proc ui_channels {priority} {
45        return {}
46}
47
48# This should be a command line argument.
49# if true, use_db insructs the script to insert directly into a database
50# otherwise, sql statements will be printed to stdout.
51set use_db ""
52
53array set ui_options {}
54array set global_options {}
55array set global_variations {}
56dportinit ui_options global_options global_variations
57
58if {$use_db != ""} {
59    load @PREFIX@/lib/libmysqltcl.dylib
60    set db [mysqlconnect -user darwinports -password woot -db darwinports]
61} else {
62    set db ""
63}
64
65proc sql_exec {db sql} {
66    if {$db != ""} {
67        mysqlexec $db $sql
68    } else {
69        puts "${sql};"
70    }
71}
72
73proc sql_escape {str} {
74    global use_db
75    if {$use_db != ""} {
76        return [msyqlescape $str]
77    } else {
78        regsub -all -- {'} $str {\\'} str
79        regsub -all -- {"} $str {\\"} str
80        regsub -all -- {\n} $str {\\n} str
81        return $str
82    }
83}
84
85# CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL,
86#  path VARCHAR(255),
87#  version VARCHAR(255),
88#  description TEXT);
89
90# CREATE TABLE categories (portfile VARCHAR(255),
91#  category VARCHAR(255),
92#  primary INTEGER);
93
94# CREATE TABLE maintainers (portfile VARCHAR(255),
95#  maintainer VARCHAR(255),
96#  primary INTEGER);
97
98sql_exec $db "DROP TABLE log"
99sql_exec $db "CREATE TABLE IF NOT EXISTS log (activity VARCHAR(255), activity_time TIMESTAMP(14))"
100sql_exec $db "INSERT INTO log VALUES ('update', NOW())"
101
102sql_exec $db "DROP TABLE portfiles"
103sql_exec $db "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT)"
104
105sql_exec $db "DROP TABLE IF EXISTS categories"
106sql_exec $db "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER)"
107
108sql_exec $db "DROP TABLE IF EXISTS maintainers"
109sql_exec $db "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER)"
110
111sql_exec $db "DROP TABLE IF EXISTS dependencies"
112sql_exec $db "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255))"
113
114sql_exec $db "DROP TABLE IF EXISTS variants"
115sql_exec $db "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255))"
116
117sql_exec $db "DROP TABLE IF EXISTS platforms"
118sql_exec $db "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255))"
119
120if {[catch {set ports [dportsearch ".+"]} errstr]} {
121        puts "port search failed: $errstr"
122        exit 1
123}
124
125foreach {name array} $ports {
126        array unset portinfo
127        array set portinfo $array
128        set portname [sql_escape $portinfo(name)]
129        if {[info exists portinfo(version)]} {
130                set portversion [sql_escape $portinfo(version)]
131        } else {
132                set portversion ""
133        }
134        set portdir [sql_escape $portinfo(portdir)]
135        if {[info exists portinfo(description)]} {
136                set description [sql_escape $portinfo(description)]
137        } else {
138                set description ""
139        }
140        if {[info exists portinfo(categories)]} {
141                set categories $portinfo(categories)
142        } else {
143                set categories ""
144        }
145        if {[info exists portinfo(maintainers)]} {
146                set maintainers $portinfo(maintainers)
147        } else {
148                set maintainers ""
149        }
150        if {[info exists portinfo(variants)]} {
151                set variants $portinfo(variants)
152        } else {
153                set variants ""
154        }
155        if {[info exists portinfo(depends_lib)]} {
156                set depends_lib $portinfo(depends_lib)
157        } else {
158                set depends_lib ""
159        }
160        if {[info exists portinfo(platforms)]} {
161                set platforms $portinfo(platforms)
162        } else {
163                set platforms ""
164        }
165               
166        set sql "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description')"
167        #puts "$sql"
168        sql_exec $db $sql
169
170        set primary 1
171        foreach category $categories {
172                set category [sql_escape $category]
173                set sql "INSERT INTO categories VALUES ('$portname', '$category', $primary)"
174                #puts "$sql"
175                sql_exec $db $sql
176                set primary 0
177        }
178       
179        set primary 1
180        foreach maintainer $maintainers {
181                set maintainer [sql_escape $maintainer]
182                set sql "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary)"
183                #puts "$sql"
184                sql_exec $db $sql
185                set primary 0
186        }
187
188        foreach lib $depends_lib {
189                set lib [sql_escape $lib]
190                set sql "INSERT INTO dependencies VALUES ('$portname', '$lib')"
191                #puts "$sql"
192                sql_exec $db $sql
193        }
194
195        foreach variant $variants {
196                set variant [sql_escape $variant]
197                set sql "INSERT INTO variants VALUES ('$portname', '$variant')"
198                #puts "$sql"
199                sql_exec $db $sql
200        }
201
202        foreach platform $platforms {
203                set platform [sql_escape $platform]
204                set sql "INSERT INTO platforms VALUES ('$portname', '$platform')"
205                #puts "$sql"
206                sql_exec $db $sql
207        }
208
209}
210
211if {$db != ""} {
212    mysqlclose $db
213    mysqlclose
214}
Note: See TracBrowser for help on using the repository browser.