[modify] complete rewrite of utool
This commit is contained in:
parent
1931445c13
commit
dbc0c638fd
@ -25,6 +25,7 @@ elif [[ $number =~ ^[0-9a-fA-F]{1,9}$ ]]; then
|
||||
hex=`printf "%d" '0x'$number`
|
||||
date -d@$hex +'%Y-%m-%d %H:%M:%S'
|
||||
else
|
||||
echo -e "${c_bb}-j选项:将十进制或者十六进制数字作为入参,转换成标准时间格式,只接收第一个参数,其他参数将被丢弃,有歧义时,使用'0x'或者'0X'来区分十进制和十六进制,退出...${c_e}\n"
|
||||
echo -e "${c_br}请输入正确的十进制--11位以内,或者十六进制数字--9位以内:${c_e}"
|
||||
echo -e " 十进制的时间戳 - 1678523385"
|
||||
echo -e " 十六进制时间戳 - 0x640c3bf9/0X640C3BF9/0x640C3bf9/640c3bf9"
|
||||
|
@ -7,7 +7,7 @@ import time
|
||||
def utool(option):
|
||||
|
||||
def print_usage():
|
||||
intro = """utool -- a self-defined command line interface, which is used to facilitate operating the system, supports the following options. In the description part, where there is a leading asterisk signifies that this option must take an argument, and for more information of this situation, simply run `utool -h` for details."""
|
||||
intro = """utool -- A self-defined command line interface, which is used to facilitate operating the system, supports the following options. In the description part, where there is a leading asterisk signifies that this option must take an argument, and for more information of this situation, simply run `utool -h` for details."""
|
||||
print(f"{c_intro}{intro}{c_e}")
|
||||
print("_" * 121)
|
||||
print(f"{c_title}|Option| Description{' ' * 40}|Option| Description{' ' * 40}|{c_e}")
|
||||
@ -49,6 +49,46 @@ def utool(option):
|
||||
print(f"{c_br}Plz enter correct IP...{c_e}")
|
||||
exit(ord(option.strip('-')))
|
||||
|
||||
# -e
|
||||
def gen_md5():
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}需要至少一个字符串作为输入,退出...{c_e}\n")
|
||||
exit(ord(option.strip('-')))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item
|
||||
|
||||
os.environ['param'] = param
|
||||
print(f"{c_by}Warning: 输入字符串中间的任何空白符将会被删除,要保留的话,需手动将字符串用单引号括起来{c_e}")
|
||||
print(f"本次计算MD5值的字符串为 - {param}\n本次计算得到的MD5的值为 - ", end='')
|
||||
# print(f"本次计算得到的MD5的值为 - ", end='')
|
||||
os.system('echo -n $param | md5sum | cut -d " " -f 1')
|
||||
|
||||
# -f
|
||||
def number2date():
|
||||
exit_on_wrong_number(2)
|
||||
os.environ['param'] = sys.argv[2]
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/number2d.sh $param')
|
||||
|
||||
# -g
|
||||
def date2number():
|
||||
if len(sys.argv) < 3:
|
||||
print(f"{c_br}-k选项:将输入的时间转换成十进制和十六进制,需要一个字符串格式的时间作为输入,退出...{c_e}\n")
|
||||
exit(ord(option.strip('-')))
|
||||
|
||||
param=''
|
||||
for item in sys.argv[2:]:
|
||||
param += item + ' '
|
||||
|
||||
os.environ['param'] = param
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/date2n.sh $param')
|
||||
|
||||
# -p
|
||||
def gen_passwd():
|
||||
exit_on_wrong_number(2)
|
||||
os.environ['length'] = sys.argv[2]
|
||||
os.system('/usr/bin/bash /opt/scripts/utool/genpw.sh length')
|
||||
|
||||
def exit_on_wrong_number(number=1):
|
||||
if len(sys.argv) != (number+1):
|
||||
@ -63,16 +103,16 @@ def utool(option):
|
||||
'-b': [' generate two-factor key of GITHUB', github_two_factor],
|
||||
'-o': ['Reserved', None],
|
||||
'-c': [' show external IP of this machine', get_external_ip],
|
||||
'-p': ['Reserved', None],
|
||||
'-p': ['*generate password of length 1~79', gen_passwd],
|
||||
'-d': [' show the location of ip(only v4 for now)', get_ip_location],
|
||||
'-q': ['Reserved', None],
|
||||
'-e': ['Reserved', None],
|
||||
'-e': ['*generate md5 value of the input string', gen_md5],
|
||||
'-r': ['Reserved', None],
|
||||
'-f': ['Reserved', None],
|
||||
'-f': ['*convert a (hexa)decimal to specific time format', number2date],
|
||||
'-s': ['Reserved', None],
|
||||
'-g': ['Reserved', None],
|
||||
'-g': ['*convert multi-formats time to a decimal', date2number],
|
||||
'-t': ['Reserved', None],
|
||||
'-h': ['Reserved', print_usage],
|
||||
'-h': [' show this help information and exit', print_usage],
|
||||
'-u': ['Reserved', None],
|
||||
'-i': ['Reserved', None],
|
||||
'-v': ['Reserved', None],
|
||||
@ -90,7 +130,6 @@ def utool(option):
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
global option
|
||||
options = [ '-' + chr(x) for x in range(ord('a'), ord('z')+1)]
|
||||
print_usage = utool('-h')
|
||||
@ -108,6 +147,7 @@ def main():
|
||||
else:
|
||||
print_usage()
|
||||
|
||||
# global area below ↓
|
||||
c_title = '\033[1;4;37;40m' # title color
|
||||
c_text = '\033[37;40m' # text color
|
||||
c_intro = '\033[3;32m' # text color
|
||||
|
Loading…
x
Reference in New Issue
Block a user