Merge branch 'tweak/support-logs-zip-comment' into 'dev'

Add Zip comments to support archives

See merge request crafty-controller/crafty-4!438
This commit is contained in:
Iain Powrie 2022-08-27 19:15:49 +00:00
commit ee71e48035
3 changed files with 30 additions and 12 deletions

View File

@ -11,6 +11,7 @@
### Tweaks
- Make imports threaded ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/433))
- Add 'Created By' Field to servers ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/434))
- Add Zip comments to support archives ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/438))
### Lang
TBD
<br><br>

View File

@ -70,10 +70,13 @@ class FileHelpers:
FileHelpers.del_file(src_path)
@staticmethod
def make_archive(path_to_destination, path_to_zip):
def make_archive(path_to_destination, path_to_zip, comment=""):
# create a ZipFile object
path_to_destination += ".zip"
with ZipFile(path_to_destination, "w") as zip_file:
zip_file.comment = bytes(
comment, "utf-8"
) # comments over 65535 bytes will be truncated
for root, _dirs, files in os.walk(path_to_zip, topdown=True):
ziproot = path_to_zip
for file in files:
@ -98,10 +101,13 @@ class FileHelpers:
return True
@staticmethod
def make_compressed_archive(path_to_destination, path_to_zip):
def make_compressed_archive(path_to_destination, path_to_zip, comment=""):
# create a ZipFile object
path_to_destination += ".zip"
with ZipFile(path_to_destination, "w", ZIP_DEFLATED) as zip_file:
zip_file.comment = bytes(
comment, "utf-8"
) # comments over 65535 bytes will be truncated
for root, _dirs, files in os.walk(path_to_zip, topdown=True):
ziproot = path_to_zip
for file in files:
@ -127,7 +133,7 @@ class FileHelpers:
return True
def make_compressed_backup(
self, path_to_destination, path_to_zip, excluded_dirs, server_id
self, path_to_destination, path_to_zip, excluded_dirs, server_id, comment=""
):
# create a ZipFile object
path_to_destination += ".zip"
@ -145,6 +151,9 @@ class FileHelpers:
results,
)
with ZipFile(path_to_destination, "w", ZIP_DEFLATED) as zip_file:
zip_file.comment = bytes(
comment, "utf-8"
) # comments over 65535 bytes will be truncated
for root, dirs, files in os.walk(path_to_zip, topdown=True):
for l_dir in dirs:
if str(os.path.join(root, l_dir)).replace("\\", "/") in ex_replace:
@ -189,7 +198,9 @@ class FileHelpers:
return True
def make_backup(self, path_to_destination, path_to_zip, excluded_dirs, server_id):
def make_backup(
self, path_to_destination, path_to_zip, excluded_dirs, server_id, comment=""
):
# create a ZipFile object
path_to_destination += ".zip"
ex_replace = [p.replace("\\", "/") for p in excluded_dirs]
@ -206,6 +217,9 @@ class FileHelpers:
results,
)
with ZipFile(path_to_destination, "w") as zip_file:
zip_file.comment = bytes(
comment, "utf-8"
) # comments over 65535 bytes will be truncated
for root, dirs, files in os.walk(path_to_zip, topdown=True):
for l_dir in dirs:
if str(os.path.join(root, l_dir)).replace("\\", "/") in ex_replace:

View File

@ -1,6 +1,7 @@
import os
import pathlib
from pathlib import Path
from datetime import datetime
import platform
import shutil
import time
@ -180,18 +181,20 @@ class Controller:
)
# Make version file .txt when we download it for support
# Most people have a default editor for .txt also more mobile friendly...
FileHelpers.copy_file(
os.path.join(self.project_root, "app", "config", "version.json"),
os.path.join(temp_dir, "crafty_sys_info.txt"),
sys_info_string = (
f"Crafty v{self.helper.get_version_string()} Support Logs\n"
f"\n"
f"OS Info:- \n"
f"OS: {str(platform.system())}\n"
f"Version: {str(platform.release())}"
f"\n \n"
f"Log archive created on: {datetime.now()}"
)
with open(
os.path.join(temp_dir, "crafty_sys_info.txt"), "a", encoding="utf-8"
) as f:
f.write("\n")
f.write("OS Info:\n")
f.write("OS: " + str(platform.system()) + "\n")
f.write("Version: " + str(platform.release()))
FileHelpers.make_compressed_archive(temp_zip_storage, temp_dir)
f.write(sys_info_string)
FileHelpers.make_compressed_archive(temp_zip_storage, temp_dir, sys_info_string)
if len(self.helper.websocket_helper.clients) > 0:
self.helper.websocket_helper.broadcast_user(
exec_user["user_id"],