Class: Cfruby::Cfp_Stat

Inherits:
Object
  • Object
show all
Includes:
Cfp_ClassAccessor
Defined in:
lib/libcfenjin/cfp_stat.rb

Overview

Cfp_Stat holds the state of the Cfruby engine at runtime. With Cfruby engine classes it needs to be passed during class initialisation. Scripts can access state through the local @cfp variable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cfp_ClassAccessor

#assign, #cfgroup, #dump_classlist, #init_classlist, #isa, #isa?

Constructor Details

#initialize(version = nil, verbose = 0, trace = 0, dry_run = true, quiet_mode = false, strict = false, defines = [], undefines = []) ⇒ Cfp_Stat

Returns a new instance of Cfp_Stat.



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
# File 'lib/libcfenjin/cfp_stat.rb', line 30

def initialize version=nil, verbose=0, trace=0, dry_run=true, quiet_mode=false, strict=false, defines=[], undefines=[]
    @version      = version
	@dry_run      = dry_run
	@strict       = strict
	@site         = Hash.new
	# Set up the main logger
	@cfp_logger	= Cfp_Logger.new self,verbose,trace,dry_run,quiet_mode
	# Set up the library logger (if not unit testing)
	@cfp_liblogger = Cfp_LibLogger.new @cfp_logger
	# ---- Set up flow monitor
	@logger = @cfp_logger
	# Only initialize flow monitor when not unit testing
	begin
		Test::Unit.class
	rescue NameError
		@cfp_controller = Cfp_FlowMonitor.new(@cfp_logger)
		@cfp_logger.trace TRACE_ALL,'Initialized engine state (Cfp_Stat)'
	end
	# ---- Get OS info
	@os           = OS::OSFactory.new.get_os
	# ---- Get package list
	if packagemanager = @os.get_package_manager()
		@packagelist = packagemanager.packages()
	end
	# ---- Get user list
	if usermanager = @os.get_user_manager()
		@usermanager = usermanager
	end
	@classlist = Cfp_ClassList.new defines,undefines
end

Instance Attribute Details

#cfp_libloggerObject (readonly)

Returns the value of attribute cfp_liblogger.



24
25
26
# File 'lib/libcfenjin/cfp_stat.rb', line 24

def cfp_liblogger
  @cfp_liblogger
end

#cfp_loggerObject (readonly)

Returns the value of attribute cfp_logger.



24
25
26
# File 'lib/libcfenjin/cfp_stat.rb', line 24

def cfp_logger
  @cfp_logger
end

#classlistObject (readonly)

Returns the value of attribute classlist.



25
26
27
# File 'lib/libcfenjin/cfp_stat.rb', line 25

def classlist
  @classlist
end

#dry_runObject

Returns the value of attribute dry_run.



26
27
28
# File 'lib/libcfenjin/cfp_stat.rb', line 26

def dry_run
  @dry_run
end

#osObject (readonly)

Returns the value of attribute os.



24
25
26
# File 'lib/libcfenjin/cfp_stat.rb', line 24

def os
  @os
end

#packagelistObject (readonly)

Returns the value of attribute packagelist.



24
25
26
# File 'lib/libcfenjin/cfp_stat.rb', line 24

def packagelist
  @packagelist
end

#siteObject

Returns the value of attribute site.



26
27
28
# File 'lib/libcfenjin/cfp_stat.rb', line 26

def site
  @site
end

#sitepathObject

Returns the value of attribute sitepath.



26
27
28
# File 'lib/libcfenjin/cfp_stat.rb', line 26

def sitepath
  @sitepath
end

#strictObject

Returns the value of attribute strict.



26
27
28
# File 'lib/libcfenjin/cfp_stat.rb', line 26

def strict
  @strict
end

#usermanagerObject (readonly)

Returns the value of attribute usermanager.



25
26
27
# File 'lib/libcfenjin/cfp_stat.rb', line 25

def usermanager
  @usermanager
end

Instance Method Details

#dev_versionObject



80
81
82
83
84
85
# File 'lib/libcfenjin/cfp_stat.rb', line 80

def dev_version
  if @version and @version =~ /dev(\d+)/
    return $1.to_i
  end
  0
end

#distributionObject



69
70
71
# File 'lib/libcfenjin/cfp_stat.rb', line 69

def distribution
	@os['distribution']
end

#hostnameObject



61
62
63
# File 'lib/libcfenjin/cfp_stat.rb', line 61

def hostname
	@os.hostname
end

#osnameObject



65
66
67
# File 'lib/libcfenjin/cfp_stat.rb', line 65

def osname
	@os['name']
end

#showtraceObject



87
88
89
90
91
# File 'lib/libcfenjin/cfp_stat.rb', line 87

def showtrace
	 @logger.trace TRACE_ON,"Trace=#{@logger.tracelevel}"
	 @logger.trace TRACE_ENGINE,"Verbose=#{@logger.verbose}"
	 @logger.trace TRACE_ENGINE,'Hostname='+hostname
end

#versionObject



73
74
75
76
77
78
# File 'lib/libcfenjin/cfp_stat.rb', line 73

def version
  if @version and @version =~ /^(\d+\.\d+)/
    return $1.to_f
  end
  1.0
end