Browse Source

Check vehicle and all vehicle update fixes

version2
venkataakhil 1 year ago
parent
commit
caca62111f
  1. 439
      smart_service/apis/check_update.py
  2. 1
      smart_service/apis/master_api.py
  3. 36
      smart_service/apis/publish_api.py
  4. 321
      smart_service/apis/test.py
  5. 739
      smart_service/apis/update_validation.py
  6. 7
      smart_service/transactions/doctype/publish/publish.js
  7. 12
      smart_service/transactions/doctype/publish/publish.py

439
smart_service/apis/check_update.py

@ -0,0 +1,439 @@
import frappe
from frappe.model.document import Document
import json
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
""" Constants """
JSON_EXT = ".json"
JSON_INT_PATH = "/files/json_files/internal/"
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/"
JSON_GLOABL_PATH = "/files/json_files/global/"
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/"
STATUS = "status"
ERROR = "error"
UPDATE_AVAILABLE = 'IsUpdateAvailable'
UPDATE_FAILED = "Update checking Failed"
PARAM_MISSING = "Parameter missing :"
VERSION = 'Version'
CUR_VERSION = 'CurrentVersion'
DIS = 'Discription'
FILE_ERROR = 'File failed to load'
LANGUAGE = 'Language'
FILE_SIZE = 'FileSize'
JSON_URL = 'JsonURL'
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
@frappe.whitelist(allow_guest=1)
def check_vehicle_update(vehicle_list=None):
""" Rate Limiting """
# rate_res = custom_rate_limit(limit=5, seconds=15)
# if rate_res != 1:
# return rate_res
""" Validate Inputs """
val = input_validation(vehicle_list=vehicle_list)
""" Validate Input response """
if val != '':
return {"Vehicle": None,
"VehicleReqList": [],
STATUS: 0, ERROR: PARAM_MISSING+val}
response = {}
""" Iterate Vehicle List """
if vehicle_list:
try:
""" Read Request Body """
req_list = json.loads(vehicle_list)
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
""" Get Publish Type based on IID """
publish_type = frappe.db.get_list(
'App Device', filters={'name': iid}, fields='publish_type')
if publish_type:
publish_type = publish_type[0]['publish_type']
VehicleReqList = []
for v in vehicle_data:
l_id = v['LanguageID']
current_version = float(v[CUR_VERSION])
""" New function to validate publish version and get file path """
pulish_response = get_vehicle_publish_data(vehicle=vehicle,
l_id=l_id, current_version=current_version, publish_type=publish_type)
""" Append to Main Vehicle Request Response List """
VehicleReqList.append(pulish_response)
return {
"Vehicle": vehicle, "VehicleReqList": VehicleReqList, STATUS: 1, ERROR: "No error"}
except Exception as e:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: "Check Parameter: vehicle list"}
def get_file_size(file_name):
return os.path.getsize(base_url + file_name)
def get_vehicle_publish_data(vehicle, l_id, current_version, publish_type):
""" Response Structure """
vehicle_response_data = {
"Name": None,
"Version": 0,
"Vehicle": None,
"Language": l_id,
"Description": None,
"JsonURL": None,
"FileSize": None,
"Error": None,
"IsUpdateAvailable": False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name as Name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version >= {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only First Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
# frappe.log_error('Inside 1 Internal')
""" 1 Internal File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
# frappe.log_error('data', str(data))
# data = latest_publish_version
# frappe.log_error("data",str(data))
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Internal available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Full Internal File """
# same as latest_publish_version
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
# data = latest_publish_version
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Internal Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Global Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data['Remarks'] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data['Remarks'] = "Global available"
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "Global available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data['Remarks'] = "Global available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data['Remarks'] = "New Condition"
return vehicle_response_data
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {STATUS: 0, ERROR: PARAM_MISSING+val}
if vehicle_list:
try:
vehicle_req_list = []
response = {}
v_list = json.loads(vehicle_list)
lang = v_list['LanguageID']
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
if publish_type[0][0] is not None:
if vehicle_data:
for v in vehicle_data:
v_id = v['Vehicle']
current_version = float(v[CUR_VERSION])
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global'
and vehicle_status='Active' and publish_module='Automotive System' and version = (select max(version) as version
from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and publish_type='Global' and language='{}');'''.format(v_id, lang, v_id, lang), as_dict=1)
data1 = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and vehicle='{}' and language='{}'
;'''.format(v_id, lang, v_id, lang), as_dict=1)
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0][CUR_VERSION] = current_version
data1[0][UPDATE_AVAILABLE] = "false"
vehicle_req_list.append(data1)
elif len(data1_global) == 0:
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
data_append = []
rd = []
try:
for d in data:
d[UPDATE_AVAILABLE] = 'true'
d[CUR_VERSION] = current_version
data_append.append(d)
vehicle_req_list.append(data_append)
except:
pass
else:
if current_version < float(data1_global[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and publish_type='Global' and vehicle_status='Active'
and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, v_id, lang), as_dict=1)
elif current_version == float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='{}'
and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
elif current_version > float(data1_global[0]['version']):
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
# return data
data_append = []
rd = []
try:
for d in data:
d[UPDATE_AVAILABLE] = 'true'
d[CUR_VERSION] = current_version
data_append.append(d)
vehicle_req_list.append(data_append)
# for note in publish_dec:
# rd.append(note)
# vehicle_req_list.append(rd)
# for n in publish_dec:
# rd.append(n['release_description'])
# vehicle_req_list.append(rd)
except:
pass
response['LanguageID'] = lang
if len(vehicle_req_list) != 0:
data = [vu[0] for vu in vehicle_req_list]
# publish_dec_txt = [pd[0] for pd in publish_dec]
response['VehicleReqList'] = data
# response['release_description'] = publish_dec_txt['release_description']
return response
else:
return {STATUS: 0, ERROR: "No Vehicles in criteria"}
else:
return {STATUS: 0, ERROR: "Invalid Publish Details"}
else:
return {STATUS: 0, ERROR: "Invalid Publish Details"}
except Exception as e:
return {STATUS: 0, ERROR: str(e)}
else:
return {STATUS: 0, ERROR: "Check argument: vehicle list"}

