Julian Noble
11 months ago
20 changed files with 475 additions and 176 deletions
@ -0,0 +1,52 @@ |
|||||||
|
# -*- tcl -*- |
||||||
|
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
||||||
|
# |
||||||
|
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. |
||||||
|
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. |
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
# (C) 2023 |
||||||
|
# |
||||||
|
# @@ Meta Begin |
||||||
|
# Application punk::cap::handlers::caphandler 999999.0a1.0 |
||||||
|
# Meta platform tcl |
||||||
|
# Meta license <unspecified> |
||||||
|
# @@ Meta End |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
## Requirements |
||||||
|
##e.g package require frobz |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
namespace eval punk::cap::handlers::caphandler { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
## Ready |
||||||
|
package provide punk::cap::handlers::caphandler [namespace eval punk::cap::handlers::caphandler { |
||||||
|
variable pkg punk::cap::handlers::caphandler |
||||||
|
variable version |
||||||
|
set version 999999.0a1.0 |
||||||
|
}] |
||||||
|
return |
@ -0,0 +1,127 @@ |
|||||||
|
# -*- tcl -*- |
||||||
|
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
||||||
|
# |
||||||
|
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. |
||||||
|
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. |
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
# (C) 2023 |
||||||
|
# |
||||||
|
# @@ Meta Begin |
||||||
|
# Application punk::cap::handlers::templates 999999.0a1.0 |
||||||
|
# Meta platform tcl |
||||||
|
# Meta license <unspecified> |
||||||
|
# @@ Meta End |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
## Requirements |
||||||
|
##e.g package require frobz |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
#register using: |
||||||
|
# punk::cap::register_capabilityname templates ::punk::cap::handlers::templates |
||||||
|
|
||||||
|
#By convention and for consistency, we don't register here during package loading - but require the calling app to do it. |
||||||
|
# (even if it tends to be done immediately after package require anyway) |
||||||
|
# registering capability handlers can involve validating existing provider data and is best done explicitly as required. |
||||||
|
# It is also possible for a capability handler to be registered to handle more than one capabilityname |
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
namespace eval punk::cap::handlers::templates { |
||||||
|
namespace eval capsystem { |
||||||
|
#interfaces for punk::cap to call into |
||||||
|
if {[info commands caphandler.registry] eq ""} { |
||||||
|
punk::cap::interface_caphandler.registry create caphandler.registry |
||||||
|
oo::objdefine caphandler.registry { |
||||||
|
method pkg_register {pkg capname capdict caplist} { |
||||||
|
#caplist may not be complete set - which somewhat reduces its utility here regarding any decisions based on the context of this capname/capdict (review - remove this arg?) |
||||||
|
if {![dict exists $capdict relpath]} { |
||||||
|
puts stderr "punk::cap::handlers::templates::capsystem::pkg_register WARNING - package '$pkg' is attempting to register with punk::cap as a provider of 'templates' capability, but is missing 'relpath' key" |
||||||
|
return 0 |
||||||
|
} |
||||||
|
set provide_statement [package ifneeded $pkg [package require $pkg]] |
||||||
|
set tmfile [lindex $provide_statement end] |
||||||
|
if {![file exists $tmfile]} { |
||||||
|
puts stderr "punk::cap::handlers::templates::capsystem::pkg_register WARNING - unable to determine base folder for package '$pkg' which is attempting to register with punk::cap as a provider of 'templates' capability" |
||||||
|
return 0 |
||||||
|
} |
||||||
|
set tpath [file normalize [file join $tmfile [dict get $capdict relpath]]] ;#relpath is relative to the tm *file* - not it's containing folder |
||||||
|
if {![file isdirectory $tpath]} { |
||||||
|
puts stderr "punk::cap::handlers::templates::capsystem pkg_register WARNING - unable to determine relpath location [dict get $capdict relpath] for package '$pkg' which is attempting to register with punk::cap as a provider of 'templates' capability" |
||||||
|
} |
||||||
|
if {$capname ni $::punk::cap::handlers::templates::handled_caps} { |
||||||
|
lappend ::punk::cap::handlers::templates::handled_caps $capname |
||||||
|
} |
||||||
|
if {[info commands punk::cap::handlers::templates::$capname] eq ""} { |
||||||
|
punk::cap::handlers::templates::api create ::punk::cap::handlers::templates::$capname $capname |
||||||
|
} |
||||||
|
set cname [string map [list . _] $capname] |
||||||
|
upvar ::punk::cap::handlers::templates::pkg_folders_$cname pfolders |
||||||
|
dict lappend pfolders $pkg $tpath |
||||||
|
return 1 |
||||||
|
} |
||||||
|
method pkg_unregister {pkg} { |
||||||
|
upvar ::punk::cap::handlers::templates::handled_caps hcaps |
||||||
|
foreach capname $hcaps { |
||||||
|
set cname [string map [list . _] $capname] |
||||||
|
upvar ::punk::cap::handlers::templates::pkg_folders_$cname pfolders |
||||||
|
dict unset pfolders $pkg |
||||||
|
#destroy api objects? |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
variable handled_caps [list] |
||||||
|
#variable pkg_folders [dict create] |
||||||
|
|
||||||
|
# -- --- --- --- --- --- --- |
||||||
|
#handler api for clients of this capability - called via punk::cap::call_handler <capname> <method> ?args? |
||||||
|
# -- --- --- --- --- --- --- |
||||||
|
namespace export * |
||||||
|
|
||||||
|
oo::class create api { |
||||||
|
#return a dict keyed on folder with source pkg as value |
||||||
|
constructor {capname} { |
||||||
|
variable capabilityname |
||||||
|
variable cname |
||||||
|
set cname [string map [list . _] $capname] |
||||||
|
set capabilityname $capname |
||||||
|
} |
||||||
|
method folders {} { |
||||||
|
variable capabilityname |
||||||
|
variable cname |
||||||
|
upvar punk::cap::handlers::templates::pkg_folders_$cname pkg_folders |
||||||
|
package require punk::cap |
||||||
|
set capinfo [punk::cap::capability $capabilityname] |
||||||
|
# e.g {punk.templates {handler punk::mix::templates providers ::somepkg}} |
||||||
|
|
||||||
|
#use the order of pkgs as registered with punk::cap - may have been modified with punk::cap::promote_package/demote_package |
||||||
|
set pkgs [dict get $capinfo providers] |
||||||
|
set folderdict [dict create] |
||||||
|
foreach pkg $pkgs { |
||||||
|
foreach pfolder [dict get $pkg_folders $pkg] { |
||||||
|
dict set folderdict $pfolder [list source $pkg sourcetype package] |
||||||
|
} |
||||||
|
} |
||||||
|
return $folderdict |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||||
|
## Ready |
||||||
|
package provide punk::cap::handlers::templates [namespace eval punk::cap::handlers::templates { |
||||||
|
variable pkg punk::cap::handlers::templates |
||||||
|
variable version |
||||||
|
set version 999999.0a1.0 |
||||||
|
}] |
||||||
|
return |
@ -0,0 +1,3 @@ |
|||||||
|
0.1.0 |
||||||
|
#First line must be a semantic version number |
||||||
|
#all other lines are ignored. |
@ -1,102 +0,0 @@ |
|||||||
# -*- tcl -*- |
|
||||||
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
|
||||||
# |
|
||||||
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. |
|
||||||
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. |
|
||||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
||||||
# (C) 2023 |
|
||||||
# |
|
||||||
# @@ Meta Begin |
|
||||||
# Application punk::cap::templates 999999.0a1.0 |
|
||||||
# Meta platform tcl |
|
||||||
# Meta license <unspecified> |
|
||||||
# @@ Meta End |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
||||||
## Requirements |
|
||||||
##e.g package require frobz |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
||||||
#register using: |
|
||||||
# punk::cap::register_capabilityname templates ::punk::cap::templates |
|
||||||
|
|
||||||
#By convention and for consistency, we don't register here during package loading - but require the calling app to do it. |
|
||||||
# (even if it tends to be done immediately after package require anyway) |
|
||||||
# registering capability handlers can involve validating existing provider data and is best done explicitly as required. |
|
||||||
# It is also possible for a capability handler to be registered to handle more than one capabilityname |
|
||||||
|
|
||||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
||||||
namespace eval punk::cap::templates { |
|
||||||
variable callback |
|
||||||
set callback [namespace current]::callback |
|
||||||
if {[info commands $callback] eq ""} { |
|
||||||
punk::cap::callbackbase create $callback |
|
||||||
oo::objdefine $callback { |
|
||||||
method pkg_register {pkg capdict fullcaplist} { |
|
||||||
if {![dict exists $capdict relpath]} { |
|
||||||
return 0 |
|
||||||
} |
|
||||||
return 1 |
|
||||||
} |
|
||||||
method pkg_unregister {pkg} { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
#return a dict keyed on folder with source pkg as value |
|
||||||
proc folders {} { |
|
||||||
package require punk::cap |
|
||||||
set caplist [punk::cap::capabilities templates] |
|
||||||
# e.g {templates {punk::mix::templates ::somepkg}} |
|
||||||
set templates_record [lindex $caplist 0] |
|
||||||
set pkgs [dict get [lindex $templates_record 1] providers] |
|
||||||
|
|
||||||
set folderdict [dict create] |
|
||||||
foreach pkg $pkgs { |
|
||||||
set provide_statement [package ifneeded $pkg [package require $pkg]] |
|
||||||
set tmfile [lindex $provide_statement end] |
|
||||||
if {![file exists $tmfile]} { |
|
||||||
puts stderr "punk::cap::templates::folders WARNING - unable to determine base folder for package '$pkg' which is registered with punk::cap as a provider of 'templates' capability" |
|
||||||
continue |
|
||||||
} |
|
||||||
|
|
||||||
set caplist [dict get [punk::cap::pkgcap $pkg] accepted] |
|
||||||
set templates_entries [lsearch -all -inline -index 0 $caplist templates] ;#we generally expect only one - but if multiple exist - use them |
|
||||||
foreach templates_info $templates_entries { |
|
||||||
lassign $templates_info _templates templates_dict |
|
||||||
if {[dict exists $templates_dict relpath]} { |
|
||||||
#set tmdir [file dirname [lindex $provide_statement end]] |
|
||||||
set tpath [file normalize [file join $tmfile [dict get $templates_dict relpath]]] ;#relpath is relative to the tm *file* - not it's containing folder |
|
||||||
#relpath relative to file is important for tm files that are zip/tar based containers |
|
||||||
if {[file isdirectory $tpath]} { |
|
||||||
dict set folderdict $tpath [list source $pkg sourcetype package] |
|
||||||
} else { |
|
||||||
puts stderr "punk::cap::templates::folders WARNING - unable to determine relpath location [dict get $templates_dict relpath] for package '$pkg' which is registered with punk::cap as a provider of 'templates' capability" |
|
||||||
} |
|
||||||
} else { |
|
||||||
puts stderr "punk::cap::templates::folders WARNING - registered pkg '$pkg' has capability 'templates' but has an entry with no 'relpath' key - unable to use as source of templates" |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return $folderdict |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
|
||||||
## Ready |
|
||||||
package provide punk::cap::templates [namespace eval punk::cap::templates { |
|
||||||
variable pkg punk::cap::templates |
|
||||||
variable version |
|
||||||
set version 999999.0a1.0 |
|
||||||
}] |
|
||||||
return |
|
Loading…
Reference in new issue