Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

# 

# flags.py: global anaconda flags 

# 

# Copyright (C) 2001 Red Hat, Inc. All rights reserved. 

# 

# This program is free software; you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation; either version 2 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

# 

 

import selinux 

import shlex 

import glob 

from pyanaconda.core.constants import SELINUX_DEFAULT, CMDLINE_APPEND, ANACONDA_ENVIRON 

from collections import OrderedDict 

 

from pyanaconda.anaconda_loggers import get_module_logger 

log = get_module_logger(__name__) 

 

# A lot of effort, but it only allows a limited set of flags to be referenced 

class Flags(object): 

def __setattr__(self, attr, val): 

# pylint: disable=no-member 

if attr not in self.__dict__ and not self._in_init: 

raise AttributeError(attr) 

else: 

self.__dict__[attr] = val 

 

def get(self, attr, val=None): 

return getattr(self, attr, val) 

 

def set_cmdline_bool(self, flag): 

if flag in self.cmdline: 

setattr(self, flag, self.cmdline.getbool(flag)) 

 

def __init__(self, read_cmdline=True): 

self.__dict__['_in_init'] = True 

self.livecdInstall = False 

self.ibft = True 

self.usevnc = False 

self.vncquestion = True 

self.mpath = True 

self.dmraid = True 

self.selinux = SELINUX_DEFAULT 

self.debug = False 

self.armPlatform = None 

self.preexisting_x11 = False 

self.noverifyssl = False 

self.imageInstall = False 

self.automatedInstall = False 

self.dirInstall = False 

self.askmethod = False 

self.eject = True 

self.extlinux = False 

self.nombr = False 

self.gpt = False 

self.leavebootorder = False 

self.testing = False 

self.mpathFriendlyNames = True 

# ksprompt is whether or not to prompt for missing ksdata 

self.ksprompt = True 

self.rescue_mode = False 

self.noefi = False 

self.kexec = False 

# nosave options 

self.nosave_input_ks = False 

self.nosave_output_ks = False 

self.nosave_logs = False 

# single language options 

self.singlelang = False 

# enable SE/HMC 

self.hmc = False 

# current runtime environments 

self.environs = [ANACONDA_ENVIRON] 

# parse the boot commandline 

self.cmdline = BootArgs() 

# Lock it down: no more creating new flags! 

self.__dict__['_in_init'] = False 

if read_cmdline: 

self.read_cmdline() 

 

def read_cmdline(self): 

for f in ("selinux", "debug", "leavebootorder", "testing", "extlinux", 

"nombr", "gpt", "noefi"): 

self.set_cmdline_bool(f) 

 

if not selinux.is_selinux_enabled(): 

self.selinux = 0 

 

cmdline_files = ['/proc/cmdline', '/run/install/cmdline', 

'/run/install/cmdline.d/*.conf', '/etc/cmdline'] 

class BootArgs(OrderedDict): 

""" 

Hold boot arguments as an OrderedDict. 

""" 

def __init__(self, cmdline=None, files=None): 

""" 

Create a BootArgs object. 

Reads each of the "files", then parses "cmdline" if it was provided. 

""" 

super().__init__() 

if files is None: 

self.read(cmdline_files) 

elif files: 

self.read(files) 

if cmdline: 

self.readstr(cmdline) 

 

def read(self, filenames): 

""" 

Read and parse a filename (or a list of filenames). 

Files that can't be read are silently ignored. 

Returns a list of successfully read files. 

filenames can contain \\*, ?, and character ranges expressed with [] 

""" 

 

readfiles = [] 

if isinstance(filenames, str): 

filenames = [filenames] 

 

# Expand any filename globs 

filenames = [f for g in filenames for f in glob.glob(g)] 

 

for f in filenames: 

try: 

self.readstr(open(f).read()) 

readfiles.append(f) 

except IOError: 

continue 

return readfiles 

 

def readstr(self, cmdline): 

cmdline = cmdline.strip() 

# if the BOOT_IMAGE contains a space, pxelinux will strip one of the 

# quotes leaving one at the end that shlex doesn't know what to do 

# with 

(left, middle, right) = cmdline.rpartition("BOOT_IMAGE=") 

if right.count('"') % 2: 

cmdline = left + middle + '"' + right 

 

# shlex doesn't properly handle \\ (it removes them) 

# which scrambles the spaces used in labels so use underscores 

cmdline = cmdline.replace("\\x20", "_") 

 

lst = shlex.split(cmdline) 

 

# options might have the inst. prefix (used to differentiate 

# boot options for the installer from other boot options) 

inst_prefix = "inst." 

 

for i in lst: 

# drop the inst. prefix (if found), so that getbool() works 

# consistently for both "foo=0" and "inst.foo=0" 

if i.startswith(inst_prefix): 

i = i[len(inst_prefix):] 

 

if "=" in i: 

(key, val) = i.split("=", 1) 

else: 

key = i 

val = None 

 

# Some duplicate args create a space separated string 

if key in CMDLINE_APPEND and self.get(key, None): 

if val: 

self[key] = self[key] + " " + val 

else: 

self[key] = val 

 

def getbool(self, arg, default=False): 

""" 

Return the value of the given arg, as a boolean. The rules are: 

- "arg", "arg=val": True 

- "noarg", "noarg=val", "arg=[0|off|no]": False 

""" 

result = default 

for a in self: 

if a == arg: 

if self[arg] in ("0", "off", "no"): 

result = False 

else: 

result = True 

elif a == 'no' + arg: 

result = False # XXX: should noarg=off -> True? 

return result 

 

def can_touch_runtime_system(msg, touch_live=False): 

""" 

Guard that should be used before doing actions that modify runtime system. 

 

:param msg: message to be logged in case that runtime system cannot be touched 

:type msg: str 

:param touch_live: whether to allow touching liveCD installation system 

:type touch_live: bool 

:rtype: bool 

 

""" 

 

if flags.livecdInstall and not touch_live: 

log.info("Not doing '%s' in live installation", msg) 

return False 

 

if flags.imageInstall: 

log.info("Not doing '%s' in image installation", msg) 

return False 

 

if flags.dirInstall: 

log.info("Not doing '%s' in directory installation", msg) 

return False 

 

if flags.testing: 

log.info("Not doing '%s', because we are just testing", msg) 

return False 

 

return True 

 

flags = Flags()