MKP 1.0.7, extended type hints, added file error handling
This commit is contained in:
parent
b3115ea001
commit
a094e9a917
@ -98,7 +98,7 @@ def debugLog(function):
|
|||||||
# write output to file
|
# write output to file
|
||||||
if debugLogFilename != "":
|
if debugLogFilename != "":
|
||||||
try:
|
try:
|
||||||
with open(debugLogFilename, "a") as f:
|
with open(debugLogFilename, "a+") as f:
|
||||||
f.write(f"{out1}{out2}{out3}\n")
|
f.write(f"{out1}{out2}{out3}\n")
|
||||||
except:
|
except:
|
||||||
sys.stderr.write(f"Something went wrong when writing to file {debugLogFilename}\n")
|
sys.stderr.write(f"Something went wrong when writing to file {debugLogFilename}\n")
|
||||||
@ -210,7 +210,7 @@ def calculateNewUserStorage(current_storage: float) -> float:
|
|||||||
return float(new_storage)
|
return float(new_storage)
|
||||||
|
|
||||||
#@debugLog
|
#@debugLog
|
||||||
def calculateNewStorageCounters(ul_bytes: float, dl_bytes: float) -> tuple:
|
def calculateNewStorageCounters(ul_bytes: float, dl_bytes: float) -> tuple[float, float]:
|
||||||
# let the chance that no change occured be at 2%
|
# let the chance that no change occured be at 2%
|
||||||
no_change = random.randint(1, 100)
|
no_change = random.randint(1, 100)
|
||||||
if no_change > 98:
|
if no_change > 98:
|
||||||
@ -300,7 +300,7 @@ def doCmkHalStoragesOutput(storages: dict, hostname: str) -> None:
|
|||||||
print(f"{storage};{realname};{new_ul_bytes};{new_dl_bytes}")
|
print(f"{storage};{realname};{new_ul_bytes};{new_dl_bytes}")
|
||||||
|
|
||||||
#@debugLog
|
#@debugLog
|
||||||
def getStatus() -> tuple:
|
def getStatus() -> tuple[str, str]:
|
||||||
# randomly set one of the three available states
|
# randomly set one of the three available states
|
||||||
status_index = random.randint(1,100)
|
status_index = random.randint(1,100)
|
||||||
if status_index <= 5:
|
if status_index <= 5:
|
||||||
@ -315,14 +315,14 @@ def getStatus() -> tuple:
|
|||||||
return hal_status, hal_version
|
return hal_status, hal_version
|
||||||
|
|
||||||
#@debugLog
|
#@debugLog
|
||||||
def doLogin(hostname: str, username: str, password: str) -> tuple:
|
def doLogin(hostname: str, username: str, password: str) -> tuple[bool, int]:
|
||||||
# simulate the login to our HAL system
|
# simulate the login to our HAL system
|
||||||
# give it a chance of 2% to fail to demonstrate an error from time to time
|
# give it a chance of 2% to fail to demonstrate an error from time to time
|
||||||
success = random.randint(1, 100)
|
success = random.randint(1, 100)
|
||||||
if success > 2:
|
if success > 2:
|
||||||
return True, 200
|
return True, 200
|
||||||
else:
|
else:
|
||||||
return False, 404
|
return False, 401
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global debugLogFilename
|
global debugLogFilename
|
||||||
|
BIN
mkp/hal9001-1.0.7.mkp
Normal file
BIN
mkp/hal9001-1.0.7.mkp
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user