Module: Yast::UsersRoutinesInclude

Defined in:
../../src/include/users/routines.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) GetInt(value, default_value)

helper function: return the 'any' value as integer



44
45
46
47
48
49
50
51
52
# File '../../src/include/users/routines.rb', line 44

def GetInt(value, default_value)
  value = deep_copy(value)
  return default_value if value == nil
  return Convert.to_integer(value) if Ops.is_integer?(value)
  if Ops.is_string?(value) && !value.empty?
    return value.to_i
  end
  default_value
end

- (Object) GetString(value, default_value)

helper function: return the 'any' value as string



55
56
57
58
59
# File '../../src/include/users/routines.rb', line 55

def GetString(value, default_value)
  value = deep_copy(value)
  return default_value if value == nil
  Builtins.sformat("%1", value)
end

- (Object) initialize_users_routines(include_target)



31
32
33
34
35
# File '../../src/include/users/routines.rb', line 31

def initialize_users_routines(include_target)
  Yast.import "Mode"

  textdomain "users"
end

- (Object) installation

check if this is installation stage - adding user during firstboot should be same as during 2nd stage



39
40
41
# File '../../src/include/users/routines.rb', line 39

def installation
  Stage.cont || Stage.firstboot
end

- (String) SplitFullName(what, cn)

Split cn (fullname) in forename and surname.

Parameters:

  • what (Symbol)

    surname orforename

  • cn (String)

    fullname

  • type

    user type

Returns:

  • (String)

    selected part of user name



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
# File '../../src/include/users/routines.rb', line 67

def SplitFullName(what, cn)
  cn = "" if cn == nil

  # if cn is to be substituted, do not try to resolve givenName/sn
  return "" if Builtins.issubstring(cn, "%")

  strs = Builtins.splitstring(cn, " ")
  i = 1
  sn = ""
  givenName = ""

  Builtins.foreach(strs) do |str|
    if Ops.less_than(i, Builtins.size(strs))
      if givenName == ""
        givenName = str
      else
        givenName = Ops.add(Ops.add(givenName, " "), str)
      end
    else
      sn = str
    end
    i = Ops.add(i, 1)
  end
  return sn if what == :sn
  return givenName if what == :givenName

  nil
end

- (Object) UserLogged(name)

if the user has log on system



97
98
99
100
101
102
103
104
105
106
# File '../../src/include/users/routines.rb', line 97

def UserLogged(name)
  out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("ps --no-headers -u %1", name)
    )
  )
  proc = Ops.get_string(out, "stdout", "")
  Builtins.size(proc) != 0 && !Mode.config
end