1
smart_service/apis/master_api.py

@ -349,6 +349,7 @@ def old_variant(LSD, language):
@frappe.whitelist(methods=['POST'])
def variant(LSD, language, iid=None):
# frappe.log_error("variant")
date_format = "%Y-%m-%d %H:%M:%S.%f"
# if LSD != "null":
# try:

36
smart_service/apis/publish_api.py

@ -246,8 +246,8 @@ def old_json_grouping(args, language):
final.append(variant_out)
dicfinal = {"JSON": final}
frappe.db.sql(""" UPDATE %s.tabPublish SET publish_status = "%s" where name = "%s" """ % (
current_db_name, "Published", args))
frappe.db.sql(""" UPDATE `tabPublish` SET publish_status = "%s" where name = "%s" """ % (
"Published", args))
frappe.db.commit()
return dicfinal
@ -317,7 +317,7 @@ def json_grouping(args, language):
kms_active_status = True
else:
kms_active_status = False
if kms_mapping_status:
vari.update({"kms_mapping_active_status": kms_active_status})
vari["Assets"] = var_asset
variant_out["Variant"] = vari
@ -406,9 +406,11 @@ def json_grouping(args, language):
final.append(variant_out)
dicfinal = {"JSON": final}
frappe.db.sql(""" UPDATE %s.tabPublish SET publish_status = "%s" where name = "%s" """ % (
current_db_name, "Published", args))
frappe.log_error('dicfinal' + str(dicfinal))
frappe.db.sql(""" UPDATE `tabPublish` SET publish_status = "%s" where name = "%s" """ % (
"Published", args))
frappe.db.commit()
return dicfinal
except Exception as e:
frappe.log_error('JSON Grouping', str(e))
@ -441,6 +443,7 @@ def new_publish(args, publish_type, vehicle, language, version):
""" JSON generation """
json_file = json_grouping(args, language)
frappe.log_error('json grouping' + str(json_file))
file_name = ""
base_file_name = "%s-%s_v%s.json" % (vehicle, language, version)
@ -514,14 +517,16 @@ def new_publish(args, publish_type, vehicle, language, version):
if pub_ver:
frappe.log_error('inside')
prev_update_ver_internal = float(pub_ver[1]["version"])
frappe.log_error('version_internal' + str(prev_update_ver_internal))
frappe.log_error('version_internal' +
str(prev_update_ver_internal))
prev_full_internal_update_file = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_update_ver_internal)
if check_if_global_exist:
frappe.log_error('inside1')
prev_global_update_ver = check_if_global_exist[0]["version"]
frappe.log_error('version_global' + str(prev_global_update_ver))
frappe.log_error('version_global' +
str(prev_global_update_ver))
prev_global_file = full_update_path + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle,
language, prev_global_update_ver)
@ -537,16 +542,17 @@ def new_publish(args, publish_type, vehicle, language, version):
else:
return False, "File save issue"
# frappe.log_error("global exists")
# last_fullupdate_file = frappe.db.sql(""" SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}"
# and publish_type = "Internal" AND `language` = "{}" order by modified desc limit 2 ;""".format(vehicle, language), as_dict=1)
# if last_fullupdate_file:
# pass
else:
frappe.log_error(str('first time ionternal'))
full_update_file_name = full_update_path_internal + vehicle + "/" + \
"%s-%s-full_v%s.json" % (vehicle, language, version)
if str(version) == "0.01":
frappe.log_error(str('first time ionternal file creation'))
with open(full_update_file_name, "w") as outfile:
outfile.write(json.dumps(json_file))
get_step_total_count(full_update_file_name)
@ -569,8 +575,6 @@ def new_publish(args, publish_type, vehicle, language, version):
else:
return False, "File save issue"
set_publish_flag(publish_type, vehicle, language)
frappe.log_error('file_name' + str(file_name))
@ -643,7 +647,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
data_new = json.load(json_file1)
for k in data_new["JSON"]:
old_var_key = check_key(k["Variant"]["name"], data_old["JSON"], "Variant")
old_var_key = check_key(
k["Variant"]["name"], data_old["JSON"], "Variant")
if old_var_key is not None and old_var_key >= 0:
var_dict = {}
var_dict["Variant"] = k["Variant"]
@ -654,7 +659,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
var_dict["Variant"]["Assets"] = data_old["JSON"][old_var_key]["Variant"]["Assets"]
for i in variant_systems:
old_sys_key = check_key(i["sys_id"], var_dict["Variant"]["Systems"], "System")
old_sys_key = check_key(
i["sys_id"], var_dict["Variant"]["Systems"], "System")
if old_sys_key is not None and old_sys_key >= 0:
var_dict["Variant"]["Systems"][old_sys_key]["systemdisplayorder"] = i["systemdisplayorder"]
@ -672,7 +678,8 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
if old_sub_key is not None and old_sub_key >= 0:
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"][old_sub_key] = s
else:
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"].append(s)
var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"].append(
s)
else:
var_dict["Variant"]["Systems"].append(i)
@ -720,7 +727,8 @@ def check_key(key_name, old_data, type=None):
if old_data[d]["sub_systems"] == key_name:
return d
except:
frappe.log_error("Check key subsystem:",frappe.get_traceback())
frappe.log_error("Check key subsystem:",
frappe.get_traceback())
@frappe.whitelist(allow_guest=True)

