From 9e4bc69452761bf29e8e86b325097bc3e51b579c Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Tue, 18 Apr 2023 13:24:19 +0530 Subject: [PATCH] Base url --- smart_service/apis/master_api.py | 51 ++++++++++---------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index 87d7fe1..0a06b81 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -389,39 +389,17 @@ def asset_to_files_path(): def change_file_dir(): - data = frappe.db.sql(''' - select name,file from tabProcedure_Details where content_type = 'File' and file = '/files/Driver Seat Back Rest Foam.jpg' ;''', as_dict=1) - # for d in data: - # frappe.log_error("File data :", str(d)) - - # path = os.path.join(base_url, d['file']) - # isExist = os.path.exists(path) - # frappe.log_error("Path exists :", str(isExist)) - # if not isExist: - # ext = path[-3:] - # path = path[:-3] - # extension = '' - # if ext == 'png': - # extension = 'jpg' - - # if ext == 'jpg': - # extension = 'png' - - # path = path[:-3] + extension - # frappe.log_error("New path:", str(path)) - # if os.path.exists(path): - # file_name = d[:-3] + extension - - # frappe.log_error("New file :", str(file_name)) - - base_url = os.path.expanduser( - "~") + "/frappe-bench/sites/" + site_name + "/public/files" + base_path = os.path.expanduser( + "~") + "/frappe-bench/sites/" + site_name + "/public" + file_data = frappe.db.sql(''' + select name,file from tabProcedure_Details where content_type = 'File' and file = '/files/Driver Seat Back Rest Foam.jpg' ;''', as_dict=1) - for d in data: + for d in file_data: frappe.log_error("File data :", str(d)) path = d['file'] - isExist = os.path.exists(os.path.join(base_url, path)) + isExist = os.path.exists(base_path+path) + frappe.log_error("Path exists :", str(isExist)) if not isExist: ext = path[-3:] @@ -436,19 +414,20 @@ def change_file_dir(): new_full_path = path + extension frappe.log_error("New path:", str(new_full_path)) - new_file_dir = os.path.join(base_url,new_full_path) + new_file_dir = base_path + '/files/Driver Seat Back Rest Foam.jpg' + if os.path.exists(new_file_dir): - - frappe.log_error("final", str('ext changed File exists in local:'+ str(os.path.join(base_url,new_full_path)))) + frappe.log_error("final", str( + 'ext changed File exists in local:' + str(new_file_dir))) else: - frappe.log_error("final", str('File Not exists: ' + str(os.path.join(base_url,new_full_path)))) + frappe.log_error("final", str( + 'File Not exists: ' + new_file_dir)) # frappe.db.sql(f''' # update tabProcedure_Details set file = '{new_full_path}' where content_type = 'File' and name = '{d['name']}'; # ''') # frappe.db.commit() - - if data: - return data + if file_data: + return file_data else: return "Done"