summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/fileparsing.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-12 04:12:48 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-12 04:12:48 +0000
commitbd169b44a0ce58413fb5b031c3f12cd4ca6f4cbe (patch)
tree0411a38b49c5a311819c878c475672376c0f2578 /lib/puppet/util/fileparsing.rb
parent138150d1f240d3c249b2985540af1a7e327802e1 (diff)
downloadpuppet-bd169b44a0ce58413fb5b031c3f12cd4ca6f4cbe.tar.gz
puppet-bd169b44a0ce58413fb5b031c3f12cd4ca6f4cbe.tar.xz
puppet-bd169b44a0ce58413fb5b031c3f12cd4ca6f4cbe.zip
Mounts work again, at least with the parsedfile provider. I still need to create a netinfo provider, but it should be short and easy. And, painfully, I still need to port the other six or so subclasses to this new provider.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1859 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util/fileparsing.rb')
-rw-r--r--lib/puppet/util/fileparsing.rb49
1 files changed, 46 insertions, 3 deletions
diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb
index 705192b11..91a70c214 100644
--- a/lib/puppet/util/fileparsing.rb
+++ b/lib/puppet/util/fileparsing.rb
@@ -34,6 +34,15 @@ module Puppet::Util::FileParsing
@record_order.clear
end
+ def fields(type)
+ type = symbolize(type)
+ if @record_types.include?(type)
+ @record_types[type][:fields].dup
+ else
+ nil
+ end
+ end
+
# Try to match a specific text line.
def handle_text_line(line, hash)
if line =~ hash[:match]
@@ -46,10 +55,22 @@ module Puppet::Util::FileParsing
# Try to match a record.
def handle_record_line(line, hash)
if hash[:match]
+ raise "No provision yet for matching whole lines"
else
ret = {}
- hash[:fields].zip(line.split(hash[:separator])) do |param, value|
- ret[param] = value
+ sep = hash[:separator]
+
+ # String "helpfully" replaces ' ' with /\s+/ in splitting, so we
+ # have to work around it.
+ if sep == " "
+ sep = / /
+ end
+ hash[:fields].zip(line.split(sep)) do |param, value|
+ if value and value != ""
+ ret[param] = value
+ else
+ ret[param] = :absent
+ end
end
ret[:record_type] = hash[:name]
return ret
@@ -117,6 +138,8 @@ module Puppet::Util::FileParsing
r
end
+ options[:absent] ||= ""
+
options[:separator] ||= /\s+/
# Unless they specified a string-based joiner, just use a single
@@ -164,7 +187,14 @@ module Puppet::Util::FileParsing
else
joinchar = type[:joiner] || type[:separator]
- return type[:fields].collect { |field| details[field].to_s }.join(joinchar)
+ return type[:fields].collect { |field|
+ # If the field is marked absent, use the appropriate replacement
+ if details[field] == :absent
+ type[:absent]
+ else
+ details[field].to_s
+ end
+ }.join(joinchar)
end
end
@@ -177,6 +207,19 @@ module Puppet::Util::FileParsing
end
end
+ def valid_attr?(type, attr)
+ type = symbolize(type)
+ if @record_types[type] and @record_types[type][:fields].include?(symbolize(attr))
+ return true
+ else
+ if symbolize(attr) == :ensure
+ return true
+ else
+ false
+ end
+ end
+ end
+
private
# Define a new type of record.
def new_line_type(name, type, options)