Skip to content

Commit

Permalink
Optimizing performance
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamDevourer committed Feb 21, 2022
1 parent b076748 commit 0978f3b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions SLN.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
if not VERSION_PATH.exists():
with open(f"{VERSION_PATH}", "w") as version_file:
version_file.write(json.dumps({"currentVersion": "v1.0.0 - Release"}))
# close
version_file.close()

with open(f"{VERSION_PATH}", "r+") as version_file:
version_data = json.load(version_file)
Expand All @@ -54,6 +56,7 @@
version_file.write(json.dumps({"currentVersion": "v1.0.0 - Release"}))

current_version = version_data["currentVersion"]
version_file.close()


def relative_to_logs(path: str) -> Path:
Expand Down Expand Up @@ -152,6 +155,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True):
# append log_header to the file.
with open(f"{relative_to_logs(f'{file_log_name}.log')}", "a") as log_file:
log_file.write(log_header)
log_file.close()

# if the first line of {file_log_name}.log is different from current_version
with open(f"{relative_to_logs(f'{file_log_name}.log')}") as check_ver:
Expand All @@ -165,6 +169,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True):
log_file.write(
"\n\n[NOTICE] Log file has been deleted or cleaned.\n"
)
log_file.close()
else:
# Delete everything inside the file and append log_header.
with open(
Expand All @@ -174,6 +179,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True):
log_file.write(
f"\n\n[NOTICE] PROGRAM HAS BEEN UPDATED TO {current_version}!\n"
)
log_file.close()

# if the file exceeds 1000 lines, delete everything and append log_header to the file.
with open(f"{relative_to_logs(f'{file_log_name}.log')}", "r") as log_file:
Expand Down Expand Up @@ -207,3 +213,4 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True):

if __name__ == "__main__":
print(__copyright__)
exit()

0 comments on commit 0978f3b

Please sign in to comment.