diff options
author | xiubuzhe <xiubuzhe@sina.com> | 2023-10-15 23:51:49 +0800 |
---|---|---|
committer | xiubuzhe <xiubuzhe@sina.com> | 2023-10-15 23:51:49 +0800 |
commit | 6cb42d6b8d889a832c19b6e0f58d29af78009d99 (patch) | |
tree | ffcfd95f189b324cfe149b152612ea64551ecf4e /lib | |
parent | 98fae3427e6791003e64572a2a6ca317c72473ef (diff) | |
download | sunhpc-6cb42d6b8d889a832c19b6e0f58d29af78009d99.tar.gz sunhpc-6cb42d6b8d889a832c19b6e0f58d29af78009d99.tar.bz2 sunhpc-6cb42d6b8d889a832c19b6e0f58d29af78009d99.zip |
add bash-complete scripts
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sunhpc/commands/__init__.py | 19 | ||||
-rw-r--r-- | lib/sunhpc/commands/list/help/__init__.py | 1 | ||||
-rw-r--r-- | lib/sunhpc/commands/report/completion/__init__.py | 116 | ||||
-rw-r--r-- | lib/sunhpc/commands/soft/autodock/__init__.py | 5 |
4 files changed, 136 insertions, 5 deletions
diff --git a/lib/sunhpc/commands/__init__.py b/lib/sunhpc/commands/__init__.py index a8c6c5b..744273e 100644 --- a/lib/sunhpc/commands/__init__.py +++ b/lib/sunhpc/commands/__init__.py @@ -14,7 +14,6 @@ import socket import syslog import struct import sqlite3 -import termios import argparse import textwrap import datetime @@ -38,10 +37,8 @@ DEFAULT_HELP_WIDTH = 8 def get_help_width(): try: - data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234') - columns = int(struct.unpack('hh', data)[1]) + (columns, heigh) = shutil.get_terminal_size() except (IOError, ValueError) as e: - print ("terminal size detection failed, using default width.") return DEFAULT_HELP_WIDTH columns = columns - RIGHT_PADDING @@ -1255,8 +1252,22 @@ class Command(object): o.runWrapper(n, args) return o.getText() + def remove_empty_values(self, input_list): + """ + 从列表中删除空值 + + :param input_list: 输入的列表 + :return: 不包含空值的新列表 + """ + # 使用列表推导式过滤掉空值 + result_list = [value for value in input_list if value is not None and value != ""] + return result_list + def runWrapper(self, name, args): + # 删除所有空值和None. + args = self.remove_empty_values(args) + username = pwd.getpwuid(os.geteuid())[0] if args: command = '%s %s' % (name, ' '.join(args)) diff --git a/lib/sunhpc/commands/list/help/__init__.py b/lib/sunhpc/commands/list/help/__init__.py index a8e230a..f7f31dd 100644 --- a/lib/sunhpc/commands/list/help/__init__.py +++ b/lib/sunhpc/commands/list/help/__init__.py @@ -25,6 +25,7 @@ class Command(sunhpc.commands.list.command): def run(self, params, args): (subdir, cols) = self.fillParams([('subdir', ), ('cols', 80) ], params) + if subdir: filepath = os.path.join(sunhpc.commands.__path__[0], subdir) modpath = 'sunhpc.commands.%s' % '.'.join(subdir.split(os.sep)) diff --git a/lib/sunhpc/commands/report/completion/__init__.py b/lib/sunhpc/commands/report/completion/__init__.py new file mode 100644 index 0000000..aa75f40 --- /dev/null +++ b/lib/sunhpc/commands/report/completion/__init__.py @@ -0,0 +1,116 @@ +#coding:utf-8 + +import os +import sys +import json +import sunhpc +class Command(sunhpc.commands.report.command): + """ + Output the path prefix for the location of the Rocks distribution. + + <example cmd='report distro'> + Output the current path prefix to the distribution. + </example> + """ + def run(self, params, args): + + basepath = '/opt/sunhpc/lib' + + cmd = args + dotscmd = '' + listcmd = [] + module = None + if len(cmd): + s = 'sunhpc.commands.%s' % '.'.join(cmd) + try: + __import__(s) + module, listcmd, dotscmd = eval(s), s.split('.'), '.'.join(cmd) + i = 1 + except: + module = None + else: + listcmd = ['sunhpc', 'commands'] + + if not module: + for i in range(len(args), 0, -1): + s = 'sunhpc.commands.%s' % '.'.join(args[:i]) + try: + __import__(s) + module, listcmd, dotscmd = eval(s), s.split('.'), '.'.join(args[:i]) + if module: + break + except ImportError: + listcmd = s.split('.')[:-1] + continue + + cmdpath = os.path.join(basepath, '/'.join(listcmd)) + + cmddirs = [] + for d in os.listdir(cmdpath): + tmpdirs = os.path.join(cmdpath, d) + + if d.startswith('__'): + continue + + if not os.path.isdir(tmpdirs): + continue + + cmddirs.append(d) + + print (' '.join(cmddirs)) + + try: + o = getattr(module, 'Command')(None) + except AttributeError: + sys.exit(0) + + if o.MustBeRoot and not self.isRootUser(): + sys.exit(0) + + + results = [] + for arg in o.usage().split(): + tmp = arg.split('=', 1) + if len(tmp) != 2: + continue + + tmpstr = arg.replace('[', '') + tmpstr = tmpstr.replace(']', '') + tmpstr = tmpstr.split('=')[0] + '=' + + results.append(tmpstr) + + #print (' '.join(results)) + + #print ('--add-interface= --set-net=') + print ('--envs= prefix=') + + +RollName = "base" + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/sunhpc/commands/soft/autodock/__init__.py b/lib/sunhpc/commands/soft/autodock/__init__.py index f67f372..61ad54b 100644 --- a/lib/sunhpc/commands/soft/autodock/__init__.py +++ b/lib/sunhpc/commands/soft/autodock/__init__.py @@ -51,7 +51,10 @@ class Command(command): softname = 'autodock' suffname = 'tar.gz' dirsname = os.path.join(source, 'hpcsoft', 'AutoDock') - verslist = self.getVersions(key=softname, suffix=suffname, dirs=dirsname) + try: + verslist = self.getVersions(key=softname, suffix=suffname, dirs=dirsname) + except FileNotFoundError as e: + self.msg(str(e), 'a') if len(args): version = args[0] |