From e1402dc49bc9cd4e5f113d1a9d46121f6944806a Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Wed, 29 Nov 2023 17:07:11 -0500 Subject: [PATCH] update to raise an error if the user does not have permission to modify the js files. --- update_js.py | 57 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/update_js.py b/update_js.py index 45f8766..b61a302 100644 --- a/update_js.py +++ b/update_js.py @@ -1,30 +1,45 @@ import os from custom_nodes.EternalKernelLiteGraphNodes.local_shared import ETK_PATH, GDE_PATH -def check_for_js_extension(): - # here we check to see that the js extension is installed at {GDE_PATH}/web/extensions/etk/ui_modifications.js - # if it is not, we will copy it there from the ETK_PATH - # check if the file exists + +def check_for_js_extension(): import shutil for fn in ["ui_modifications.js", "ui_helpers.js"]: - check_full_path = os.path.normpath(os.path.join(ETK_PATH, f"{GDE_PATH}/web/extensions/etk/{fn}")) - etk_dir_file_mtime = os.path.getmtime(check_full_path) - web_dir_file_mtime = os.path.getmtime(os.path.join(ETK_PATH, fn)) + etk_file_path = os.path.normpath(os.path.join(GDE_PATH, "web", "extensions", "etk", fn)) + web_file_path = os.path.join(ETK_PATH, fn) - # determine direction of copy - if etk_dir_file_mtime > web_dir_file_mtime: - # copy from etk to web - copy_from = check_full_path - copy_to = os.path.join(ETK_PATH, fn) + # Check if both files exist + if os.path.exists(etk_file_path) and os.path.exists(web_file_path): + # Check for read and write permissions + if not os.access(etk_file_path, os.R_OK): + raise PermissionError(f"Read permission denied for {etk_file_path}") + if not os.access(web_file_path, os.W_OK): + raise PermissionError(f"Write permission denied for {web_file_path}") + + etk_dir_file_mtime = os.path.getmtime(etk_file_path) + web_dir_file_mtime = os.path.getmtime(web_file_path) + + # Determine direction of copy + if etk_dir_file_mtime > web_dir_file_mtime: + copy_from = etk_file_path + copy_to = web_file_path + else: + copy_from = web_file_path + copy_to = etk_file_path + + # Check if destination directory exists and has write permission + dest_dir = os.path.dirname(copy_to) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) + elif not os.access(dest_dir, os.W_OK): + raise PermissionError(f"Write permission denied for directory {dest_dir}") + + # Copy the file and give feedback + print(f"Copying {copy_from} to {copy_to}, because the file is out of date") + shutil.copyfile(copy_from, copy_to) + print(f"Copied {copy_from} to {copy_to}") else: - # copy from web to etk - copy_from = os.path.join(ETK_PATH, fn) - copy_to = check_full_path - - # copy the file, give the user feedback, overwrite if necessary - print(f"copying {copy_from} to {copy_to}, because the file is out of date") - shutil.copyfile(copy_from, copy_to) - print(f"copied {copy_from} to {copy_to}") + print(f"One or both of the files {etk_file_path} and {web_file_path} do not exist.") -check_for_js_extension() \ No newline at end of file +check_for_js_extension()