From 4061df55a5fe40a5b26ff72d4c91df5213eb1fef Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Mon, 26 Jun 2023 17:52:09 +0530 Subject: [PATCH] file size updated --- smart_service/apis/support.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/smart_service/apis/support.py b/smart_service/apis/support.py index fcb4ab2..539bd0d 100644 --- a/smart_service/apis/support.py +++ b/smart_service/apis/support.py @@ -11,6 +11,8 @@ base_path = os.path.expanduser( base_url = os.path.expanduser( "~") + "/frappe-bench/sites/" + site_name + "/public/files" +base_url1 = os.path.expanduser( + "~") + "/frappe-bench/sites/" + site_name + "/public" """ Working """ @@ -169,13 +171,18 @@ def append_size_file(): """ SELECT * FROM `tabFile` where file_size = 0 and is_folder!=1; """, as_dict=1) for d in data: try: - file_path = base_url + d.get("file_url") - file_size = os.path.getsize(file_path) - frappe.db.sql( - f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) - frappe.db.commit() - except: - pass + file_path = base_url1 + d.get("file_url") + isExist=os.path.exists(file_path) + if isExist: + file_size = os.path.getsize(file_path) + frappe.db.sql( + f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) + frappe.db.commit() + else: + pass + + except Exception as e: + return str(e) return data except Exception as e: frappe.log_error("FIle size ", str(e))