MKP 1.0.6, added type hints
This commit is contained in:
parent
abff64b3b5
commit
b3115ea001
@ -83,19 +83,29 @@ def debugLog(function):
|
||||
local_time = strftime(TIMEFMT,localtime(start))
|
||||
# get function name
|
||||
fname = function.__name__
|
||||
# create output
|
||||
# out1: Timestamp|Name of Function|Runtime|Num Args|Num Kwargs|Return Value|Return Value Type
|
||||
out1 = f"{local_time}{SEP}{fname}{SEP}{seconds}{SEP}{len_args}{SEP}{len_kwargs}{SEP}{value}{SEP}{type(value)}"
|
||||
# out2: all arguments
|
||||
out2 = ""
|
||||
for arg in args:
|
||||
out2 = out2 + SEP + str(arg)
|
||||
# out 3: all keyowrd arguments
|
||||
# out 3: all keyword arguments
|
||||
out3 = ""
|
||||
if len_kwargs > 0:
|
||||
for key, val in kwargs.items():
|
||||
out3 = out3 + SEP + key + ":" + str(val)
|
||||
# write output to file
|
||||
if debugLogFilename != "":
|
||||
try:
|
||||
with open(debugLogFilename, "a") as f:
|
||||
f.write(f"{out1}{out2}{out3}\n")
|
||||
except:
|
||||
sys.stderr.write(f"Something went wrong when writing to file {debugLogFilename}\n")
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.stderr.write(f"Debug activated, but no debug filename given.\n")
|
||||
sys.exit(1)
|
||||
return value
|
||||
return wrapper
|
||||
|
||||
@ -149,7 +159,7 @@ long_options = [
|
||||
'hostname=', 'username=', 'password=', 'help'
|
||||
]
|
||||
|
||||
def createDebugFilename(hostname):
|
||||
def getDebugFilename(hostname: str) -> str:
|
||||
home_path = os.getenv("HOME")
|
||||
tmp_path = f"{home_path}/tmp"
|
||||
file_name = f"{tmp_path}/hal9001_{hostname}_debug.log"
|
||||
@ -178,7 +188,7 @@ def showOptions():
|
||||
print(f"Password: {opt_password}")
|
||||
|
||||
#@debugLog
|
||||
def calculateNewUserStorage(current_storage):
|
||||
def calculateNewUserStorage(current_storage: float) -> float:
|
||||
# let the chance that no change occured be at 90%
|
||||
no_change = random.randint(1, 100)
|
||||
if no_change > 10:
|
||||
@ -200,7 +210,7 @@ def calculateNewUserStorage(current_storage):
|
||||
return float(new_storage)
|
||||
|
||||
#@debugLog
|
||||
def calculateNewStorageCounters(ul_bytes, dl_bytes):
|
||||
def calculateNewStorageCounters(ul_bytes: float, dl_bytes: float) -> tuple:
|
||||
# let the chance that no change occured be at 2%
|
||||
no_change = random.randint(1, 100)
|
||||
if no_change > 98:
|
||||
@ -219,12 +229,12 @@ def calculateNewStorageCounters(ul_bytes, dl_bytes):
|
||||
return float(new_ul_bytes), float(new_dl_bytes)
|
||||
|
||||
#@debugLog
|
||||
def doCmkHalStatusOutput(status, version, username, ipaddress):
|
||||
def doCmkHalStatusOutput(status: str, version: str, username: str, ipaddress: str) -> None:
|
||||
print("<<<hal9001_status:sep(59)>>>")
|
||||
print(f"{status};{version};{username};{ipaddress}")
|
||||
|
||||
#@debugLog
|
||||
def doCmkHalUsersOutput(users, hostname):
|
||||
def doCmkHalUsersOutput(users: dict, hostname: str) -> None:
|
||||
print("<<<hal9001_users:sep(59)>>>")
|
||||
home_path = os.getenv("HOME")
|
||||
tmp_path = f"{home_path}/tmp"
|
||||
@ -251,7 +261,7 @@ def doCmkHalUsersOutput(users, hostname):
|
||||
print(f"{user};{realname};{new_storage};{quota_max}")
|
||||
|
||||
#@debugLog
|
||||
def doCmkHalStoragesOutput(storages, hostname):
|
||||
def doCmkHalStoragesOutput(storages: dict, hostname: str) -> None:
|
||||
print("<<<hal9001_storages:sep(59)>>>")
|
||||
home_path = os.getenv("HOME")
|
||||
tmp_path = f"{home_path}/tmp"
|
||||
@ -290,7 +300,7 @@ def doCmkHalStoragesOutput(storages, hostname):
|
||||
print(f"{storage};{realname};{new_ul_bytes};{new_dl_bytes}")
|
||||
|
||||
#@debugLog
|
||||
def getStatus():
|
||||
def getStatus() -> tuple:
|
||||
# randomly set one of the three available states
|
||||
status_index = random.randint(1,100)
|
||||
if status_index <= 5:
|
||||
@ -305,7 +315,7 @@ def getStatus():
|
||||
return hal_status, hal_version
|
||||
|
||||
#@debugLog
|
||||
def doLogin(hostname, username, password):
|
||||
def doLogin(hostname: str, username: str, password: str) -> tuple:
|
||||
# simulate the login to our HAL system
|
||||
# give it a chance of 2% to fail to demonstrate an error from time to time
|
||||
success = random.randint(1, 100)
|
||||
@ -332,7 +342,7 @@ def main():
|
||||
sys.stderr.write(f"No password given.\n")
|
||||
showUsage()
|
||||
sys.exit(1)
|
||||
debugLogFilename = createDebugFilename(opt_hostname)
|
||||
debugLogFilename = getDebugFilename(opt_hostname)
|
||||
success, code = doLogin(opt_hostname, opt_username, opt_password)
|
||||
if success:
|
||||
status, version = getStatus()
|
||||
|
BIN
mkp/hal9001-1.0.6.mkp
Normal file
BIN
mkp/hal9001-1.0.6.mkp
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user