Class: Cfruby::OS::Linux
- Defined in:
- lib/libcfruby/osmodules/linux-generic.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
an alternative to calling lookup.
-
#get_package_manager ⇒ Object
returns an object implementing the PackageManager interface as appropriate for the default package management system for a given OS.
-
#get_user_manager ⇒ Object
Returns a UserManager object specific to OS X.
-
#initialize ⇒ Linux
constructor
A new instance of Linux.
-
#lookup(key) ⇒ Object
returns the value of the given key for this OS.
Methods inherited from OS
#get_process_manager, #get_scheduler, #method_missing, #to_s
Constructor Details
#initialize ⇒ Linux
Returns a new instance of Linux.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/libcfruby/osmodules/linux-generic.rb', line 10 def initialize() @keys = Hash.new() @keys['name'] = 'Linux' unameoutput = `uname -v` @keys['version'] = `cat /proc/version`.strip if File.exist? '/etc/HOSTNAME' @keys['hostname'] = `cat /etc/HOSTNAME`.strip elsif File.exist? '/etc/hostname' @keys['hostname'] = `cat /etc/hostname`.strip end # ---- figure distribution @keys['distribution'] = 'unknown' version = `cat /proc/version`.strip @keys['distribution'] = 'debianlinux' if version =~ /Debian/ @keys['distribution'] = 'rocklinux' if version =~ /[Rr]ock/ Cfruby.controller.inform('debug', "Distro #{self['distribution']}") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cfruby::OS::OS
Instance Method Details
#[](key) ⇒ Object
an alternative to calling lookup
70 71 72 |
# File 'lib/libcfruby/osmodules/linux-generic.rb', line 70 def [](key) return(lookup(key)) end |
#get_package_manager ⇒ Object
returns an object implementing the PackageManager interface as appropriate for the default package management system for a given OS
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/libcfruby/osmodules/linux-generic.rb', line 34 def get_package_manager() # look for portage if(File.executable?('/usr/bin/emerge') and File.directory?('/usr/portage')) return(Packages::PortagePackageManager.new()) end # look for apt if(File.executable?('/usr/bin/apt-get')) return(Packages::AptPackageManager.new()) end Cfruby.controller.inform('debug', "No package manager available") return(nil) end |
#get_user_manager ⇒ Object
Returns a UserManager object specific to OS X
51 52 53 |
# File 'lib/libcfruby/osmodules/linux-generic.rb', line 51 def get_user_manager() return(Users::LinuxUserManager.new()) end |
#lookup(key) ⇒ Object
returns the value of the given key for this OS. At a minimum an OS should provide the following:
- name
-
returns the name of the OS
- version
-
the version of the OS
- osname
-
e.g. freebsd, linux, windows, etc - these should return true and be case insensitive to allow
lookups of the form lookup(‘Windows’) In addition to the above name and version should be implemented as getter methods for convenience
64 65 66 |
# File 'lib/libcfruby/osmodules/linux-generic.rb', line 64 def lookup(key) return(@keys[key]) end |