Posted to tcl by dbohdan at Fri Apr 10 12:25:21 GMT 2015view raw

  1. # tcl-augeas, Tcl bindings for Augeas.
  2. # Copyright (C) 2015 Danyil Bohdan.
  3. # This code is released under the terms of the MIT license. See the file
  4. # LICENSE for details.
  5.  
  6. namespace eval ::augeas::oo {
  7. variable ooSystem
  8. variable newClassCommand
  9.  
  10. if {![catch { package require TclOO }]} {
  11. set ooSystem tcloo
  12. set newClassCommand {::oo::class create}
  13. } elseif {![catch { package require snit 2}]} {
  14. set ooSystem snit
  15. set newClassCommand ::snit::type
  16. } else {
  17. error "augeas::oo requires that either TclOO or Snit 2.x be available"
  18. }
  19. }
  20.  
  21. proc ::augeas::oo::new {root {loadpath ""} {flags 0} {debug 0}} {
  22. variable ooSystem
  23. if {$ooSystem eq "tcloo"} {
  24. return [::augeas::oo::Augeas new \
  25. $root $loadpath $flags $debug]
  26. } else { ;# snit
  27. return [::augeas::oo::Augeas create %AUTO% \
  28. $root $loadpath $flags $debug]
  29. }
  30. }
  31.  
  32. {*}$::augeas::oo::newClassCommand ::augeas::oo::Augeas {
  33. constructor {root {loadpath ""} {flags 0} {_debug 0}} {
  34. variable id
  35. variable debug
  36. set id [::augeas::init $root $loadpath $flags]
  37. set debug $_debug
  38. }
  39.  
  40. destructor {
  41. variable id
  42. if {[info exists id]} {
  43. ::augeas::close $id
  44. }
  45. }
  46.  
  47. method save {} {
  48. variable id
  49. ::augeas::save $id
  50. }
  51.  
  52. method load {} {
  53. variable id
  54. ::augeas::load $id
  55. }
  56.  
  57. method get {path} {
  58. variable id
  59. ::augeas::get $id $path
  60. }
  61.  
  62. method set {path value} {
  63. variable id
  64. ::augeas::set $id $path $value
  65. }
  66.  
  67. method setm {base sub value} {
  68. variable id
  69. ::augeas::setm $id $base $sub $value
  70. }
  71.  
  72. method span {base} {
  73. variable id
  74. ::augeas::span $id $base
  75. }
  76.  
  77. method insert {path label {before 0}} {
  78. variable id
  79. ::augeas::insert $id $path $label $before
  80. }
  81.  
  82. method mv {src dst} {
  83. variable id
  84. ::augeas::mv $id $src $dst
  85. }
  86.  
  87. method rm {path} {
  88. variable id
  89. ::augeas::rm $id $path
  90. }
  91.  
  92. method rename {src lbl} {
  93. variable id
  94. ::augeas::rename $id $src $lbl
  95. }
  96.  
  97. method match {path} {
  98. variable id
  99. ::augeas::match $id $path
  100. }
  101. }
  102.  
  103. package provide augeas::oo 0.1
  104.