1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#!/usr/local/bin/ruby -w
# $Id$
require 'singleton'
require 'puppet/log'
# see the bottom of the file for further inclusions
#------------------------------------------------------------
# the top-level module
#
# all this really does is dictate how the whole system behaves, through
# preferences for things like debugging
#
# it's also a place to find top-level commands like 'debug'
module Puppet
class Error < RuntimeError
attr_accessor :stack, :line, :file
def initialize(message)
@message = message
@stack = caller
end
def to_s
if @file and @line
return "%s at file %s, line %s" %
[@message, @file, @line]
else
return @message
end
end
end
class DevError < Error; end
# the hash that determines how our system behaves
@@config = Hash.new(false)
# define helper messages for each of the message levels
Puppet::Log.levels.each { |level|
define_method(level,proc { |args|
Puppet::Log.create(level,args)
})
module_function level
}
# I keep wanting to use Puppet.error
alias :error :err
# configuration parameter access and stuff
def self.[](param)
case param
when :debug:
if Puppet::Log.level == :debug
return true
else
return false
end
when :loglevel:
return Puppet::Log.level
when :logdest:
return Puppet::Log.destination
else
return @@config[param]
end
end
# configuration parameter access and stuff
def self.[]=(param,value)
case param
when :debug:
if value
Puppet::Log.level=(:debug)
else
Puppet::Log.level=(:notice)
end
when :loglevel:
Puppet::Log.level=(value)
when :logdest:
Puppet::Log.destination=(value)
else
@@config[param] = value
end
end
def self.recmkdir(dir,mode = 0755)
tmp = dir.sub(/^\//,'')
path = [File::SEPARATOR]
tmp.split(File::SEPARATOR).each { |dir|
path.push dir
if ! FileTest.exist?(File.join(path))
Dir.mkdir(File.join(path), mode)
elsif FileTest.directory?(File.join(path))
next
else FileTest.exist?(File.join(path))
raise "Cannot create %s: basedir %s is a file" %
[dir, File.join(path)]
end
}
end
self[:rrdgraph] = false
if Process.uid == 0
self[:puppetroot] = "/var/puppet"
else
self[:puppetroot] = File.expand_path("~/.puppet")
end
self[:rrddir] = File.join(self[:puppetroot],"rrd")
self[:logdir] = File.join(self[:puppetroot],"log")
self[:logfile] = File.join(self[:puppetroot],"log/puppet.log")
self[:statefile] = File.join(self[:puppetroot],"log/state")
end
require 'puppet/type'
require 'puppet/storage'
|