Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/share/ruby/vendor_r...
File: augeas.rb
##
[0] Fix | Delete
# augeas.rb: Ruby wrapper for augeas
[1] Fix | Delete
#
[2] Fix | Delete
# Copyright (C) 2008 Red Hat Inc.
[3] Fix | Delete
#
[4] Fix | Delete
# This library is free software; you can redistribute it and/or
[5] Fix | Delete
# modify it under the terms of the GNU Lesser General Public
[6] Fix | Delete
# License as published by the Free Software Foundation; either
[7] Fix | Delete
# version 2.1 of the License, or (at your option) any later version.
[8] Fix | Delete
#
[9] Fix | Delete
# This library is distributed in the hope that it will be useful,
[10] Fix | Delete
# but WITHOUT ANY WARRANTY; without even the implied warranty of
[11] Fix | Delete
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
[12] Fix | Delete
# Lesser General Public License for more details.
[13] Fix | Delete
#
[14] Fix | Delete
# You should have received a copy of the GNU Lesser General Public
[15] Fix | Delete
# License along with this library; if not, write to the Free Software
[16] Fix | Delete
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[17] Fix | Delete
#
[18] Fix | Delete
# Author: Bryan Kearney <bkearney@redhat.com>
[19] Fix | Delete
##
[20] Fix | Delete
[21] Fix | Delete
require "_augeas"
[22] Fix | Delete
[23] Fix | Delete
# Wrapper class for the augeas[http://augeas.net] library.
[24] Fix | Delete
class Augeas
[25] Fix | Delete
private_class_method :new
[26] Fix | Delete
[27] Fix | Delete
class Error < RuntimeError; end
[28] Fix | Delete
[29] Fix | Delete
# Create a new Augeas instance and return it.
[30] Fix | Delete
#
[31] Fix | Delete
# Use +root+ as the filesystem root. If +root+ is +nil+, use the value
[32] Fix | Delete
# of the environment variable +AUGEAS_ROOT+. If that doesn't exist
[33] Fix | Delete
# either, use "/".
[34] Fix | Delete
#
[35] Fix | Delete
# +loadpath+ is a colon-spearated list of directories that modules
[36] Fix | Delete
# should be searched in. This is in addition to the standard load path
[37] Fix | Delete
# and the directories in +AUGEAS_LENS_LIB+
[38] Fix | Delete
#
[39] Fix | Delete
# +flags+ is a bitmask (see <tt>enum aug_flags</tt>)
[40] Fix | Delete
#
[41] Fix | Delete
# When a block is given, the Augeas instance is passed as the only
[42] Fix | Delete
# argument into the block and closed when the block exits. In that
[43] Fix | Delete
# case, the return value of the block is the return value of
[44] Fix | Delete
# +open+. With no block, the Augeas instance is returned.
[45] Fix | Delete
def self.open(root = nil, loadpath = nil, flags = NONE, &block)
[46] Fix | Delete
aug = open3(root, loadpath, flags)
[47] Fix | Delete
if block_given?
[48] Fix | Delete
begin
[49] Fix | Delete
rv = yield aug
[50] Fix | Delete
return rv
[51] Fix | Delete
ensure
[52] Fix | Delete
aug.close
[53] Fix | Delete
end
[54] Fix | Delete
else
[55] Fix | Delete
return aug
[56] Fix | Delete
end
[57] Fix | Delete
end
[58] Fix | Delete
[59] Fix | Delete
# Set one or multiple elemens to path.
[60] Fix | Delete
# Multiple elements are mainly sensible with a path like
[61] Fix | Delete
# .../array[last()+1], since this will append all elements.
[62] Fix | Delete
def set(path, *values)
[63] Fix | Delete
values.flatten.each { |v| set_internal(path, v) }
[64] Fix | Delete
end
[65] Fix | Delete
[66] Fix | Delete
# The same as +set+, but raises <tt>Augeas::Error</tt> if setting fails
[67] Fix | Delete
def set!(path, *values)
[68] Fix | Delete
values.flatten.each do |v|
[69] Fix | Delete
raise Augeas::Error unless set_internal(path, v)
[70] Fix | Delete
end
[71] Fix | Delete
end
[72] Fix | Delete
[73] Fix | Delete
# Clear the +path+, i.e. make its value +nil+
[74] Fix | Delete
def clear(path)
[75] Fix | Delete
set_internal(path, nil)
[76] Fix | Delete
end
[77] Fix | Delete
[78] Fix | Delete
# Clear multiple nodes values in one operation. Find or create a node matching +sub+
[79] Fix | Delete
# by interpreting +sub+ as a path expression relative to each node matching
[80] Fix | Delete
# +base+. If +sub+ is '.', the nodes matching +base+ will be modified.
[81] Fix | Delete
def clearm(base, sub)
[82] Fix | Delete
setm(base, sub, nil)
[83] Fix | Delete
end
[84] Fix | Delete
[85] Fix | Delete
# Create the +path+ with empty value if it doesn't exist
[86] Fix | Delete
def touch(path)
[87] Fix | Delete
set_internal(path, nil) if match(path).empty?
[88] Fix | Delete
end
[89] Fix | Delete
[90] Fix | Delete
# Clear all transforms under <tt>/augeas/load</tt>. If +load+
[91] Fix | Delete
# is called right after this, there will be no files
[92] Fix | Delete
# under +/files+
[93] Fix | Delete
def clear_transforms
[94] Fix | Delete
rm("/augeas/load/*")
[95] Fix | Delete
end
[96] Fix | Delete
[97] Fix | Delete
# Add a transform under <tt>/augeas/load</tt>
[98] Fix | Delete
#
[99] Fix | Delete
# The HASH can contain the following entries
[100] Fix | Delete
# * <tt>:lens</tt> - the name of the lens to use
[101] Fix | Delete
# * <tt>:name</tt> - a unique name; use the module name of the LENS when omitted
[102] Fix | Delete
# * <tt>:incl</tt> - a list of glob patterns for the files to transform
[103] Fix | Delete
# * <tt>:excl</tt> - a list of the glob patterns to remove from the list that matches <tt>:INCL</tt>
[104] Fix | Delete
def transform(hash)
[105] Fix | Delete
lens = hash[:lens]
[106] Fix | Delete
name = hash[:name]
[107] Fix | Delete
incl = hash[:incl]
[108] Fix | Delete
excl = hash[:excl]
[109] Fix | Delete
raise ArgumentError, "No lens specified" unless lens
[110] Fix | Delete
raise ArgumentError, "No files to include" unless incl
[111] Fix | Delete
lens = "#{lens}.lns" unless lens.include? '.'
[112] Fix | Delete
name = lens.split(".")[0].sub("@", "") unless name
[113] Fix | Delete
[114] Fix | Delete
xfm = "/augeas/load/#{name}/"
[115] Fix | Delete
set(xfm + "lens", lens)
[116] Fix | Delete
set(xfm + "incl[last()+1]", incl)
[117] Fix | Delete
set(xfm + "excl[last()+1]", excl) if excl
[118] Fix | Delete
end
[119] Fix | Delete
[120] Fix | Delete
# The same as +save+, but raises <tt>Augeas::Error</tt> if saving fails
[121] Fix | Delete
def save!
[122] Fix | Delete
raise Augeas::Error unless save
[123] Fix | Delete
end
[124] Fix | Delete
[125] Fix | Delete
# The same as +load+, but raises <tt>Augeas::Error</tt> if loading fails
[126] Fix | Delete
def load!
[127] Fix | Delete
raise Augeas::Error unless load
[128] Fix | Delete
end
[129] Fix | Delete
[130] Fix | Delete
# Set path expression context to +path+ (in /augeas/context)
[131] Fix | Delete
def context=(path)
[132] Fix | Delete
set_internal('/augeas/context', path)
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
# Get path expression context (from /augeas/context)
[136] Fix | Delete
def context
[137] Fix | Delete
get('/augeas/context')
[138] Fix | Delete
end
[139] Fix | Delete
[140] Fix | Delete
end
[141] Fix | Delete
[142] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function