Class: Babushka::SystemProfile

Inherits:
Object
  • Object
show all
Extended by:
ShellHelpers
Includes:
ShellHelpers
Defined in:
lib/babushka/system_profile.rb

Direct Known Subclasses

LinuxSystemProfile, OSXSystemProfile

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from ShellHelpers

cmd_dir, failable_shell, log_shell, login_shell, raw_shell, shell, shell!, shell?, sudo, which

Methods included from LogHelpers

#debug, #log, #log_block, #log_error, #log_ok, #log_verbose, #log_warn

Class Method Details

+ (Object) for_flavour



13
14
15
# File 'lib/babushka/system_profile.rb', line 13

def self.for_flavour
  new
end

+ (Object) for_host



6
7
8
9
10
11
# File 'lib/babushka/system_profile.rb', line 6

def self.for_host
  {
    'Linux' => LinuxSystemProfile,
    'Darwin' => OSXSystemProfile
  }[shell('uname -s')].try(:for_flavour)
end

Instance Method Details

- (Object) cpu_type



30
31
32
33
34
35
36
37
# File 'lib/babushka/system_profile.rb', line 30

def cpu_type
  shell('uname -p').tap {|result|
    result.replace shell('uname -m') if result[/unknown|\s/]
    # These replacements are taken from PhusionPassenger::PlatformInfo.cpu_architectures
    result.replace 'x86' if result[/^i.86$/]
    result.replace 'x86_64' if result == 'amd64'
  }
end

- (Object) description



43
44
45
46
47
48
49
50
# File 'lib/babushka/system_profile.rb', line 43

def description
  [
    (flavour_str unless flavour_str == system_str),
    system_str,
    version,
    ("(#{name_str})" unless name_str.nil?)
  ].compact.join(' ')
end

- (Object) differentiator_for(specs)



83
84
85
86
87
88
89
90
# File 'lib/babushka/system_profile.rb', line 83

def differentiator_for specs
  nonmatches = [*specs].map {|spec|
    first_nonmatch_for spec
  }.sort_by {|spec|
    [:system, :flavour, :name].index spec
  }.compact
  send "#{nonmatches.last}_str" unless nonmatches.empty?
end

- (Object) first_nonmatch_for(spec)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/babushka/system_profile.rb', line 67

def first_nonmatch_for spec
  if spec == :all
    nil
  elsif SystemDefinitions.all_systems.include? spec
    spec == system ? nil : :system
  elsif PkgHelper.all_manager_keys.include? spec
    spec == pkg_helper_key ? nil : :pkg_helper
  elsif our_flavours.include? spec
    spec == flavour ? nil : :flavour
  elsif our_flavour_names.include? spec
    spec == name ? nil : :name
  else
    :system
  end
end

- (Object) flavour_str_map



99
100
101
102
103
104
105
106
107
108
# File 'lib/babushka/system_profile.rb', line 99

def flavour_str_map
  # Only required for names that can't be auto-capitalized,
  # e.g. :ubuntu => 'Ubuntu' isn't required.
  {
    :linux => {
      :centos => 'CentOS',
      :redhat => 'Red Hat'
    }
  }
end

- (Object) library_ext

The extension that dynamic libraries are given on this system. On linux libraries are named like 'libssl.so'; on OS X, 'libssl.bundle'.



28
# File 'lib/babushka/system_profile.rb', line 28

def library_ext; 'so' end

- (Boolean) linux?

Returns:

  • (Boolean)


21
# File 'lib/babushka/system_profile.rb', line 21

def linux?; false end

- (Object) match_list



59
60
61
# File 'lib/babushka/system_profile.rb', line 59

def match_list
  [name, flavour, pkg_helper_key, system, :all].compact
end

- (Boolean) matches?(specs)

Returns:

  • (Boolean)


63
64
65
# File 'lib/babushka/system_profile.rb', line 63

def matches? specs
  [*specs].any? {|spec| first_nonmatch_for(spec).nil? }
end

- (Object) name



52
53
54
# File 'lib/babushka/system_profile.rb', line 52

def name
  (SystemDefinitions.names[system][flavour] || {})[release]
end

- (Object) name_str



55
56
57
# File 'lib/babushka/system_profile.rb', line 55

def name_str
  (SystemDefinitions.descriptions[system][flavour] || {})[release]
end

- (Boolean) osx?

Returns:

  • (Boolean)


22
# File 'lib/babushka/system_profile.rb', line 22

def osx?; false end

- (Object) our_flavour_names



95
96
97
# File 'lib/babushka/system_profile.rb', line 95

def our_flavour_names
  SystemDefinitions.names[system][flavour].values
end

- (Object) our_flavours



92
93
94
# File 'lib/babushka/system_profile.rb', line 92

def our_flavours
  SystemDefinitions.names[system].keys
end

- (Object) pkg_helper



23
# File 'lib/babushka/system_profile.rb', line 23

def pkg_helper; nil end

- (Object) pkg_helper_key



24
# File 'lib/babushka/system_profile.rb', line 24

def pkg_helper_key; pkg_helper.try(:manager_key) end

- (Object) pkg_helper_str



25
# File 'lib/babushka/system_profile.rb', line 25

def pkg_helper_str; pkg_helper_key.to_s.capitalize end

- (Object) total_memory



39
40
41
# File 'lib/babushka/system_profile.rb', line 39

def total_memory
  raise "#{self.class}#total_memory is unimplemented."
end

- (Object) version_info



17
18
19
# File 'lib/babushka/system_profile.rb', line 17

def version_info
  @_version_info ||= get_version_info
end