︙ | | | ︙ | |
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package require Eagle.Library
#
# NOTE: This procedure returns a formatted, possibly version-specific,
# package name, for use in logging.
#
proc formatPackageName { package version } {
return [string trim [appendArgs \
$package " " [getLookupVersion $version]]]
}
#
# NOTE: This procedure returns a formatted script result. If the string
# result is empty, only the return code is used. The code argument
# must be an integer Tcl return code (e.g. from [catch]) and the
# result argument is the script result or error message.
|
|
<
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package require Eagle.Library
#
# NOTE: This procedure returns a formatted, possibly version-specific,
# package name, for use in logging.
#
proc formatPackageName { package version } {
return [string trim [appendArgs $package " " $version]]
}
#
# NOTE: This procedure returns a formatted script result. If the string
# result is empty, only the return code is used. The code argument
# must be an integer Tcl return code (e.g. from [catch]) and the
# result argument is the script result or error message.
|
︙ | | | ︙ | |
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
#
# NOTE: This procedure accepts a package requirement (spec) and returns
# a simple package version, if possible. An empty string will be
# returned, if appropriate (i.e. any version should be allowed).
# The requirement argument must be a package specification that
# conforms to TIP #268.
#
proc getLookupVersion { requirement } {
if {[set index [string first - $requirement]] != -1} then {
incr index -1; set requirement [string range $requirement 0 $index]
}
if {[set index [string first a $requirement]] != -1 || \
[set index [string first b $requirement]] != -1} then {
incr index -1; set requirement [string range $requirement 0 $index]
}
if {$requirement eq "0"} then {
set requirement ""
} elseif {[regexp -- {^\d+$} $requirement]} then {
append requirement .0
}
return $requirement
}
#
# NOTE: This procedure issues an HTTP request that should return metadata
# that can be used to load and/or provide the specified package.
# The apiKey argument is the API key to use -OR- an empty string if
# a public package is being looked up. The package argument is the
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
#
# NOTE: This procedure accepts a package requirement (spec) and returns
# a simple package version, if possible. An empty string will be
# returned, if appropriate (i.e. any version should be allowed).
# The requirement argument must be a package specification that
# conforms to TIP #268.
#
proc packageRequirementToVersion { requirement } {
set result $requirement
if {[set index [string first - $result]] != -1} then {
incr index -1; set result [string range $result 0 $index]
}
if {[set index [string first a $result]] != -1 || \
[set index [string first b $result]] != -1} then {
incr index -1; set result [string range $result 0 $index]
}
if {$result eq "0"} then {
set result ""
} elseif {[regexp -- {^\d+$} $result]} then {
append result .0
}
return $result
}
#
# NOTE: This procedure issues an HTTP request that should return metadata
# that can be used to load and/or provide the specified package.
# The apiKey argument is the API key to use -OR- an empty string if
# a public package is being looked up. The package argument is the
|
︙ | | | ︙ | |
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
#
# NOTE: The code must be the literal string "OK" for the package lookup
# request to be considered successful.
#
return [expr {$code eq "OK"}]
}
#
# NOTE: This procedure attempts to extract the package lookup metadata from
# the lookup result. The result argument is the lookup result. The
# varName argument is the name of an array variable, in the call frame
# of the immediate caller, that should receive the extracted package
# lookup metadata. The caller argument must be an empty string -OR-
# the literal string "handler".
#
proc extractAndVerifyLookupMetadata { result varName caller } {
variable strictUnknownLanguage
#
# NOTE: Grab the language for the package script. It must be an empty
# string, "Tcl", or "Eagle". If it is an empty string, "Eagle"
# will be assumed.
#
set language [getDictionaryValue $result Language]
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
#
# NOTE: The code must be the literal string "OK" for the package lookup
# request to be considered successful.
#
return [expr {$code eq "OK"}]
}
#
# NOTE: This procedure was stolen from the "common.tcl" script used by the
# package repository server. It has been modified to support both
# native Tcl and Eagle. It should be noted here that TIP #268 syntax
# is not supported by Eagle. For native Tcl, the requirement argument
# must be a package version or requirement conforming to the TIP #268
# syntax. For Eagle, the requirement argument must be a simple dotted
# package version, with up to four components, without any 'a' or 'b'.
# The emptyOk argument should be non-zero if an empty string should be
# considered to be valid by the caller. The rangeOk argument should
# be non-zero if the version range syntax is allowed; this argument is
# ignored for Eagle because it requires TIP #268 support.
#
proc isValidPackageRequirement { requirement rangeOk {emptyOk false} } {
if {$emptyOk && [string length $requirement] == 0} then {
return true
}
if {[isEagle]} then {
#
# NOTE: Eagle does not support TIP #268. Use the built-in sub-command
# that checks a version number.
#
return [string is version -strict $requirement]
} else {
#
# HACK: If a version range is not allowed, make sure that the dash
# character is not present.
#
if {!$rangeOk && [string first - $requirement] != -1} then {
return false
}
#
# HACK: There is no direct way to check if a package requirement
# that uses the TIP #268 syntax is valid; however, we can
# purposely "misuse" the [package present] command for this
# purpose. We know the "Tcl" package is always present;
# therefore, if an error is raised here, then the package
# requirement is probably invalid. Unfortunately, the error
# message text has to be checked as well; otherwise, there
# is no way to verify version numbers that happen to be less
# than the running patch level of Tcl.
#
if {[catch {package present Tcl $requirement} error] == 0} then {
return true
} else {
#
# TODO: Maybe this will require updates in the future?
#
set pattern(1) "expected version number but got *"
set pattern(2) "expected versionMin-versionMax but got *"
if {![string match $pattern(1) $error] && \
![string match $pattern(2) $error]} then {
return true
} else {
return false
}
}
}
}
#
# NOTE: This procedure attempts to extract the package lookup metadata from
# the lookup result. The result argument is the lookup result. The
# varName argument is the name of an array variable, in the call frame
# of the immediate caller, that should receive the extracted package
# lookup metadata. The caller argument must be an empty string -OR-
# the literal string "handler".
#
proc extractAndVerifyLookupMetadata { result varName caller } {
variable strictUnknownLanguage
#
# NOTE: Grab the returned patch level. It cannot be an empty string
# and it must conform to the TIP #268 requirements for a single
# package version.
#
set patchLevel [getDictionaryValue $result PatchLevel]
if {[string length $patchLevel] == 0} then {
error "missing patch level"
}
if {![isValidPackageRequirement $patchLevel false]} then {
error "bad patch level"
}
#
# NOTE: Grab the language for the package script. It must be an empty
# string, "Tcl", or "Eagle". If it is an empty string, "Eagle"
# will be assumed.
#
set language [getDictionaryValue $result Language]
|
︙ | | | ︙ | |
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
#
# NOTE: If the caller wants the package lookup metadata, use their
# array variable name.
#
if {[string length $varName] > 0} then {
upvar 1 $varName metadata
set metadata(language) $language
set metadata(script) $script
set metadata(certificate) $certificate
}
}
#
|
>
|
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
#
# NOTE: If the caller wants the package lookup metadata, use their
# array variable name.
#
if {[string length $varName] > 0} then {
upvar 1 $varName metadata
set metadata(patchLevel) $patchLevel
set metadata(language) $language
set metadata(script) $script
set metadata(certificate) $certificate
}
}
#
|
︙ | | | ︙ | |
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
#
# NOTE: If the entire package metadata array is missing, fail.
#
if {![info exists metadata]} then {
error "missing metadata"
}
#
# NOTE: If the language for the package script is mising, fail.
#
if {![info exists metadata(language)]} then {
error "missing language"
}
|
>
>
>
>
>
>
>
|
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
#
# NOTE: If the entire package metadata array is missing, fail.
#
if {![info exists metadata]} then {
error "missing metadata"
}
#
# NOTE: If the patch level for the package is mising, fail.
#
if {![info exists metadata(patchLevel)]} then {
error "missing patch level"
}
#
# NOTE: If the language for the package script is mising, fail.
#
if {![info exists metadata(language)]} then {
error "missing language"
}
|
︙ | | | ︙ | |
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
|
}
#
# NOTE: Maybe check for the package and then optionally log results.
#
if {$verboseUnknownResult} then {
set ifNeededVersion [getIfNeededVersion \
$package [getLookupVersion $version]]
if {[string length $ifNeededVersion] > 0} then {
set command [list package ifneeded $package $ifNeededVersion]
if {[catch $command result(3)] == 0 && \
[string length $result(3)] > 0} then {
pkgLog [appendArgs \
|
|
|
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
}
#
# NOTE: Maybe check for the package and then optionally log results.
#
if {$verboseUnknownResult} then {
set ifNeededVersion [getIfNeededVersion \
$package [packageRequirementToVersion $version]]
if {[string length $ifNeededVersion] > 0} then {
set command [list package ifneeded $package $ifNeededVersion]
if {[catch $command result(3)] == 0 && \
[string length $result(3)] > 0} then {
pkgLog [appendArgs \
|
︙ | | | ︙ | |
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
|
#
set apiKeys [getLookupApiKeys]; lappend apiKeys ""
foreach apiKey $apiKeys {
#
# NOTE: Issue the lookup request to the remote package repository.
#
set data [getLookupData \
$apiKey $package [getLookupVersion $version]]
#
# NOTE: Attempt to grab the lookup code from the response data.
#
set code [getLookupCodeFromData $data]
#
|
|
<
|
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
|
#
set apiKeys [getLookupApiKeys]; lappend apiKeys ""
foreach apiKey $apiKeys {
#
# NOTE: Issue the lookup request to the remote package repository.
#
set data [getLookupData $apiKey $package $version]
#
# NOTE: Attempt to grab the lookup code from the response data.
#
set code [getLookupCodeFromData $data]
#
|
︙ | | | ︙ | |