321
smart_service/apis/test.py

@ -0,0 +1,321 @@
import frappe
from frappe.model.document import Document
import json
import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
JSON_EXT = ".json"
JSON_INT_PATH = "/files/json_files/internal/"
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/"
JSON_GLOABL_PATH = "/files/json_files/global/"
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/"
STATUS = "status"
ERROR = "error"
UPDATE_AVAILABLE = 'IsUpdateAvailable'
UPDATE_FAILED = "Update checking Failed"
PARAM_MISSING = "Parameter missing :"
VERSION = 'version'
CUR_VERSION = 'CurrentVersion'
DIS = 'Discription'
FILE_ERROR = 'File failed to load'
LANGUAGE = 'language'
FILE_SIZE = 'FileSize'
JSON_URL = 'JsonURL'
REMARKS = 'remarks'
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser(
"~") + "/frappe-bench/sites/" + site_name + "/public"
def custom_rate_limit(limit, seconds):
ip_based = True
ip = frappe.local.request_ip if ip_based is True else None
identity = None
identity = ip
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}"
value = frappe.cache().get(cache_key) or 0
if not value:
frappe.cache().setex(cache_key, seconds, 0)
value = frappe.cache().incrby(cache_key, 1)
if value > limit:
frappe.local.response["http_status_code"] = 429
return "You hit the rate limit because of too many requests. Please try after sometime."
return 1
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
""" Validate Input's """
val = input_validation(vehicle_list=vehicle_list)
""" Error response based on missing Input arguements """
if val != '':
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: PARAM_MISSING+val}
if vehicle_list:
""" Validate Input keys """
try:
vehicle_req_list = []
v_list = json.loads(vehicle_list)
language = v_list['LanguageID']
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
if not publish_type:
""" Error Response for Invalid Publish Type """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Publish Type not set "}
for v in vehicle_data:
vehicle_id = get_vehicle_id(v['Vehicle'])
publish_response = get_all_vehicle_publish_data(
v['Vehicle'], language, float(v['CurrentVersion']), publish_type[0][0], vehicle_id)
vehicle_req_list.append(publish_response)
""" Vehicle List Response """
return {"LanguageID": language,
"VehicleReqList": vehicle_req_list, STATUS: 1, ERROR: 'No Error'}
except Exception as e:
""" Error Response for Input key's validation """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
""" Error Response for Empty Vehicle List """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Check Arugument: vehicle list"}
def get_vehicle_id(vehicle):
vehicle_id = frappe.db.sql(
'''select myid as vehicle_id from `tabVehicle` where vehicle ='{0}'; '''.format(vehicle), as_dict=1)
if vehicle_id:
return vehicle_id[0]['vehicle_id']
else:
False
def get_all_vehicle_publish_data(vehicle, l_id, current_version, publish_type, vehicle_id):
""" Response Structure """
vehicle_response_data = {
"name": None,
"version": 0,
"vehicle_id": vehicle_id,
"language": l_id,
"description": None,
ERROR: None,
UPDATE_AVAILABLE: False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version > {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
""" 1 Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Full Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Global available"
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "New Condition"
return vehicle_response_data

739
smart_service/apis/update_validation.py

@ -17,6 +17,7 @@ JSON_INT_PATH = "/files/json_files/internal/"
JSON_FULL_INT_PATH = "/files/json_files/full_update/internal/"
JSON_GLOABL_PATH = "/files/json_files/global/"
JSON_FULL_UPDATE_PATH = "/files/json_files/full_update/"
JSON_FULL_GLOBAL_PATH = "/files/json_files/full_update/"
STATUS = "status"
ERROR = "error"
UPDATE_AVAILABLE = 'IsUpdateAvailable'
@ -24,11 +25,12 @@ UPDATE_FAILED = "Update checking Failed"
PARAM_MISSING = "Parameter missing :"
VERSION = 'Version'
CUR_VERSION = 'CurrentVersion'
DIS = 'Discription'
DIS = 'Description'
FILE_ERROR = 'File failed to load'
LANGUAGE = 'Language'
FILE_SIZE = 'FileSize'
JSON_URL = 'JsonURL'
REMARKS = 'remarks'
def custom_rate_limit(limit, seconds):
@ -67,7 +69,7 @@ def get_parent_map(input_list, parameter):
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
def check_all_vehicle_updates_old(vehicle_list=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
@ -87,62 +89,86 @@ def check_all_vehicle_updates(vehicle_list=None):
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
frappe.log_error('request' + str(vehicle_list))
# frappe.log_error('request' + str(vehicle_list))
if publish_type[0][0] is not None:
if vehicle_data:
for v in vehicle_data:
v_id = v['Vehicle']
current_version = float(v[CUR_VERSION])
frappe.log_error('cur', str(current_version))
# frappe.log_error('cur', str(current_version))
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published'
and publish_type='Global'
and vehicle_status='Active' and publish_module='Automotive System' and version = (select max(version) as version
from `tabPublish` where publish_module='Automotive System' and publish_type='Global'
and vehicle='{}');'''.format(v_id, lang, v_id), as_dict=1)
frappe.log_error(str(data1_global))
from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and publish_type='Global' and language='{}');'''.format(v_id, lang, v_id, lang), as_dict=1)
# frappe.log_error(
# 'first_data1_global' + str(data1_global))
data1 = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
;'''.format(v_id, lang, publish_type[0][0], v_id), as_dict=1)
frappe.log_error('data1' + str(data1))
and vehicle='{}' and language='{}'
;'''.format(v_id, lang, v_id, lang), as_dict=1)
# frappe.log_error('data1' + str(data1))
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
frappe.log_error('con1')
# frappe.log_error('con1')
data1[0][CUR_VERSION] = current_version
data1[0][UPDATE_AVAILABLE] = "false"
vehicle_req_list.append(data1)
elif len(data1_global) == 0:
# frappe.log_error('con5')
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
data_append = []
rd = []
try:
for d in data:
d[UPDATE_AVAILABLE] = 'true'
d[CUR_VERSION] = current_version
data_append.append(d)
vehicle_req_list.append(data_append)
except:
pass
else:
if current_version < float(data1_global[0]['version']):
frappe.log_error('con2')
# frappe.log_error('con2')
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and publish_type='Global' and vehicle_status='Active'
and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{}')'''.format(v_id, lang, v_id), as_dict=1)
frappe.log_error(
'data_internal' + str(data))
and vehicle='{}' and language='{}')'''.format(v_id, lang, v_id, lang), as_dict=1)
# frappe.log_error(
# 'data_internal' + str(data))
elif current_version == float(data1_global[0]['version']):
frappe.log_error('con3')
# frappe.log_error('con3')
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='{}'
and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}')'''.format(v_id, lang, publish_type[0][0], v_id), as_dict=1)
frappe.log_error('data'+str(data))
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
# frappe.log_error('data'+str(data))
elif current_version > float(data1_global[0]['version']):
frappe.log_error('con4')
# frappe.log_error('con4')
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' and
version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}')'''.format(v_id, lang, publish_type[0][0], v_id), as_dict=1)
and vehicle='{}' and language='{}')'''.format(v_id, lang, publish_type[0][0], v_id, lang), as_dict=1)
# return data
data_append = []
rd = []
@ -167,7 +193,7 @@ def check_all_vehicle_updates(vehicle_list=None):
if len(vehicle_req_list) != 0:
data = [vu[0] for vu in vehicle_req_list]
frappe.log_error(str(data))
# frappe.log_error(str(data))
# publish_dec_txt = [pd[0] for pd in publish_dec]
response['VehicleReqList'] = data
# response['release_description'] = publish_dec_txt['release_description']
@ -180,27 +206,568 @@ def check_all_vehicle_updates(vehicle_list=None):
return {STATUS: 0, ERROR: "Invalid Publish Details"}
except Exception as e:
frappe.log_error(str(e))
return {STATUS: 0, ERROR: "Failed to fetch updates"}
# frappe.log_error(str(e))
return {STATUS: 0, ERROR: str(e)}
else:
return {STATUS: 0, ERROR: "Check argument: vehicle list"}
@frappe.whitelist(allow_guest=1)
def check_all_vehicle_updates(vehicle_list=None):
""" Validate Input's """
val = input_validation(vehicle_list=vehicle_list)
""" Error response based on missing Input arguements """
if val != '':
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: PARAM_MISSING+val}
if vehicle_list:
""" Validate Input keys """
try:
vehicle_req_list = []
v_list = json.loads(vehicle_list)
language = v_list['LanguageID']
iid = v_list['InstallationId']
vehicle_data = v_list['VehicleReqList']
publish_type = frappe.db.sql(
'''SELECT publish_type FROM `tabApp Device` where name='{}';'''.format(iid), as_list=1)
if not publish_type:
""" Error Response for Invalid Publish Type """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Publish Type not set "}
for v in vehicle_data:
vehicle_id = get_vehicle_id(v['Vehicle'])
publish_response = get_all_vehicle_publish_data(
v['Vehicle'], language, float(v['CurrentVersion']), publish_type[0][0], vehicle_id)
vehicle_req_list.append(publish_response)
""" Vehicle List Response """
return {"LanguageID": language,
"VehicleReqList": vehicle_req_list, STATUS: 1, ERROR: 'No Error'}
except Exception as e:
""" Error Response for Input key's validation """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
""" Error Response for Empty Vehicle List """
return {"LanguageID": None,
"VehicleReqList": [], STATUS: 0, ERROR: "Check Arugument: vehicle list"}
def get_vehicle_id(vehicle):
vehicle_id = frappe.db.sql(
'''select myid as vehicle_id from `tabVehicle` where vehicle ='{0}'; '''.format(vehicle), as_dict=1)
if vehicle_id:
return vehicle_id[0]['vehicle_id']
else:
False
def get_all_vehicle_publish_data(vehicle, l_id, current_version, publish_type, vehicle_id):
""" Response Structure """
vehicle_response_data = {
"name": None,
"version": 0,
"vehicle_id": vehicle_id,
"language": l_id,
"description": None,
ERROR: None,
UPDATE_AVAILABLE: False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version > {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only First Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
# frappe.log_error('Inside 1 Internal')
""" 1 Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0]['version']) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Full Internal File """
data = frappe.db.sql('''SELECT name, format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0]['version']
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Internal Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0]['version']
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global Full Update available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data[UPDATE_AVAILABLE] = True
# vehicle_response_data[REMARKS] = "Global available"
data = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id, language,
release_description as description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0]['version']) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['name'] = data[0]['name']
vehicle_response_data['version'] = data[0]['version']
# vehicle_response_data['vehicle_id'] = data[0]['vehicle_id']
vehicle_response_data['language'] = data[0]['language']
vehicle_response_data['description'] = data[0]['description']
# vehicle_response_data['FileSize'] = get_file_size(
# file_name)
# vehicle_response_data['JsonURL'] = file_name
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "Global available"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to read file"
else:
vehicle_response_data[UPDATE_AVAILABLE] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data[ERROR] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data[UPDATE_AVAILABLE] = True
vehicle_response_data[REMARKS] = "New Condition"
return vehicle_response_data
@frappe.whitelist(allow_guest=1)
def check_vehicle_update(vehicle_list=None):
""" Rate Limiting """
rate_res = custom_rate_limit(limit=5, seconds=15)
frappe.log_error(str(vehicle_list))
if rate_res != 1:
return rate_res
# if vehicle_list == None:
# return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"}
""" Validate Inputs """
val = input_validation(vehicle_list=vehicle_list)
""" Validate Input response """
if val != '':
return {STATUS: 0, ERROR: PARAM_MISSING+val}
return {"Vehicle": None,
"VehicleReqList": [],
STATUS: 0, ERROR: PARAM_MISSING+val}
response = {}
""" Iterate Vehicle List """
if vehicle_list:
try:
""" Read Request Body """
req_list = json.loads(vehicle_list)
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
""" Get Publish Type based on IID """
publish_type = frappe.db.get_list(
'App Device', filters={'name': iid}, fields='publish_type')
if publish_type:
publish_type = publish_type[0]['publish_type']
vehicle_req_list = []
for v in vehicle_data:
l_id = v['LanguageID']
current_version = float(v[CUR_VERSION])
""" New function to validate publish version and get file path """
pulish_response = get_vehicle_publish_data(vehicle=vehicle,
l_id=l_id, current_version=current_version, publish_type=publish_type)
""" Append to Main Vehicle Request Response List """
vehicle_req_list.append(pulish_response)
return {
"Vehicle": vehicle, "VehicleReqList": vehicle_req_list, STATUS: 1, ERROR: "No error"}
except Exception as e:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: str(e)}
else:
return {"Vehicle": None, "VehicleReqList": [], STATUS: 0, ERROR: "Check Parameter: vehicle list"}
def get_file_size(file_name):
return os.path.getsize(base_url + file_name)
def get_vehicle_publish_data(vehicle, l_id, current_version, publish_type):
""" Response Structure """
vehicle_response_data = {
"Name": None,
"Version": 0,
"Vehicle": None,
"Language": l_id,
"Description": None,
"JsonURL": None,
"FileSize": None,
"Error": None,
"IsUpdateAvailable": False,
"CurrentVersion": current_version
}
latest_global_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and publish_type='Global' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
latest_publish_version = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as Description
FROM `tabPublish` where vehicle='{0}' and language='{1}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{0}' and language='{1}' and version > {2});
'''.format(vehicle, l_id, current_version), as_dict=1)
if not latest_publish_version:
""" Latest File already downloaded Global/Internal """
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Latest Version"
else:
if not latest_global_version or (current_version >= float(latest_global_version[0]['version'])):
""" Only First Internal available """
if publish_type == 'Internal':
value = round(
float(latest_publish_version[0]['version']) - current_version, 2)
if value == 0.01:
# frappe.log_error('Inside 1 Internal')
""" 1 Internal File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data[REMARKS] = "Internal available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Internal available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Full Internal File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Internal'
and vehicle='{0}' and language='{1}' );
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_INT_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data[REMARKS] = "Internal Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Internal Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "No Update available"
elif current_version < float(latest_global_version[0]['version']):
""" Only Global available """
if (float(latest_global_version[0]['version']) - int(current_version)) > 1:
""" Full Global File """
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_FULL_GLOBAL_PATH + vehicle + "/" + vehicle + \
"-" + l_id + "-"+"full_v" + \
str(data[0][VERSION]
) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data[REMARKS] = "Global Full Update available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Global Full Update available"
vehicle_response_data['Error'] = "Failed to get Publish version"
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data[REMARKS] = "Full Update Global available"
else:
""" Single Global File """
# vehicle_response_data['IsUpdateAvailable'] = True
# vehicle_response_data[REMARKS] = "Global available"
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as Description FROM `tabPublish` where vehicle='{0}' and language='{1}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System'
and vehicle='{0}' and language='{1}' and publish_type ='Global');
'''.format(vehicle, l_id), as_dict=1)
if data:
file_name = JSON_GLOABL_PATH+vehicle+"/"+vehicle + \
"-" + l_id + "_v" + \
str(data[0][VERSION]) + JSON_EXT
if os.path.exists(base_url + file_name):
vehicle_response_data['Name'] = data[0]['Name']
vehicle_response_data['Vehicle'] = data[0]['Vehicle']
vehicle_response_data['Version'] = data[0]['Version']
vehicle_response_data['Language'] = data[0]['Language']
vehicle_response_data['Description'] = data[0]['Description']
vehicle_response_data['FileSize'] = get_file_size(
file_name)
vehicle_response_data['JsonURL'] = file_name
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data[REMARKS] = "Global available"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data['Error'] = "Failed to read file"
else:
vehicle_response_data['IsUpdateAvailable'] = False
vehicle_response_data[REMARKS] = "Global available"
vehicle_response_data['Error'] = "Failed to get Publish version"
else:
""" Unknow condition Dont Know Yet """
value = {'latest_publish_version': latest_publish_version[0]['version'],
" latest_global_version": latest_global_version[0]['version']}
frappe.log_error('New check Update', str(
f'Unknow Condition{value}'))
vehicle_response_data['IsUpdateAvailable'] = True
vehicle_response_data[REMARKS] = "New Condition"
return vehicle_response_data
@frappe.whitelist(allow_guest=1)
def check_vehicle_update_old(vehicle_list=None):
rate_res = custom_rate_limit(limit=5, seconds=15)
if rate_res != 1:
return rate_res
val = input_validation(vehicle_list=vehicle_list)
if val != '':
return {STATUS: 0, ERROR: PARAM_MISSING+val}
response = {}
if vehicle_list:
try:
req_list = json.loads(vehicle_list)
response['Vehicle'] = req_list['Vehicle']
vehicle = req_list['Vehicle']
@ -218,22 +785,22 @@ def check_vehicle_update(vehicle_list=None):
for v in vehicle_data:
l_id = v['LanguageID']
current_version = float(v[CUR_VERSION])
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}'
data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as Description FROM `tabPublish` where vehicle='{}'
and language='{}' and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' and vehicle='{}'
and publish_type='Global');
'''.format(vehicle, l_id, vehicle), as_dict=1)
and publish_type='Global' and language='{}');
'''.format(vehicle, l_id, vehicle, l_id), as_dict=1)
frappe.log_error('glbal'+str(data1_global))
# frappe.log_error('glbal'+str(data1_global))
data1 = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' and
data1 = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language,release_description as Description FROM `tabPublish` where vehicle='{}' and language='{}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and vehicle='{}'); '''.format(vehicle, l_id, vehicle), as_dict=1)
and vehicle='{}' and language='{}'); '''.format(vehicle, l_id, vehicle, l_id), as_dict=1)
frappe.log_error('data1' + str(data1))
if len(data1_global) > 0 and len(data1) > 0:
if data1_global[0]['version']:
# frappe.log_error('data1' + str(data1))
# if len(data1_global) > 0 and len(data1) > 0:
if len(data1_global) > 0:
if data1[0]['version'] is not None:
if current_version == float(data1[0]['version']):
data1[0][UPDATE_AVAILABLE] = "false"
@ -245,14 +812,14 @@ def check_vehicle_update(vehicle_list=None):
else:
if current_version < (float(data1_global[0]['version'])-1.00):
frappe.log_error(str('global_test4'))
# frappe.log_error(str('global_test4'))
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as description FROM `tabPublish` where vehicle='{}' and language='{}' and
release_description as Description FROM `tabPublish` where vehicle='{}' and language='{}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and publish_type='Global'
and vehicle='{}')'''.format(vehicle, l_id, vehicle), as_dict=1)
frappe.log_error('file'+str(data))
and vehicle='{}' and language='{}')'''.format(vehicle, l_id, vehicle, l_id), as_dict=1)
# frappe.log_error('file'+str(data))
try:
for d in data:
try:
@ -269,8 +836,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except Exception as e:
frappe.log_error(
'error1', str(e))
# frappe.log_error(
# 'error1', str(e))
file_name = None
file_size = None
d[JSON_URL] = file_name
@ -282,17 +849,17 @@ def check_vehicle_update(vehicle_list=None):
current_version)
vehicle_req_list.append(d)
except Exception as e:
frappe.log_error('error 2', str(e))
# frappe.log_error('error 2', str(e))
vehicle_req_list.append(
{ERROR: UPDATE_FAILED})
elif current_version == (float(data1_global[0]['version'])-1.00):
frappe.log_error(str('global_test3'))
# frappe.log_error(str('global_test3'))
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as description FROM `tabPublish` where vehicle='{}' and language='{}' and
release_description as Description FROM `tabPublish` where vehicle='{}' and language='{}' and
publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System'
and publish_type='Global' and vehicle='{}')'''.format(vehicle, l_id, publish_type, vehicle), as_dict=1)
and publish_type='Global' and vehicle='{}' and language='{}')'''.format(vehicle, l_id, vehicle, l_id), as_dict=1)
try:
for d in data:
file_name = None
@ -310,8 +877,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except Exception as e:
frappe.log_error(
'error 3', str(e))
# frappe.log_error(
# 'error 3', str(e))
# file_name= None
file_size = None
d[JSON_URL] = file_name
@ -323,34 +890,33 @@ def check_vehicle_update(vehicle_list=None):
current_version)
vehicle_req_list.append(d)
except Exception as e1:
frappe.log_error('error 4', str(e))
# frappe.log_error('error 4', str(e))
vehicle_req_list.append(
{ERROR: UPDATE_FAILED})
elif current_version == float(data1_global[0]['version']):
""" Check For only internal """
frappe.log_error(str('global_test2'))
# frappe.log_error(str('global_test2'))
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,release_description as Description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' and
publish_type='{}' and vehicle='{}')'''.format(vehicle, l_id, publish_type, vehicle), as_dict=1)
publish_type='{}' and vehicle='{}' and language='{}')'''.format(vehicle, l_id, publish_type, vehicle, l_id), as_dict=1)
try:
for d in data:
try:
if float(data1[0]['version']) - current_version > 0.01:
# frappe.log_error(
# 'file error 1', JSON_FULL_INT_PATH + vehicle+"/" + vehicle+"-" + d[LANGUAGE]+"-full_v" + str(d[VERSION]) + JSON_EXT)
file_name = JSON_FULL_INT_PATH + vehicle+"/" + \
vehicle+"-" + \
d[LANGUAGE]+"-full_v" + \
str(d[VERSION]) + \
JSON_EXT
frappe.log_error(
'File 1 ', file_name)
# frappe.log_error(
# 'File 1 ', file_name)
file_size = os.path.getsize(
base_url + file_name)
d[JSON_URL] = file_name
@ -371,8 +937,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except Exception as e:
frappe.log_error(
'error 5', str(e))
# frappe.log_error(
# 'error 5', str(e))
file_name = None
file_size = None
d[JSON_URL] = file_name
@ -384,19 +950,19 @@ def check_vehicle_update(vehicle_list=None):
current_version)
vehicle_req_list.append(d)
except Exception as e2:
frappe.log_error(
'error 6', str(e))
# frappe.log_error(
# 'error 6', str(e))
vehicle_req_list.append(
{ERROR: UPDATE_FAILED})
elif current_version > float(data1_global[0]['version']):
frappe.log_error(str('global_test6'))
# frappe.log_error(str('global_test6'))
if current_version < float(data1[0]['version']):
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language ,release_description as Description
FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' and
vehicle_status='Active' and publish_module='Automotive System' and version = (select max(version) as
version from `tabPublish` where publish_module='Automotive System' and publish_type ='{}' and
vehicle='{}' )'''.format(vehicle, l_id, publish_type, vehicle), as_dict=1)
vehicle='{}' and language='{}' )'''.format(vehicle, l_id, publish_type, vehicle, l_id), as_dict=1)
try:
for d in data:
try:
@ -406,8 +972,8 @@ def check_vehicle_update(vehicle_list=None):
d[LANGUAGE]+"-full_v" + \
str(d[VERSION]) + \
JSON_EXT
frappe.log_error(
'File 2 ', file_name)
# frappe.log_error(
# 'File 2 ', file_name)
file_size = os.path.getsize(
base_url + file_name)
d[JSON_URL] = file_name
@ -428,8 +994,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except Exception as e:
frappe.log_error(
'error 9', str(e))
# frappe.log_error(
# 'error 9', str(e))
file_name = JSON_INT_PATH+vehicle+"/" + \
vehicle+"-" + \
d[LANGUAGE]+"_v" + \
@ -445,26 +1011,26 @@ def check_vehicle_update(vehicle_list=None):
current_version)
vehicle_req_list.append(d)
except Exception as e3:
frappe.log_error(
'error 10', str(e))
# frappe.log_error(
# 'error 10', str(e))
vehicle_req_list.append(
{'Error': UPDATE_FAILED})
# else:
# vehicle_req_list.append({'Error':"Else 3"})
elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']):
frappe.log_error(str('global_test1'))
# frappe.log_error(str('global_test1'))
if current_version < float(data1[0]['version']):
frappe.log_error(
str('global_test'))
# frappe.log_error(
# str('global_test'))
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,
release_description as description FROM `tabPublish` where vehicle='{}' and language='{}'
release_description as Description FROM `tabPublish` where vehicle='{}' and language='{}'
and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System'
and version = (select max(version) as version from `tabPublish`
where publish_module='Automotive System' and vehicle='{}' and publish_type='Global' );
'''.format(vehicle, l_id, vehicle), as_dict=1)
frappe.log_error(
'error 7 data', str(data))
where publish_module='Automotive System' and vehicle='{}' and publish_type='Global' and language='{}' );
'''.format(vehicle, l_id, vehicle, l_id), as_dict=1)
# frappe.log_error(
# 'error 7 data', str(data))
try:
for d in data:
try:
@ -481,8 +1047,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except Exception as e:
frappe.log_error(
'error 7', str(e))
# frappe.log_error(
# 'error 7', str(e))
file_name = JSON_GLOABL_PATH+vehicle+"/" + \
vehicle+"-" + \
d[LANGUAGE]+"_v" + \
@ -498,8 +1064,8 @@ def check_vehicle_update(vehicle_list=None):
current_version)
vehicle_req_list.append(d)
except Exception as e2:
frappe.log_error(
'error 8', str(e))
# frappe.log_error(
# 'error 8', str(e))
vehicle_req_list.append(
{ERROR: UPDATE_FAILED})
@ -507,12 +1073,12 @@ def check_vehicle_update(vehicle_list=None):
vehicle_req_list.append(
{LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)})
else:
frappe.log_error('null')
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language FROM `tabPublish`
# frappe.log_error('null')
data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language,release_description as Description FROM `tabPublish`
where vehicle='{}' and language='{}' and publish_status='Published' and vehicle_status='Active'
and publish_module='Automotive System' and version =
(select max(version) as version from `tabPublish` where publish_module='Automotive System' and
publish_type='{}' and vehicle='{}');'''.format(vehicle, l_id, publish_type, vehicle), as_dict=1)
publish_type='{}' and vehicle='{}' and language='{}');'''.format(vehicle, l_id, publish_type, vehicle, l_id), as_dict=1)
if data:
try:
for d in data:
@ -528,8 +1094,8 @@ def check_vehicle_update(vehicle_list=None):
d[UPDATE_AVAILABLE] = 'true'
except:
frappe.log_error(
'error 11', str(e))
# frappe.log_error(
# 'error 11', str(e))
file_name = None
file_size = None
d[JSON_URL] = file_name
@ -540,7 +1106,7 @@ def check_vehicle_update(vehicle_list=None):
d[CUR_VERSION] = float(current_version)
vehicle_req_list.append(d)
except Exception as e2:
frappe.log_error('error 12', str(e))
# frappe.log_error('error 12', str(e))
vehicle_req_list.append(
{ERROR: UPDATE_FAILED})
if len(vehicle_req_list) > 0:
@ -549,7 +1115,6 @@ def check_vehicle_update(vehicle_list=None):
else:
return {STATUS: 0, ERROR: "No Vehicles in criteria"}
return response
else:
response['JSON'] = {STATUS: 0, ERROR: "Data Not available"}

7
smart_service/transactions/doctype/publish/publish.js

@ -446,7 +446,8 @@ frappe.ui.form.on("Publish", {
version: frm.doc.version,
},
callback: function (r) {
// if (r.message[0]) {
debugger
if (r.message[0] == true) {
frm.set_value("publish_status", "Published");
frm.page.clear_primary_action("Publish");
frm.set_value(
@ -476,6 +477,10 @@ frappe.ui.form.on("Publish", {
},
},
});
}
else{
frappe.msgprint('Failed To Publish')
}
},
});
}

12
smart_service/transactions/doctype/publish/publish.py

@ -59,6 +59,7 @@ class Publish(Document):
str(km_mapping.name) + '\n'
def on_submit(self):
if self.docstatus == 1 and self.publish_status == 'To Publish' and self.publish_module == 'Repair service' and self.publish_type == 'Internal':
repair_res_obj = repair_checksheet_publish(self.vehicle, self.vehicle_id,
self.language, self.publish_type,
@ -128,6 +129,14 @@ class Publish(Document):
update_publish_mapping(self.vehicle, self.variant_mapping,
self.language, self.publish_module, self.publish_type)
if self.publish_type == 'Internal':
frappe.db.sql(
'''update tabVehicle set internal_publish = 1 where vehicle= '{0}'; '''.format(self.vehicle))
else:
frappe.db.sql(
'''update tabVehicle set global_publish = 1 where vehicle= '{0}'; '''.format(self.vehicle))
def on_cancel(self):
# Published document should not allow to cancel
if self.publish_status == "Published":
@ -239,7 +248,8 @@ def update_publish_mapping(vehicle, variant, language, module, publish_type):
}, fields=['name'])
if pub_data:
doc = frappe.get_doc('Module Publish Mapping', pub_data[0]['name'])
doc = frappe.get_doc(
'Module Publish Mapping', pub_data[0]['name'])
else:
doc = frappe.get_doc({
'doctype': 'Module Publish Mapping',

Loading…
Cancel
Save