From d8b4b0dbf35b2b183cd62adf591ebf4650448a0d Mon Sep 17 00:00:00 2001 From: luke Date: Tue, 4 Apr 2006 22:23:08 +0000 Subject: adding -e ability to puppet executable git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1065 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/parser/interpreter.rb | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 4f5f1f69a..730b59e15 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -42,11 +42,11 @@ module Puppet # create our interpreter def initialize(hash) - unless hash.include?(:Manifest) - raise Puppet::DevError, "Interpreter was not passed a manifest" + if @code = hash[:Code] + @file = nil # to avoid warnings + elsif ! @file = hash[:Manifest] + raise Puppet::DevError, "You must provide code or a manifest" end - - @file = hash[:Manifest] @filetimeout = hash[:ParseCheck] || 15 @lastchecked = 0 @@ -258,24 +258,26 @@ module Puppet end def parsefiles - if defined? @parser - # Only check the files every 15 seconds or so, not on - # every single connection - if (Time.now - @lastchecked).to_i >= @filetimeout.to_i - unless @parser.reparse? - @lastchecked = Time.now - return false + if @file + if defined? @parser + # Only check the files every 15 seconds or so, not on + # every single connection + if (Time.now - @lastchecked).to_i >= @filetimeout.to_i + unless @parser.reparse? + @lastchecked = Time.now + return false + end + else + return end - else - return end - end - unless FileTest.exists?(@file) - if @ast - return - else - raise Puppet::Error, "Manifest %s must exist" % @file + unless FileTest.exists?(@file) + if @ast + return + else + raise Puppet::Error, "Manifest %s must exist" % @file + end end end @@ -284,7 +286,11 @@ module Puppet end # should i be creating a new parser each time...? @parser = Puppet::Parser::Parser.new() - @parser.file = @file + if @code + @parser.string = @code + else + @parser.file = @file + end @ast = @parser.parse # Mark when we parsed, so we can check freshness -- cgit