add grub command

This commit is contained in:
2023-10-11 18:33:26 +08:00
parent 5e70554a44
commit 4e37223538
2 changed files with 63 additions and 6 deletions

View File

@@ -653,7 +653,7 @@ class Command(object):
#print("\033[92m[+]\033[0m \033[96m%s\033[0m" % (msg)) #print("\033[92m[+]\033[0m \033[96m%s\033[0m" % (msg))
print("\033[92m[+]\033[0m %s" % (msg)) print("\033[92m[+]\033[0m %s" % (msg))
def message(self, msg, tag='[+]', end=''): def message(self, tag='[+]', msg=' ', end=' '):
header = '\033[92m%s\033[0m' % tag header = '\033[92m%s\033[0m' % tag
ender = '\033[95m%s\033[0m' % end ender = '\033[95m%s\033[0m' % end
msger = '\033[31m%s\033[0m' % msg msger = '\033[31m%s\033[0m' % msg
@@ -856,7 +856,7 @@ class Command(object):
w, r ,e = (p.stdin, p.stdout, p.stderr) w, r ,e = (p.stdin, p.stdout, p.stderr)
currLength = 0 currLength = 0
prevLength = 0 prevLength = 0
spinChars = '-\|/' spinChars = r'-\|/'
spinIndex = 0 spinIndex = 0
while 1: while 1:
line = e.readline().decode() line = e.readline().decode()
@@ -1269,7 +1269,7 @@ class Command(object):
pdict = {} pdict = {}
plist = [] plist = []
nparams = 0 nparams = 0
flagpattern=re.compile("^[a-zA-z0-9\-_+]+=") flagpattern=re.compile(r"^[a-zA-z0-9\-_+]+=")
for arg in args: for arg in args:
tokens = arg.split() tokens = arg.split()
if tokens[0] == 'select': if tokens[0] == 'select':
@@ -1543,7 +1543,7 @@ class DocStringHandler(
s += '*[%s]*' % name s += '*[%s]*' % name
else: else:
s += '*{%s}*' % name s += '*{%s}*' % name
txt = txt.replace('*', '\*') txt = txt.replace('*', '\\*')
s += '\n%s\n' % txt.replace('\t', ' ') s += '\n%s\n' % txt.replace('\t', ' ')
if self.section['param']: if self.section['param']:
s += '\n**Parameters:**\n\n' s += '\n**Parameters:**\n\n'
@@ -1553,12 +1553,12 @@ class DocStringHandler(
s += '*[%s=%s]*' % (name, type) s += '*[%s=%s]*' % (name, type)
else: else:
s += '*{%s=%s}*' % (name, type) s += '*{%s=%s}*' % (name, type)
txt = txt.replace('*', '\*') txt = txt.replace('*', '\\*')
s += '\n%s\n' % txt.replace('\t', ' ') s += '\n%s\n' % txt.replace('\t', ' ')
if self.section['example']: if self.section['example']:
s += '\n**Examples:**\n' s += '\n**Examples:**\n'
for (cmd, txt) in self.section['example']: for (cmd, txt) in self.section['example']:
txt = txt.replace('*', '\*') txt = txt.replace("*", "\\*")
s += '%s::\n\n' % txt.replace('\t',' ') s += '%s::\n\n' % txt.replace('\t',' ')
s += ' %s sunhpc %s\n' % (prompt, cmd) s += ' %s sunhpc %s\n' % (prompt, cmd)
if self.section['related']: if self.section['related']:

View File

@@ -0,0 +1,57 @@
#coding:utf-8
import os
import sys
import sunhpc
class command(sunhpc.commands.HostArgumentProcessor,
sunhpc.commands.set.command):
pass
class Command(command):
"""
Grub2 boot configure
<param type='strings' name='default'>
Set the default boot options
</param>
<example cmd='grub default=1'>
Set the default boot options index 1
</example>
"""
def run(self, params, args):
(default, ) = self.fillParams([
('default', None),
])
if default:
try:
default_number = int(default)
#self.msg('Please modify it manually by using the command: grubby --set-defautl-index=%s' % default)
info = self.message('[*]', 'Please modify it manually by using the command:', 'grubby --set-default-index=%s' % default)
print (info)
sys.exit(0)
except ValueError:
self.msg('The "default" parameters must be the numbers.', 'a')
current_kernel = os.popen('uname -r').read().strip()
self.msg('--> Current kernel: %s' % current_kernel)
default_kernel = os.popen('grubby --default-kernel').read().strip()
self.msg('--> Default kernel: %s' % default_kernel)
kernel_index = os.popen('grubby --default-index').read().strip()
self.msg('--> Default kernel index: %s' % kernel_index)
kernel_list = os.popen('grubby --info=ALL').readlines()
self.msg('')
self.msg('-------- All Kernel List begin----------')
for i in kernel_list:
self.msg(i.strip())
self.msg('-------- All Kernel List ender----------')
self.msg('')
self.msg('Using index number, you can change the default boot kernel.e,g.. sunhpc set grub default=1', 'i')
RollName = "base"