82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# NOTE: This procedure adds a directory to the auto-path of the specified
# language (i.e. native Tcl or Eagle). The directory will not be
# added if it is already present. The language argument must be the
# literal string "eagle" or the literal string "tcl". The directory
# argument is the fully qualified path for the directory to add to
# the auto-path.
#
proc addToAutoPath { language directory } {
#
# NOTE: Add the specified directory to the auto-path if not already
# present.
#
if {[string length $language] == 0 || $language eq "eagle"} then {
if {[isEagle]} then {
|
>
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# NOTE: This procedure adds a directory to the auto-path of the specified
# language (i.e. native Tcl or Eagle). The directory will not be
# added if it is already present. The language argument must be the
# literal string "eagle" or the literal string "tcl". The directory
# argument is the fully qualified path for the directory to add to
# the auto-path.
#
# <public>
proc addToAutoPath { language directory } {
#
# NOTE: Add the specified directory to the auto-path if not already
# present.
#
if {[string length $language] == 0 || $language eq "eagle"} then {
if {[isEagle]} then {
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# literal string "tcl". The version argument must be the literal
# string "8.4", "8.5", or "8.6" when the language is "tcl" -OR-
# the literal string "1.0" when the language is "eagle". The
# fileNames argument must be a well-formed list of file names to
# download, each one relative to the language/version-specific
# directory on the package file server. The persistent argument
# should be non-zero if the downloaded files should be saved to
# permanent storage for subsequent use.
#
proc downloadFiles { language version fileNames persistent } {
variable baseUri
variable downloadUri
variable persistentDirectory
variable quiet
if {[string length $language] == 0 || $language eq "eagle"} then {
if {$version ne "1.0"} then {
error "unsupported Eagle version"
}
} elseif {$language eq "tcl"} then {
if {$version ne "8.4" && $version ne "8.5" && $version ne "8.6"} then {
error "unsupported Tcl version"
}
} else {
error "unsupported language"
}
if {$persistent} then {
set downloadRootDirectory [file join $persistentDirectory]
} else {
global env
if {[info exists env(PKGD_TEMP)]} then {
set downloadRootDirectory [file join $env(PKGD_TEMP) pkgr]
} elseif {[info exists env(TEMP)]} then {
set downloadRootDirectory [file join $env(TEMP) pkgr]
} elseif {[info exists env(TMP)]} then {
set downloadRootDirectory [file join $env(TMP) pkgr]
} else {
error "please set PKGD_TEMP (via environment) to temporary directory"
}
}
set downloadDirectories [list]
foreach fileName $fileNames {
if {[string length $fileName] == 0 || \
[file pathtype $fileName] ne "relative"} then {
error [appendArgs \
"bad file name \"" $fileName "\", not relative"]
}
set directoryParts [file split [file dirname $fileName]]
if {[llength $directoryParts] == 0} then {
error [appendArgs \
"bad file name \"" $fileName "\", no directory parts"]
}
set downloadDirectory [eval file join \
[list $downloadRootDirectory] $directoryParts]
set downloadFileName [file join $downloadDirectory \
[file tail $fileName]]
if {!$persistent} then {
catch {file delete $downloadFileName}
}
file mkdir [file dirname $downloadFileName]
set fileName [file join $language $version $fileName]
set uri [subst $downloadUri]
if {[isEagle]} then {
writeFile $downloadFileName [interp readorgetscriptfile -- "" $uri]
} else {
writeFile $downloadFileName [::PackageRepository::getFileViaHttp \
$uri 10 stdout $quiet]
}
lappend downloadDirectories [file dirname $downloadDirectory]
}
set downloadDirectories [lsort -unique $downloadDirectories]
foreach downloadDirectory $downloadDirectories {
addToAutoPath $language $downloadDirectory
}
}
#
# NOTE: Setup the variables, within this namespace, used by this script.
#
setupDownloadVars
|
|
>
>
>
>
>
>
|
>
|
>
>
>
|
|
|
>
>
>
|
|
|
|
>
>
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
|
|
>
>
>
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# literal string "tcl". The version argument must be the literal
# string "8.4", "8.5", or "8.6" when the language is "tcl" -OR-
# the literal string "1.0" when the language is "eagle". The
# fileNames argument must be a well-formed list of file names to
# download, each one relative to the language/version-specific
# directory on the package file server. The persistent argument
# should be non-zero if the downloaded files should be saved to
# permanent storage for subsequent use. The usePgp argument
# should be non-zero when an OpenPGP signature file needs to be
# downloaded and verified for each downloaded file. The
# useAutoPath argument should be non-zero to modify the auto-path
# to include the temporary or persistent directories containing
# the downloaded files.
#
# <public>
proc downloadFiles {
language version fileNames persistent usePgp useAutoPath } {
variable baseUri
variable downloadUri
variable persistentDirectory
variable quiet
if {[string length $language] == 0 || $language eq "eagle"} then {
if {$version ne "1.0"} then {
error "unsupported Eagle version"
}
} elseif {$language eq "tcl"} then {
if {$version ne "8.4" && $version ne "8.5" && $version ne "8.6"} then {
error "unsupported Tcl version"
}
} else {
error "unsupported language"
}
if {$persistent} then {
set downloadRootDirectory $persistentDirectory
} else {
set directoryNameOnly [appendArgs \
pkgd_ [string trim [pid] -] _ [string trim [clock seconds] -]]
global env
if {[info exists env(PKGD_TEMP)]} then {
set downloadRootDirectory $env(PKGD_TEMP)
} elseif {[info exists env(TEMP)]} then {
set downloadRootDirectory $env(TEMP)
} elseif {[info exists env(TMP)]} then {
set downloadRootDirectory $env(TMP)
} else {
error "please set PKGD_TEMP (via environment) to temporary directory"
}
set downloadRootDirectory [file join \
$downloadRootDirectory $directoryNameOnly]
}
set downloadDirectories [list]
foreach fileName $fileNames {
if {[string length $fileName] == 0 || \
[file pathtype $fileName] ne "relative"} then {
error [appendArgs \
"bad file name \"" $fileName "\", not relative"]
}
set directoryParts [file split [file dirname $fileName]]
if {[llength $directoryParts] == 0} then {
error [appendArgs \
"bad file name \"" $fileName "\", no directory parts"]
}
set downloadDirectory [file normalize [eval file join \
[list $downloadRootDirectory] $directoryParts]]
set downloadFileName [file normalize [file join \
$downloadDirectory [file tail $fileName]]]
if {!$persistent} then {
catch {file delete $downloadFileName}
}
file mkdir [file dirname $downloadFileName]
set savedFileName $fileName
set fileName [file join $language $version $fileName]
set uri [subst $downloadUri]
set fileName $savedFileName
if {[isEagle]} then {
writeFile $downloadFileName \
[interp readorgetscriptfile -- "" $uri]
} else {
writeFile $downloadFileName \
[::PackageRepository::getFileViaHttp $uri 10 stdout $quiet]
}
if {$usePgp} then {
set downloadSignatureFileName [appendArgs $downloadFileName .asc]
set savedFileName $fileName
set fileName [file join \
$language $version [appendArgs $fileName .asc]]
set uri [subst $downloadUri]
set fileName $savedFileName
if {[isEagle]} then {
writeFile $downloadSignatureFileName \
[interp readorgetscriptfile -- "" $uri]
} else {
writeFile $downloadSignatureFileName \
[::PackageRepository::getFileViaHttp $uri 10 stdout $quiet]
}
if {![::PackageRepository::verifyPgpSignature \
$downloadSignatureFileName]} then {
error [appendArgs \
"bad PGP signature \"" $downloadSignatureFileName \"]
}
}
lappend downloadDirectories $downloadDirectory
}
set downloadDirectories [lsort -unique $downloadDirectories]
if {$useAutoPath} then {
foreach downloadDirectory $downloadDirectories {
addToAutoPath $language $downloadDirectory
}
}
return $downloadDirectories
}
#
# NOTE: Setup the variables, within this namespace, used by this script.
#
setupDownloadVars
|