source: trunk/base/src/port1.0/portregistry.tcl @ 477

Last change on this file since 477 was 477, checked in by landonf, 15 years ago

Fix spelling of "registry"

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1# ex:ts=4
2# portregistry.tcl
3#
4# Copyright (c) 2002 Apple Computer, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
16#    may be used to endorse or promote products derived from this software
17#    without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#
31
32package provide portregistry 1.0
33package require portutil 1.0
34
35register com.apple.registry target registry_main registry_init
36register com.apple.registry provides registry
37register com.apple.registry requires main fetch extract checksum patch configure build install depends_run depends_lib
38
39# define options
40options contents description
41
42set UI_PREFIX "---> "
43
44# For now, just write stuff to a file for debugging.
45
46proc registry_new {portname {portversion 1.0}} {
47    exec mkdir -p /Library/Receipts/darwinports
48    return [open "/Library/Receipts/darwinports/$portname-$portversion" w 0644]
49}
50
51proc registry_store {rhandle data} {
52    puts $rhandle "\# Contents Format: {{filename uid gid mode size {md5}} ... }"
53    puts $rhandle $data
54}
55
56proc registry_fetch {rhandle} {
57    return -1
58}
59
60proc registry_traverse {func} {
61    return -1
62}
63
64proc registry_close {rhandle} {
65    close $rhandle
66}
67
68proc fileinfo_for_file {fname} {
69    if ![catch {file stat $fname statvar}] {
70        set md5regex "^(MD5)\[ \]\\(($fname)\\)\[ \]=\[ \](\[A-Za-z0-9\]+)\n$"
71        set pipe [open "|md5 $fname" r]
72        set line [read $pipe]
73        if {[regexp $md5regex $line match type filename sum] == 1} {
74            close $pipe
75            return [list $fname $statvar(uid) $statvar(gid) $statvar(mode) $statvar(size) $line]
76        }
77        close $pipe
78    }
79    return {}
80}
81
82proc fileinfo_for_entry {rval dir entry} {
83    upvar $rval myrval
84    set path [file join $dir $entry]
85    if [file isdirectory $path] {
86        foreach name [readdir $path] {
87            if {[string match $name .] || [string match $name ..]} {
88                continue
89            }
90            set subpath [file join $path $name]
91            if [file isdirectory $subpath] {
92                fileinfo_for_entry myrval $subpath ""
93            } elseif [file readable $subpath] {
94                lappend myrval [fileinfo_for_file $subpath]
95            }
96        }
97    } elseif [file readable $path] {
98        lappend myrval [fileinfo_for_file $path]
99    }
100    return $myrval
101}
102
103proc fileinfo_for_index {flist} {
104    global prefix
105    set rval {}
106    foreach file $flist {
107        if [string match /* $file] {
108            fileinfo_for_entry rval / $file
109        } else {
110            fileinfo_for_entry rval $prefix $file
111        }
112    }
113    return $rval
114}
115
116proc proc_disasm {pname} {
117    set p "proc "
118    append p $pname " {"
119    set space ""
120    foreach arg [info args $pname] {
121        if [info default $pname $arg value] {
122            append p "$space{" [list $arg $value] "}"
123        } else {
124            append p $space $arg
125        }
126        set space " "
127    }
128    append p "} {" [info body $pname] "}"
129    return $p
130}
131
132proc registry_init {args} {
133    return 0
134}
135
136proc registry_main {args} {
137    global portname portversion portpath categories description depends_run contents pkg_install pkg_deinstall workdir worksrcdir prefix UI_PREFIX
138
139    # Package installed successfully, so now we must register it
140    set rhandle [registry_new $portname $portversion]
141    ui_msg "$UI_PREFIX Adding $portname to registry (this may take a moment)..."
142    lappend data [list prefix $prefix]
143    lappend data [list categories $categories]
144    if [info exists description] {
145        lappend data [list description $description]
146    }
147    if [info exists depends_run] {
148        lappend data [list run_depends $depends_run]
149    }
150    if [info exists contents] {
151        set plist [fileinfo_for_index $contents]
152        lappend data [list contents $plist]
153    }
154    if {[info proc pkg_install] == "pkg_install"} {
155        lappend data [list pkg_install [proc_disasm pkg_install]]
156    }
157    if {[info proc pkg_deinstall] == "pkg_deinstall"} {
158        lappend data [list pkg_deinstall [proc_disasm pkg_deinstall]]
159    }
160    registry_store $rhandle $data
161    registry_close $rhandle
162    return 0
163}
Note: See TracBrowser for help on using the repository browser.