diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index aa85ada..9fc06c4 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -470,7 +470,7 @@ def new_publish(args, publish_type, vehicle, language, version): pub_ver = None prev_update_ver = None check_if_global_exist = frappe.db.sql("""SELECT vehicle,language,format(version,2) as version,modified,publish_type FROM tabPublish where vehicle = "{}" - and publish_type = "Global" AND `language` = "{}" order by modified desc limit 1 ;""".format(vehicle, language), as_dict=1) + and publish_type = "Global" AND `language` = "{}" and publish_module="Automotive System" order by modified desc limit 1 ;""".format(vehicle, language), as_dict=1) if publish_type.lower() == "global": frappe.log_error(str("global")) @@ -510,7 +510,7 @@ def new_publish(args, publish_type, vehicle, language, version): "%s-%s-full_v%s.json" % (vehicle, language, version) frappe.log_error( 'update file' + str(full_update_file_name)) pub_ver = 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) + and publish_type = "Internal" AND `language` = "{}" and publish_module="Automotive System" order by modified desc limit 2 ;""".format(vehicle, language), as_dict=1) if pub_ver: frappe.log_error('inside') prev_update_ver_internal = float(pub_ver[1]["version"]) diff --git a/smart_service/apis/update_validation.py b/smart_service/apis/update_validation.py index 2352a57..398991c 100644 --- a/smart_service/apis/update_validation.py +++ b/smart_service/apis/update_validation.py @@ -67,7 +67,7 @@ def get_parent_map(input_list, parameter): @frappe.whitelist(allow_guest=1) -def check_all_vehicle_updates1(vehicle_list=None): +def check_all_vehicle_updates(vehicle_list=None): rate_res = custom_rate_limit(limit=5, seconds=15) if rate_res != 1: return rate_res @@ -87,202 +87,70 @@ def check_all_vehicle_updates1(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)) 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(max(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' - order by version ASC;'''.format(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 publish_type='{}' and vehicle_status='Active' and publish_module='Automotive System' - order by version ASC;'''.format(v_id, lang, publish_type[0][0]), as_dict=1) + 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)) + 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)) if data1[0]['version'] is not None: if current_version == float(data1[0]['version']): + frappe.log_error('con1') + data1[0][CUR_VERSION] = current_version data1[0][UPDATE_AVAILABLE] = "false" vehicle_req_list.append(data1) else: if current_version < float(data1_global[0]['version']): - data = 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 publish_type='Global' and vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - order by version ASC;'''.format(v_id, lang, current_version), as_dict=1) - publish_dec = 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 publish_type='Global' and vehicle_status='Active' and version = '{}' and publish_module='Automotive System' - # order by version ASC;'''.format(v_id, lang, data1_global[0]['version']), as_dict=1) + 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)) elif current_version == float(data1_global[0]['version']): + frappe.log_error('con3') if current_version < float(data1[0]['version']): - data = 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 publish_type='{}' and vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - order by version ASC;'''.format(v_id, lang, publish_type[0][0], current_version), as_dict=1) - publish_dec = 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 publish_type='Global' and vehicle_status='Active' and version ='{}' and publish_module='Automotive System' - order by version ASC;'''.format(v_id, lang, data1[0]['version']), as_dict=1) - # return data - data_append = [] - rd = [] - try: - for d in data: - d[UPDATE_AVAILABLE] = 'true' - d[CUR_VERSION] = float( - current_version) - data_append.append(d) - vehicle_req_list.append(data_append) + 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)) - # 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] - 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'] - 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: - frappe.log_error(str(e)) - return {STATUS: 0, ERROR: "Failed to fetch updates"} - else: - return {STATUS: 0, ERROR: "Check argument: vehicle list"} - - -@frappe.whitelist(allow_guest = 1) -def check_all_vehicle_updates(vehicle_list=None): - # frappe.log_error('request' + str(vehicle_list)) - rate_res = custom_rate_limit(limit=5, seconds=15) - if rate_res != 1: - return rate_res - # if vehicle_list == None: - # return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"} - 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) - # frappe.log_error('publish_type' + str(publish_type)) - # frappe.log_error('iid' + str(iid)) - 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 publish_type='Global');'''.format(v_id, lang), as_dict=1) - 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 publish_type='Internal');'''.format(v_id, lang, publish_type[0][0]), as_dict=1) - - if publish_type[0][0] == "Global": - if current_version == float(data1_global[0]['version']): - data1[0][UPDATE_AVAILABLE] = "false" - vehicle_req_list.append(data1) - 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 vehicle_status='Active' - and version = (select max(version) as version from `tabPublish` - where publish_module='Automotive System' and publish_type='Global') and publish_module='Automotive System' - '''.format(v_id, lang, current_version), as_dict=1) - frappe.log_error( - 'global_publish' + str(data)) - publish_dec = 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 publish_type='Global' and vehicle_status='Active' and version = '{}' and publish_module='Automotive System' - # order by version ASC;'''.format(v_id, lang, data1_global[0]['version']), as_dict=1) - frappe.log_error(str('global_publish')) - - # elif current_version == float(data1_global[0]['version']): - # if current_version < float(data1[0]['version']): - # data = 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 publish_type='{}' and vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - # order by version ASC;'''.format(v_id, lang, publish_type[0][0], current_version), as_dict=1) - # publish_dec = 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 publish_type='Global' and vehicle_status='Active' and version ='{}' and publish_module='Automotive System' - # order by version ASC;'''.format(v_id, lang, data1[0]['version']), as_dict=1) - # return data - data_append = [] - rd = [] - try: - for d in data: - d[UPDATE_AVAILABLE] = 'true' - d[CUR_VERSION] = float( - current_version) - data_append.append(d) - vehicle_req_list.append(data_append) - except: - pass - - elif publish_type[0][0] == "Internal": - # frappe.log_error(str('check_ful_internal')) - if current_version == float(data1[0]['version']): - data1[0][UPDATE_AVAILABLE] = "false" - vehicle_req_list.append(data1) - else: - 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 vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' and publish_type='Internal') - '''.format(v_id, lang, current_version), as_dict=1) - # frappe.log_error( - # 'check_ful_inter' + str(data)) - publish_dec = 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 version = '{}' and publish_module='Automotive System' - and version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' and publish_type='Internal') - # order by version ASC;'''.format(v_id, lang, data1_global[0]['version']), as_dict=1) - - elif current_version == float(data1[0]['version']): + elif current_version > float(data1_global[0]['version']): + frappe.log_error('con4') if current_version < float(data1[0]['version']): - data = 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 version = (select max(version) as version from `tabPublish` where publish_module='Automotive System' and publish_type='{}')'''.format(v_id, lang, publish_type[0][0]), as_dict=1) - # frappe.log_error( - # 'check_ful_inter_else' + str(data)) - publish_dec = 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 publish_type='Global') - '''.format(v_id, lang, data1[0]['version']), as_dict=1) + 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) # return data - # else: - # frappe.log_error( - # 'check_ful_inter_else') data_append = [] rd = [] try: for d in data: d[UPDATE_AVAILABLE] = 'true' - d[CUR_VERSION] = float( - current_version) + + d[CUR_VERSION] = current_version data_append.append(d) vehicle_req_list.append(data_append) @@ -299,6 +167,8 @@ 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)) + # publish_dec_txt = [pd[0] for pd in publish_dec] response['VehicleReqList'] = data # response['release_description'] = publish_dec_txt['release_description'] return response @@ -317,8 +187,9 @@ def check_all_vehicle_updates(vehicle_list=None): @frappe.whitelist(allow_guest=1) -def check_vehicle_update1(vehicle_list=None): +def check_vehicle_update(vehicle_list=None): 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: @@ -339,420 +210,54 @@ def check_vehicle_update1(vehicle_list=None): 'App Device', filters={'name': iid}, fields='publish_type') if len(publish_type) > 0: - publish_type = publish_type[0]['publish_type'] - vehicle_req_list = [] - # Iterate on language - for v in vehicle_data: - l_id = v['LanguageID'] - current_version = float(v[CUR_VERSION]) - data1_global = 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 publish_type='Global' and vehicle_status='Active' and publish_module='Automotive System' - order by version ASC;'''.format(vehicle, l_id), 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' - order by version ASC;'''.format(vehicle, l_id), as_dict=1) - if data1_global[0]['version']: - if data1[0]['version'] is not None: - if current_version == float(data1[0]['version']): - data1[0][UPDATE_AVAILABLE] = "false" - data = {} - data[LANGUAGE] = l_id - data[UPDATE_AVAILABLE] = 'false' - data[CUR_VERSION] = float(current_version) - vehicle_req_list.append(data) - - else: - if current_version < (float(data1_global[0]['version'])-1.00): - data = frappe.db.sql('''SELECT name as Name,version as Version,vehicle_id as Vehicle,language as Language,release_description - as description FROM `tabPublish` - where vehicle='{}' and language='{}' and publish_status='Published' and publish_type='Global' and vehicle_status='Active' - and Version > '{}' - and publish_module='Automotive System' order by version DESC limit 1;'''.format(vehicle, l_id, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_FULL_UPDATE_PATH+vehicle+"/"+vehicle + \ - "-" + \ - d[LANGUAGE]+"-"+"full_v" + \ - str(d[VERSION])+JSON_EXT - frappe.log_error( - "name"+str(file_name)) - file_size = os.path.getsize( - file_name) - frappe.log_error( - "size"+str(file_size)) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version == (float(data1_global[0]['version'])-1.00): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='Global' and vehicle_status='Active' - and Version > '{}' and publish_module='Automotive System' - order by version DESC;'''.format(vehicle, l_id, current_version), as_dict=1) - try: - for d in data: - file_name = None - try: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION])+JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - # file_name= None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e1: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version == float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and - vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e2: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='Global' and vehicle_status='Active' - and publish_module='Automotive System'and version > '{}' order by version DESC;'''.format(vehicle, l_id, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e2: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version > float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and vehicle_status='Active' and version > '{}' - and publish_module='Automotive System' order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e3: - vehicle_req_list.append( - {'Error': UPDATE_FAILED}) - # else: - # vehicle_req_list.append({'Error':"Else 3"}) - - else: - vehicle_req_list.append( - {LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)}) - else: - frappe.log_error(str('internal update')) - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and vehicle_status='Active' - and publish_module='Automotive System' - and version > '{}' order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) - frappe.log_error(str(data)) - try: - for d in data: - try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-"+d[LANGUAGE] + \ - "-full_v"+str(d[VERSION])+JSON_EXT - frappe.log_error( - 'full_inernal' + str(file_name)) - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except: - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = FILE_ERROR - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float(current_version) - vehicle_req_list.append(d) - except Exception as e2: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - response['Vehicle'] = vehicle - response['VehicleReqList'] = vehicle_req_list - return response - else: - response['JSON'] = {STATUS: 0, ERROR: "Data Not available"} - return response - except Exception as e: - response['JSON'] = {STATUS: 0, ERROR: UPDATE_FAILED} - return response - else: - return {STATUS: 0, ERROR: "Check Parameter: vehicle list"} - - -@frappe.whitelist(allow_guest=1) -def check_vehicle_update_error(vehicle_list=None): - rate_res = custom_rate_limit(limit=5, seconds=15) - if rate_res != 1: - return rate_res - # if vehicle_list == None: - # return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"} - val = input_validation(vehicle_list=vehicle_list) - if val != '': - return {STATUS: 0, ERROR: PARAM_MISSING+val} - - if vehicle_list: - try: - response = {} - req_list = json.loads(vehicle_list) - response['Vehicle'] = req_list['Vehicle'] - vehicle = req_list['Vehicle'] - iid = req_list['InstallationId'] - vehicle_data = req_list['VehicleReqList'] - publish_type = frappe.db.get_list( - 'App Device', filters={'name': iid}, fields='publish_type') - if len(publish_type) > 0: publish_type = publish_type[0]['publish_type'] vehicle_req_list = [] + # Iterate on language for v in vehicle_data: l_id = v['LanguageID'] current_version = float(v[CUR_VERSION]) - data1_global = 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 publish_type='Global' - and vehicle_status='Active' and publish_module='Automotive System' - order by version ASC;'''.format(vehicle, l_id), as_dict=1) - frappe.log_error('global_req' + str(data1_global)) - - # 22 - 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' - order by version ASC;'''.format(vehicle, l_id), as_dict=1) - # 22.04 - if data1_global[0]['version'] and publish_type == 'Global': - - if data1[0]['version'] is not None: - frappe.log_error('inside') - - if current_version == float(data1[0]['version']): - frappe.log_error('inside1') - data1[0][UPDATE_AVAILABLE] = "false" - data = {} - data[LANGUAGE] = l_id - data[UPDATE_AVAILABLE] = 'false' - data[CUR_VERSION] = float(current_version) - vehicle_req_list.append(data) - - else: - if current_version < (float(data1_global[0]['version'])-1.00): - frappe.log_error('inside2') - data = frappe.db.sql('''SELECT name as Name,version as Version,vehicle_id as Vehicle,language as Language,release_description - as description FROM `tabPublish` where vehicle='{}' and language='{}' and publish_status='Published' - and publish_type='Global' and vehicle_status='Active' and Version > '{}' - and publish_module='Automotive System' order by version DESC limit 1;''' - .format(vehicle, l_id, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_FULL_UPDATE_PATH+vehicle+"/"+vehicle + \ - "-" + \ - d[LANGUAGE]+"-"+"full_v" + \ - str(d[VERSION])+JSON_EXT - # frappe.log_error( - # "name "+str(file_name)) - file_size = os.path.getsize( - file_name) - # frappe.log_error( - # "size"+str(file_size)) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version == (float(data1_global[0]['version'])-1.00): - frappe.log_error('inside3') - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='Global' and vehicle_status='Active' - and Version > '{}' and publish_module='Automotive System' - order by version DESC;'''.format(vehicle, l_id, current_version), as_dict=1) - try: - for d in data: - file_name = None - try: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION])+JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - # file_name= None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e1: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version == float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and - vehicle_status='Active' and version > '{}' and publish_module='Automotive System' - order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) + data1_global = frappe.db.sql('''SELECT name,format(version,2) as version,vehicle_id,language 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) + + 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 + 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) + + frappe.log_error('data1' + str(data1)) + if len(data1_global) > 0 and len(data1) > 0: + if data1_global[0]['version']: + if data1[0]['version'] is not None: + if current_version == float(data1[0]['version']): + data1[0][UPDATE_AVAILABLE] = "false" + data = {} + data[LANGUAGE] = l_id + data[UPDATE_AVAILABLE] = 'false' + data[CUR_VERSION] = float(current_version) + vehicle_req_list.append(data) + + else: + if current_version < (float(data1_global[0]['version'])-1.00): + 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 + 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)) try: for d in data: try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ + file_name = JSON_FULL_UPDATE_PATH+vehicle+"/"+vehicle + \ + "-" + \ + d[LANGUAGE]+"-"+"full_v" + \ str(d[VERSION]) + \ JSON_EXT file_size = os.path.getsize( @@ -763,6 +268,8 @@ def check_vehicle_update_error(vehicle_list=None): d[UPDATE_AVAILABLE] = 'true' except Exception as e: + frappe.log_error( + 'error1', str(e)) file_name = None file_size = None d[JSON_URL] = file_name @@ -773,17 +280,21 @@ def check_vehicle_update_error(vehicle_list=None): d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) - except Exception as e2: + except Exception as e: + frappe.log_error('error 2', str(e)) vehicle_req_list.append( {ERROR: UPDATE_FAILED}) - elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='Global' and vehicle_status='Active' - and publish_module='Automotive System'and version > '{}' order by version DESC;'''.format(vehicle, l_id, current_version), as_dict=1) + elif current_version == (float(data1_global[0]['version'])-1.00): + 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 + 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) try: for d in data: + file_name = None try: file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ @@ -798,11 +309,9 @@ def check_vehicle_update_error(vehicle_list=None): d[UPDATE_AVAILABLE] = 'true' except Exception as e: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT + frappe.log_error( + 'error 3', str(e)) + # file_name= None file_size = None d[JSON_URL] = file_name d[FILE_SIZE] = file_size @@ -812,434 +321,233 @@ def check_vehicle_update_error(vehicle_list=None): d[CUR_VERSION] = float( current_version) vehicle_req_list.append(d) - except Exception as e2: + except Exception as e1: + frappe.log_error('error 4', str(e)) vehicle_req_list.append( {ERROR: UPDATE_FAILED}) - elif current_version > float(data1_global[0]['version']): - if current_version < float(data1[0]['version']): - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and vehicle_status='Active' and version > '{}' - and publish_module='Automotive System' order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) - try: - for d in data: - try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' + elif current_version == float(data1_global[0]['version']): + """ Check For only internal """ + frappe.log_error(str('global_test2')) - except Exception as e: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' + 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 + 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) - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e3: - vehicle_req_list.append( - {'Error': UPDATE_FAILED}) - # else: - # vehicle_req_list.append({'Error':"Else 3"}) - - else: - vehicle_req_list.append( - {LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)}) - elif data1 and publish_type == 'Internal': - frappe.log_error(str('internal update')) - data = frappe.db.sql('''SELECT name as Name,format(max(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 publish_type='{}' and vehicle_status='Active' - and publish_module='Automotive System' - and version > '{}' order by version DESC;'''.format(vehicle, l_id, publish_type, current_version), as_dict=1) - frappe.log_error(str(data)) - try: - for d in data: - try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-"+d[LANGUAGE] + \ - "-full_v"+str(d[VERSION])+JSON_EXT - frappe.log_error( - 'full_inernal' + str(file_name)) - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except: - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = FILE_ERROR - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float(current_version) - vehicle_req_list.append(d) - except Exception as e2: - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - if len(vehicle_req_list) != 0: - response['Vehicle'] = vehicle - response['VehicleReqList'] = vehicle_req_list - return response - else: - response['JSON'] = {STATUS: 0, ERROR: "Data Not available"} - return response - except Exception as e: - response['JSON'] = {STATUS: 0, ERROR: UPDATE_FAILED} - return response - else: - return {STATUS: 0, ERROR: "Check Parameter: vehicle list"} - - -@frappe.whitelist(allow_guest=1) -def check_vehicle_update(vehicle_list=None): - rate_res = custom_rate_limit(limit=5, seconds=15) - if rate_res != 1: - return rate_res - # if vehicle_list == None: - # return {STATUS: 0, ERROR: "Parameter missing: Vehicle List"} - val = input_validation(vehicle_list=vehicle_list) - if val != '': - return {STATUS: 0, ERROR: PARAM_MISSING+val} - - if vehicle_list: - try: - response = {} - req_list = json.loads(vehicle_list) - response['Vehicle'] = req_list['Vehicle'] - vehicle = req_list['Vehicle'] - iid = req_list['InstallationId'] - vehicle_data = req_list['VehicleReqList'] - publish_type = frappe.db.get_list( - 'App Device', filters={'name': iid}, fields='publish_type') - - if len(publish_type) > 0: - publish_type = publish_type[0]['publish_type'] - vehicle_req_list = [] - # Iterate on language - for v in vehicle_data: - l_id = v['LanguageID'] - current_version = float(v[CUR_VERSION]) - data1_global = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' - and publish_status='Published' and vehicle_status='Active' and publish_module='Automotive System' - and publish_type='Global'; - '''.format(vehicle, l_id, publish_type), as_dict=1) - - data1 = frappe.db.sql('''SELECT name,format(max(version),2) as version,vehicle_id,language FROM `tabPublish` where vehicle='{}' and language='{}' and - publish_status='Published' and vehicle_status='Active' and - publish_module='Automotive System' - order by version ASC;'''.format(vehicle, l_id), as_dict=1) - - if data1_global[0]['version']: - if data1[0]['version'] is not None: - if current_version == float(data1[0]['version']): - data1[0][UPDATE_AVAILABLE] = "false" - data = {} - data[LANGUAGE] = l_id - data[UPDATE_AVAILABLE] = 'false' - data[CUR_VERSION] = float(current_version) - vehicle_req_list.append(data) - - else: - if current_version < (float(data1_global[0]['version'])-1.00): - - 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='Global')'''.format(vehicle, l_id, publish_type), as_dict=1) - try: - for d in data: - try: - file_name = JSON_FULL_UPDATE_PATH+vehicle+"/"+vehicle + \ - "-" + \ - d[LANGUAGE]+"-"+"full_v" + \ - str(d[VERSION])+JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - frappe.log_error( - 'error1', str(e)) - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as 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): - 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='Global')'''.format(vehicle, l_id, publish_type), as_dict=1) - try: - for d in data: - file_name = None try: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION])+JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - frappe.log_error( - 'error 3', str(e)) - # file_name= None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e1: - 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 """ - - 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 - 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='{}')'''.format(vehicle, l_id, publish_type), 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 + 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) + file_size = os.path.getsize( + base_url + file_name) + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' + else: + file_name = JSON_INT_PATH+vehicle+"/" + \ + vehicle+"-" + \ + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT + file_size = os.path.getsize( + base_url + file_name) + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' + + except Exception as e: frappe.log_error( - 'File 1 ', file_name) - file_size = os.path.getsize( - base_url + file_name) + 'error 5', str(e)) + file_name = None + file_size = None d[JSON_URL] = file_name d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - else: + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' + + d[CUR_VERSION] = float( + current_version) + vehicle_req_list.append(d) + except Exception as e2: + 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')) + 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 + 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) + try: + for d in data: + try: + if float(data1[0]['version']) - current_version > 0.01: + file_name = JSON_FULL_INT_PATH + vehicle+"/" + \ + vehicle+"-" + \ + d[LANGUAGE]+"-full_v" + \ + str(d[VERSION]) + \ + JSON_EXT + frappe.log_error( + 'File 2 ', file_name) + file_size = os.path.getsize( + base_url + file_name) + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' + else: + file_name = JSON_INT_PATH+vehicle+"/" + \ + vehicle+"-" + \ + d[LANGUAGE]+"_v" + \ + str(d[VERSION]) + \ + JSON_EXT + file_size = os.path.getsize( + base_url + file_name) + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' + + except Exception as e: + frappe.log_error( + 'error 9', str(e)) file_name = JSON_INT_PATH+vehicle+"/" + \ vehicle+"-" + \ d[LANGUAGE]+"_v" + \ str(d[VERSION]) + \ JSON_EXT - file_size = os.path.getsize( - base_url + file_name) + file_size = None d[JSON_URL] = file_name d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - except Exception as e: - frappe.log_error( - 'error 5', str(e)) - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e2: - frappe.log_error('error 6', str(e)) - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif (float(data1_global[0]['version'])-1.00) < current_version < float(data1_global[0]['version']): - 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,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='{}')'''.format(vehicle, l_id, publish_type), as_dict=1) - try: - for d in data: - try: - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - frappe.log_error( - 'error 7', str(e)) - file_name = JSON_GLOABL_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e2: - frappe.log_error('error 8', str(e)) - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - elif current_version > float(data1_global[0]['version']): - 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 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 ='{}' )'''.format(vehicle, l_id, publish_type), as_dict=1) - try: - for d in data: - try: - if float(data1[0]['version']) - current_version > 0.01: - file_name = JSON_FULL_INT_PATH + vehicle+"/" + \ + d[CUR_VERSION] = float( + current_version) + vehicle_req_list.append(d) + except Exception as e3: + 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')) + if current_version < float(data1[0]['version']): + 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='{}' + 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)) + try: + for d in data: + try: + file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ - d[LANGUAGE]+"-full_v" + \ + d[LANGUAGE]+"_v" + \ str(d[VERSION]) + \ JSON_EXT - frappe.log_error( - 'File 2 ', file_name) file_size = os.path.getsize( base_url + file_name) d[JSON_URL] = file_name d[FILE_SIZE] = file_size d['Error'] = None d[UPDATE_AVAILABLE] = 'true' - else: - file_name = JSON_INT_PATH+vehicle+"/" + \ + + except Exception as e: + frappe.log_error( + 'error 7', str(e)) + file_name = JSON_GLOABL_PATH+vehicle+"/" + \ vehicle+"-" + \ d[LANGUAGE]+"_v" + \ str(d[VERSION]) + \ JSON_EXT - file_size = os.path.getsize( - base_url + file_name) + file_size = None d[JSON_URL] = file_name d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' - - except Exception as e: - frappe.log_error( - 'error 9', str(e)) - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-" + \ - d[LANGUAGE]+"_v" + \ - str(d[VERSION]) + \ - JSON_EXT - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = e - d[UPDATE_AVAILABLE] = 'false' + d['Error'] = e + d[UPDATE_AVAILABLE] = 'false' - d[CUR_VERSION] = float( - current_version) - vehicle_req_list.append(d) - except Exception as e3: - frappe.log_error( - 'error 10', str(e)) - vehicle_req_list.append( - {'Error': UPDATE_FAILED}) - # else: - # vehicle_req_list.append({'Error':"Else 3"}) + d[CUR_VERSION] = float( + current_version) + vehicle_req_list.append(d) + except Exception as e2: + frappe.log_error( + 'error 8', str(e)) + vehicle_req_list.append( + {ERROR: UPDATE_FAILED}) + else: + vehicle_req_list.append( + {LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)}) else: - vehicle_req_list.append( - {LANGUAGE: l_id, UPDATE_AVAILABLE: 'false', CUR_VERSION: float(current_version)}) - else: - data = frappe.db.sql('''SELECT name as Name,format(version,2) as Version,vehicle_id as Vehicle,language as Language 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='{}')'''.format(vehicle, l_id, publish_type), as_dict=1) - try: - for d in data: + 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` + 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) + if data: try: - file_name = JSON_INT_PATH+vehicle+"/" + \ - vehicle+"-"+d[LANGUAGE] + \ - "_v"+str(d[VERSION])+JSON_EXT - file_size = os.path.getsize( - base_url + file_name) - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = None - d[UPDATE_AVAILABLE] = 'true' + for d in data: + try: + file_name = JSON_INT_PATH+vehicle+"/" + \ + vehicle+"-"+d[LANGUAGE] + \ + "_v"+str(d[VERSION])+JSON_EXT + file_size = os.path.getsize( + base_url + file_name) + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = None + d[UPDATE_AVAILABLE] = 'true' + + except: + frappe.log_error( + 'error 11', str(e)) + file_name = None + file_size = None + d[JSON_URL] = file_name + d[FILE_SIZE] = file_size + d['Error'] = FILE_ERROR + d[UPDATE_AVAILABLE] = 'false' + + d[CUR_VERSION] = float(current_version) + vehicle_req_list.append(d) + except Exception as e2: + frappe.log_error('error 12', str(e)) + vehicle_req_list.append( + {ERROR: UPDATE_FAILED}) + if len(vehicle_req_list) > 0: + response['Vehicle'] = vehicle + response['VehicleReqList'] = vehicle_req_list + else: + return {STATUS: 0, ERROR: "No Vehicles in criteria"} - except: - frappe.log_error('error 11', str(e)) - file_name = None - file_size = None - d[JSON_URL] = file_name - d[FILE_SIZE] = file_size - d['Error'] = FILE_ERROR - d[UPDATE_AVAILABLE] = 'false' - - d[CUR_VERSION] = float(current_version) - vehicle_req_list.append(d) - except Exception as e2: - frappe.log_error('error 12', str(e)) - vehicle_req_list.append( - {ERROR: UPDATE_FAILED}) - - response['Vehicle'] = vehicle - response['VehicleReqList'] = vehicle_req_list return response else: response['JSON'] = {STATUS: 0, ERROR: "Data Not available"}