Skip to content

Commit 012df43

Browse files
committed
update some UI for easy use
1 parent 9b8bfb9 commit 012df43

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

projects/WindowsSystemOps/Account/windows-user-accounts-manager.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
Created by PyCharm.
55
File Name: LinuxBashShellScriptForOps:windows-user-accounts-manager.py
6-
Version: 0.0.3
6+
Version: 0.0.4
77
Author: dgden
88
Author Email: dgdenterprise@gmail.com
99
URL: https://github.com/DingGuodong/LinuxBashShellScriptForOps
@@ -84,6 +84,37 @@ def get_ip_with_ends(num):
8484
return item
8585

8686

87+
def get_ip_with_ends_u1(num):
88+
"""
89+
get full ip address with ip from config.json, ip num can be fourth part or full ip, such as '3' in '192.168.1.3'
90+
:param num: ip
91+
:type num: str | int
92+
:return: ip
93+
:rtype: str
94+
"""
95+
if isinstance(num, int):
96+
num = str(num)
97+
98+
if servers is None:
99+
raise KeyError("no servers is found")
100+
101+
keys_list = servers.keys()
102+
keys_found_list = list()
103+
for item in keys_list: # type: str
104+
item = item.strip()
105+
if item.endswith(num):
106+
keys_found_list.append(item)
107+
if len(keys_found_list) > 1:
108+
print("warning: more than one server is found, "
109+
"please use full ip addr instead last part.")
110+
return keys_found_list[0]
111+
elif len(keys_found_list) == 1:
112+
return keys_found_list[0]
113+
else:
114+
raise RuntimeError("no server is found, "
115+
"please use full ip addr instead last part or check the config.json file.")
116+
117+
87118
def get_acc_psw_with_ends(num):
88119
"""
89120
get full ip address, username and password with given ip num from config.json
@@ -95,7 +126,7 @@ def get_acc_psw_with_ends(num):
95126
if isinstance(num, int):
96127
num = str(num)
97128

98-
ip_addr = get_ip_with_ends(num)
129+
ip_addr = get_ip_with_ends_u1(num)
99130
account = servers[ip_addr].get("account")
100131
password = servers[ip_addr].get("password")
101132
return ip_addr, account, password
@@ -396,7 +427,7 @@ def query_account_status_u1(server, name):
396427
print("WARN: account {} in IP {} may has an issue, "
397428
"such as `requests.exceptions.ConnectionError`, "
398429
u"error detail: {}.".format(name, ip, std_err.decode('gbk')))
399-
return None, std_err.st
430+
return None, std_err
400431

401432
message = std_out.strip()
402433
if message == "":
@@ -431,6 +462,15 @@ def main_change_account_status(ip=250, user='kurt'):
431462

432463

433464
def main_change_account_status_u1(ip=250, user='kurt'):
465+
"""
466+
467+
:param ip:
468+
:type ip: str | int
469+
:param user:
470+
:type user:
471+
:return:
472+
:rtype:
473+
"""
434474
import sys
435475
print("exec time: {}".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))))
436476
is_account_enabled, message = query_account_status_u1(ip, user)

0 commit comments

Comments
 (0)