[augeas-devel] [Augeas] #237: We need a way to comment-out paths

Augeas trac at fedorahosted.org
Mon Nov 21 15:41:44 UTC 2011


#237: We need a way to comment-out paths
--------------------------+-------------------------------------------------
  Reporter:  ptaff        |       Owner:  lutter
      Type:  enhancement  |      Status:  new   
  Priority:  major        |   Milestone:  next  
 Component:  Augeas       |     Version:  0.8.0 
Resolution:               |    Keywords:        
--------------------------+-------------------------------------------------
Comment (by raphink):

 And here is another example using subnodes (as proposed in
 http://augeas.net/page/Dealing_with_comments#Create_commented_sub-trees):

 {{{
 module Comment_Test =

 let eol = Util.eol

 let key_re = /[A-Za-z]+/

 let entry = Build.key_value_line key_re Sep.equal (store Rx.word)

 let comment = [ label "#comment" . del /#[ \t]*/ "# "
               . store (/([^ \t\n].*[^ \t\n]|[^ \t\n])/ - (key_re . "=" .
 Rx.word))
               . eol ]

 let commented = [ label "commented" . del /#[ \t]*/ "# " . entry ]

 let lns = (entry|comment|commented|Util.empty)*
 }}}

 While this is a bit heavier, at least it saves us from having to use a
 hardcoded "foo" and ".foo" to define commented values.

 Here is an example of this lens working on a Shellvars file (in this case,
 `/etc/default/apport` from Ubuntu 10.04):

 {{{
 $ cat fakeroot/etc/default/apport
 # set this to 0 to disable apport, or to 1 to enable it
 # you can temporarily override this with
 # sudo service apport start force_start=1
 enabled=0

 # set maximum core dump file size (default: 209715200 bytes == 200 MB)
 maxsize=209715200
 $ augtool --noautoload -I ~/dev/augeas/lenses -r fakeroot
 augtool> set /augeas/load/Comment_Test/lens Comment_Test.lns
 augtool> set /augeas/load/Comment_Test/incl /etc/default/apport
 augtool> load
 augtool> print /files/etc/default/apport/
 /files/etc/default/apport
 /files/etc/default/apport/#comment[1] = "set this to 0 to disable apport,
 or to 1 to enable it"
 /files/etc/default/apport/#comment[2] = "you can temporarily override this
 with"
 /files/etc/default/apport/#comment[3] = "sudo service apport start
 force_start=1"
 /files/etc/default/apport/enabled = "0"
 /files/etc/default/apport/#comment[4] = "set maximum core dump file size
 (default: 209715200 bytes == 200 MB)"
 /files/etc/default/apport/maxsize = "209715200"
 augtool> mv /files/etc/default/apport/maxsize
 /files/etc/default/apport/commented/maxsize
 augtool> save
 Saved 1 file(s)
 $ cat fakeroot/etc/default/apport
 # set this to 0 to disable apport, or to 1 to enable it
 # you can temporarily override this with
 # sudo service apport start force_start=1
 enabled=0

 # set maximum core dump file size (default: 209715200 bytes == 200 MB)
 # maxsize=209715200
 augtool> mv /files/etc/default/apport/commented/maxsize
 /files/etc/default/apport/maxsize
 augtool> rm /files/etc/default/apport/commented
 rm : /files/etc/default/apport/commented 1
 augtool> save
 Saved 1 file(s)
 $ cat fakeroot/etc/default/apport
 # set this to 0 to disable apport, or to 1 to enable it
 # you can temporarily override this with
 # sudo service apport start force_start=1
 enabled=0

 # set maximum core dump file size (default: 209715200 bytes == 200 MB)
 maxsize=209715200
 }}}


 Again, this is a very simple example, and it has its downsides, too (like,
 if I actually moved `enabled` instead of `maxsize`, it would put it in the
 end of the file unless I use a `ins before` before doing it).

-- 
Ticket URL: <https://fedorahosted.org/augeas/ticket/237#comment:5>
Augeas <http://augeas.net/>
a configuration API




More information about the augeas-devel mailing list