@ -7,7 +7,8 @@ import time
from smart_service . apis . app_user_login import input_validation
current_db_name = frappe . conf . get ( " db_name " )
site_name = cstr ( frappe . local . site )
base_url = os . path . expanduser ( " ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
base_url = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
def get_parent_map ( input_list , parameter ) :
@ -31,8 +32,8 @@ def get_parent_map(input_list, parameter):
def check_all_vehicle_updates ( vehicle_list = None ) :
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
return { " status " : 0 , " error " : " Parameter missing: " + val }
if vehicle_list :
@ -44,7 +45,8 @@ def check_all_vehicle_updates(vehicle_list=None):
iid = v_list [ ' InstallationId ' ]
vehicle_data = v_list [ ' VehicleReqList ' ]
publish_type = frappe . db . sql (
''' SELECT publish_type FROM {} .`tabApp Device` where name= ' {} ' ; ''' . format ( current_db_name , iid ) ,
''' SELECT publish_type FROM {} .`tabApp Device` where name= ' {} ' ; ''' . format (
current_db_name , iid ) ,
as_list = True )
if publish_type [ 0 ] [ 0 ] is not None :
@ -67,10 +69,10 @@ def check_all_vehicle_updates(vehicle_list=None):
if current_version < float ( data1_global [ 0 ] [ ' version ' ] ) :
data = frappe . db . sql ( ''' SELECT name,max(version) as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' Global ' and vehicle_status = ' Active ' and version > ' {} ' order by version ASC ; ''' .format(
current_db_name , v_id , lang , current_version ) , as_dict = True )
current_db_name , v_id , lang , current_version ) , as_dict = True )
elif current_version == float ( data1_global [ 0 ] [ ' version ' ] ) :
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
data = frappe . db . sql ( ''' SELECT name,max(version) as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' {} ' and vehicle_status = ' Active ' and version > ' {} ' order by version ASC ; ''' .format(
current_db_name , v_id , lang , publish_type [ 0 ] [ 0 ] , current_version ) , as_dict = True )
@ -79,7 +81,8 @@ def check_all_vehicle_updates(vehicle_list=None):
try :
for d in data :
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
data_append . append ( d )
Vehicle_req_list . append ( data_append )
except :
@ -98,32 +101,34 @@ def check_all_vehicle_updates(vehicle_list=None):
return { " status " : 0 , " error " : " Invalid Publish Details " }
except Exception as e :
return { " status " : 0 , " error " : e }
return { " status " : 0 , " error " : " Fail ed to fetch updates " }
else :
return { " status " : 0 , " error " : " Check argument: vehicle list " }
@frappe . whitelist ( )
def check_vehicle_update ( vehicle_list = None ) :
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
return { " status " : 0 , " error " : " Parameter missing: " + val }
if vehicle_list :
try :
response = { }
req_list = json . loads ( vehicle_list )
response [ ' Vehicle ' ] = req_list [ ' Vehicle ' ]
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 ' )
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
# Iterate on language
for v in vehicle_data :
l_id = v [ ' LanguageID ' ]
current_version = float ( v [ ' CurrentVersion ' ] )
@ -134,12 +139,12 @@ def check_vehicle_update(vehicle_list=None):
data1 = frappe . db . sql ( ''' SELECT name,max(version) as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and vehicle_status = ' Active ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id ) , as_dict = True )
if data1_global [ 0 ] [ ' version ' ] :
if data1_global [ 0 ] [ ' version ' ] :
if data1 [ 0 ] [ ' version ' ] is not None :
if current_version == float ( data1 [ 0 ] [ ' version ' ] ) :
data1 [ 0 ] [ ' IsUpdateAvailable ' ] = " false "
data = { }
data [ ' Language ' ] = l_id
data = { }
data [ ' Language ' ] = l_id
data [ ' IsUpdateAvailable ' ] = ' false '
data [ ' CurrentVersion ' ] = float ( current_version )
Vehicle_req_list . append ( data )
@ -148,82 +153,101 @@ def check_vehicle_update(vehicle_list=None):
if current_version < ( float ( data1_global [ 0 ] [ ' version ' ] ) - 1.00 ) :
data = frappe . db . sql ( ''' SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' Global ' and vehicle_status = ' Active ' and Version > ' {} ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id , current_version ) , as_dict = True )
current_db_name , vehicle , l_id , current_version ) , as_dict = True )
try :
for d in data :
try :
file_name = " /files/json_files/full_update/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " - " + " full_v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/full_update/ " + vehicle + " / " + vehicle + \
" - " + \
d [ ' Language ' ] + " - " + " full_v " + \
str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
file_name = None
file_name = None
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
Vehicle_req_list . append ( d )
except Exception as e :
Vehicle_req_list . append ( { " Error " : e } )
Vehicle_req_list . append (
{ " Error " : " Update checking Failed " } )
elif current_version == ( float ( data1_global [ 0 ] [ ' version ' ] ) - 1.00 ) :
data = frappe . db . sql ( ''' SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' Global ' and vehicle_status = ' Active ' and Version > ' {} ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id , current_version ) , as_dict = True )
current_db_name , vehicle , l_id , current_version ) , as_dict = True )
try :
for d in data :
file_name = None
try :
file_name = " /files/json_files/global/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/global/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
# file_name= None
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
Vehicle_req_list . append ( d )
except Exception as e1 :
Vehicle_req_list . append ( { " Error " : e1 } )
Vehicle_req_list . append (
{ " Error " : " Update checking Failed " } )
elif current_version == float ( data1_global [ 0 ] [ ' version ' ] ) :
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
data = frappe . db . sql ( ''' SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' {} ' and vehicle_status = ' Active ' and version > ' {} ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id , publish_type , current_version ) , as_dict = True )
try :
for d in data :
try :
file_name = " /files/json_files/internal/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/internal/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + \
" .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
file_name = None
file_name = None
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
Vehicle_req_list . append ( d )
except Exception as e2 :
Vehicle_req_list . append ( { " Error " : e2 } )
Vehicle_req_list . append (
{ " Error " : " Update checking Failed " } )
elif ( float ( data1_global [ 0 ] [ ' version ' ] ) - 1.00 ) < current_version < float ( data1_global [ 0 ] [ ' version ' ] ) :
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
@ -233,24 +257,35 @@ def check_vehicle_update(vehicle_list=None):
try :
for d in data :
try :
file_name = " /files/json_files/global/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/global/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + \
" .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
file_name = " /files/json_files/global/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_name = " /files/json_files/global/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + \
" .json "
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
Vehicle_req_list . append ( d )
except Exception as e2 :
Vehicle_req_list . append ( { " Error " : e2 } )
Vehicle_req_list . append (
{ " Error " : " Update checking Failed " } )
# else:
# Vehicle_req_list.append({"error2":"Else"})
@ -258,28 +293,39 @@ def check_vehicle_update(vehicle_list=None):
if current_version < float ( data1 [ 0 ] [ ' version ' ] ) :
data = frappe . db . sql ( ''' SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' {} ' and vehicle_status = ' Active ' and version > ' {} ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id , publish_type , current_version ) , as_dict = True )
current_db_name , vehicle , l_id , publish_type , current_version ) , as_dict = True )
try :
for d in data :
try :
file_name = " /files/json_files/internal/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/internal/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + \
" .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
file_name = " /files/json_files/internal/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_name = " /files/json_files/internal/ " + vehicle + " / " + \
vehicle + " - " + \
d [ ' Language ' ] + " _v " + \
str ( d [ ' Version ' ] ) + \
" .json "
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
d [ ' CurrentVersion ' ] = float (
current_version )
Vehicle_req_list . append ( d )
except Exception as e3 :
Vehicle_req_list . append ( { ' Error ' : e3 } )
Vehicle_req_list . append (
{ ' Error ' : " Update checking Failed " } )
# else:
# Vehicle_req_list.append({'Error':"Else 3"})
@ -289,28 +335,32 @@ def check_vehicle_update(vehicle_list=None):
else :
data = frappe . db . sql ( ''' SELECT name as Name,max(version) as Version,vehicle_id as Vehicle,language as Language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and publish_status= ' Published '
and publish_type = ' {} ' and vehicle_status = ' Active ' and version > ' {} ' order by version ASC ; ''' .format(
current_db_name , vehicle , l_id , publish_type , current_version ) , as_dict = True )
current_db_name , vehicle , l_id , publish_type , current_version ) , as_dict = True )
try :
for d in data :
try :
file_name = " /files/json_files/internal/ " + vehicle + " / " + vehicle + " - " + d [ ' Language ' ] + " _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
file_name = " /files/json_files/internal/ " + vehicle + " / " + \
vehicle + " - " + d [ ' Language ' ] + \
" _v " + str ( d [ ' Version ' ] ) + " .json "
file_size = os . path . getsize (
base_url + file_name )
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = None
except :
file_name = None
file_name = None
file_size = None
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' JsonURL ' ] = file_name
d [ ' FileSize ' ] = file_size
d [ ' Error ' ] = ' File failed to load '
d [ ' IsUpdateAvailable ' ] = ' true '
d [ ' CurrentVersion ' ] = float ( current_version )
Vehicle_req_list . append ( d )
except Exception as e2 :
Vehicle_req_list . append ( { " Error " : e2 } )
Vehicle_req_list . append (
{ " Error " : " Update checking Failed " } )
response [ ' Vehicle ' ] = vehicle
response [ ' VehicleReqList ' ] = Vehicle_req_list
@ -319,11 +369,12 @@ def check_vehicle_update(vehicle_list=None):
response [ ' JSON ' ] = { " status " : 0 , " Error " : " Data Not available " }
return response
except Exception as e :
response [ ' JSON ' ] = { " status " : 0 , " error " : e }
response [ ' JSON ' ] = { " status " : 0 , " error " : " Updat e checking Failed " }
return response
else :
return { " status " : 0 , " error " : " Check Parameter: vehicle list " }
def get_step_total_count ( json_path ) :
with open ( json_path ) as json_file :
data = json . load ( json_file )
@ -382,11 +433,10 @@ def calculate_step(data):
return data
@frappe . whitelist ( )
def check_vehicle_update11 ( vehicle_list = None ) :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
return { " status " : 0 , " error " : " Parameter missing: " + val }
# if vehicle_list == None:
# return {"status": 0, "error": "Parameter missing: Vehicle List"}
@ -395,58 +445,65 @@ def check_vehicle_update11(vehicle_list=None):
if vehicle_list :
response = { }
req_list = json . loads ( vehicle_list )
response [ ' Vehicle ' ] = req_list [ ' Vehicle ' ]
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 ' )
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 ' ]
# Iterate over language
# Iterate over language
if publish_type == ' Internal ' :
for v in vehicle_data :
for v in vehicle_data :
global_ver = frappe . db . sql ( ''' SELECT max(version) as version,publish_type as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} '
and language = ' {} ' and publish_status = ' Published ' and vehicle_status = ' Active ' and publish_type = ' Global ' ; ''' .format(
current_db_name , vehicle , l_id ) , as_dict = True )
current_db_name , vehicle , l_id ) , as_dict = True )
if global_ver :
global_pub_ver = global_pub_ver [ ' version ' ]
l_id = v [ ' LanguageID ' ]
cur_ver = v [ ' CurrentVersion ' ]
pub_ver = get_publish_ver ( vehicle , l_id )
pub_ver = get_publish_ver ( vehicle , l_id )
if cur_ver == pub_ver [ ' version ' ] :
Vehicle_req_list . append ( { ' Language ' : l_id , ' IsUpdateAvailable ' : ' false ' ,
' CurrentVersion ' : float ( cur_ver ) } )
' CurrentVersion ' : float ( cur_ver ) } )
# Global File
else :
for v in vehicle_data :
l_id = v [ ' LanguageID ' ]
cur_ver = v [ ' CurrentVersion ' ]
global_pub = frappe . db . sql ( ''' SELECT max(version) as version,publish_type, vehicle_id,language FROM {} .tabPublish where vehicle= ' {} '
and language = ' {} ' and publish_status = ' Published ' and vehicle_status = ' Active ' and publish_type = ' Global ' ; ''' .format(
current_db_name , vehicle , l_id ) , as_dict = True )
current_db_name , vehicle , l_id ) , as_dict = True )
if global_pub :
if global_pub :
global_pub_ver1 = float ( global_pub [ 0 ] [ ' version ' ] )
if global_pub_ver1 == cur_ver :
Vehicle_req_list . append ( { ' Language ' : l_id , ' IsUpdateAvailable ' : ' false ' ,
' CurrentVersion ' : float ( cur_ver ) } )
' CurrentVersion ' : float ( cur_ver ) } )
else :
if cur_ver < global_pub_ver1 :
if ( global_pub_ver1 - cur_ver ) > 1 :
file_name = " /files/json_files/full_update/ " + vehicle + " / " + vehicle + " - " + l_id + " - " + " full_v " + str ( global_pub [ 0 ] [ ' version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
Vehicle_req_list . append ( { ' Version ' : global_pub_ver1 , ' Language ' : l_id , ' IsUpdateAvailable ' : ' true ' , ' JsonURL ' : file_name , ' FileSize ' : file_size ,
' Error ' : None , ' CurrentVersion ' : float ( cur_ver ) } )
file_name = " /files/json_files/full_update/ " + vehicle + " / " + vehicle + \
" - " + l_id + " - " + " full_v " + \
str ( global_pub [ 0 ] [ ' version ' ] ) + " .json "
file_size = os . path . getsize (
base_url + file_name )
Vehicle_req_list . append ( { ' Version ' : global_pub_ver1 , ' Language ' : l_id , ' IsUpdateAvailable ' : ' true ' , ' JsonURL ' : file_name , ' FileSize ' : file_size ,
' Error ' : None , ' CurrentVersion ' : float ( cur_ver ) } )
else :
file_name = " /files/json_files/global/ " + vehicle + " / " + vehicle + " - " + l_id + " _v " + str ( global_pub [ 0 ] [ ' version ' ] ) + " .json "
file_size = os . path . getsize ( base_url + file_name )
Vehicle_req_list . append ( { ' Version ' : global_pub_ver1 , ' Language ' : l_id , ' IsUpdateAvailable ' : ' true ' , ' JsonURL ' : file_name , ' FileSize ' : file_size ,
' Error ' : None , ' CurrentVersion ' : float ( cur_ver ) } )
file_name = " /files/json_files/global/ " + vehicle + " / " + vehicle + \
" - " + l_id + " _v " + \
str ( global_pub [ 0 ] [ ' version ' ] ) + " .json "
file_size = os . path . getsize (
base_url + file_name )
Vehicle_req_list . append ( { ' Version ' : global_pub_ver1 , ' Language ' : l_id , ' IsUpdateAvailable ' : ' true ' , ' JsonURL ' : file_name , ' FileSize ' : file_size ,
' Error ' : None , ' CurrentVersion ' : float ( cur_ver ) } )
else :
Vehicle_req_list . append ( { ' Language ' : l_id , ' IsUpdateAvailable ' : ' false ' ,
@ -454,11 +511,10 @@ def check_vehicle_update11(vehicle_list=None):
return Vehicle_req_list
def get_publish_ver ( vehicle , l_id ) :
def get_publish_ver ( vehicle , l_id ) :
return frappe . db . sql ( ''' SELECT max(version) as version,publish_type as version,vehicle_id,language FROM {} .tabPublish where vehicle= ' {} ' and language= ' {} ' and
publish_status = ' Published ' and vehicle_status = ' Active ' ; ''' .format(
current_db_name , vehicle , l_id ) , as_dict = True )
current_db_name , vehicle , l_id ) , as_dict = True )
# @frappe.whitelist()
@ -477,7 +533,7 @@ def get_publish_ver(vehicle,l_id):
# if len(publish_type) > 0:
# publish_type = publish_type[0]['publish_type']
# Vehicle_req_list = []
# # Iterate on language
# # Iterate on language
# for v in vehicle_data:
# appendList = []
# appendDict = {}
@ -491,13 +547,13 @@ def get_publish_ver(vehicle,l_id):
# l_id = v['LanguageID']
# current_version = v['CurrentVersion']
# # Not necessary
# # Not necessary
# if publish_type == 'Internal':
# publish_data = frappe.db.sql('''select name,CAST(version AS DECIMAL(10,2)) as version from {}.tabPublish where vehicle= '{}'
# publish_data = frappe.db.sql('''select name,CAST(version AS DECIMAL(10,2)) as version from {}.tabPublish where vehicle= '{}'
# and language='{}' and publish_type = '{}' and version > {} and vehicle_status = 'Active';
# '''.format(current_db_name, vehicle, l_id, publish_type, current_version), as_dict=True)
# else:
# publish_data = frappe.db.sql('''select name,version,release_description as description from {}.tabPublish where vehicle= '{}'
# publish_data = frappe.db.sql('''select name,version,release_description as description from {}.tabPublish where vehicle= '{}'
# and language='{}' and publish_type = '{}' and version > {} and vehicle_status = 'Active'; '''.format(
# current_db_name, vehicle, l_id, publish_type,
# current_version), as_dict=True)
@ -567,7 +623,7 @@ def get_publish_ver(vehicle,l_id):
# FROM {}.`tabVariant Mapping` WHERE name ='{}' ; '''.format(current_db_name, d),
# as_dict=True)[0]
# var_asset = frappe.db.sql('''SELECT category, attach_file as file, {},idx as variant_asset_idx FROM {}.`tabVariant Mapping_Assets`
# var_asset = frappe.db.sql('''SELECT category, attach_file as file, {},idx as variant_asset_idx FROM {}.`tabVariant Mapping_Assets`
# where category<>'Technical Manual' and parent='{}' and language='{}';'''.format(
# active_status_case, current_db_name, d, l_id), as_dict=True)
@ -598,8 +654,8 @@ def get_publish_ver(vehicle,l_id):
# for i in appendDict[d]:
# if i is not None:
# sys = frappe.db.sql(''' SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status FROM
# {0}.`tabSystem Mapping_Sub System` as tmss inner join {0}.`tabSystems` as ts on tmss.systems = ts.system_name
# sys = frappe.db.sql(''' SELECT min(tmss.idx) as systemdisplayorder,ts.system_name,ts.icon_file,ts.myid,ts.active_status FROM
# {0}.`tabSystem Mapping_Sub System` as tmss inner join {0}.`tabSystems` as ts on tmss.systems = ts.system_name
# where tmss.parent LIKE '{1}' and substring(tmss.parent,-5,2) = '{2}' and tmss.systems ='{3}';'''
# .format(current_db_name, str(vari['name'] + "%"), l_id, i),
# as_dict=True)[0]
@ -610,7 +666,7 @@ def get_publish_ver(vehicle,l_id):
# sys['active_status'] = False
# # System Assets
# sysassets = frappe.db.sql('''SELECT idx as systemdisplayorder, system_asset,active_status FROM {3}.`tabSystem Mapping_System Assets`
# sysassets = frappe.db.sql('''SELECT idx as systemdisplayorder, system_asset,active_status FROM {3}.`tabSystem Mapping_System Assets`
# where parent like '{0}%' and language='{1}' and systems='{2}';'''.format(
# d, l_id, i, current_db_name), as_dict=True)
# for sysasset in sysassets:
@ -625,10 +681,10 @@ def get_publish_ver(vehicle,l_id):
# # Sub system
# subsystem_out = []
# for j in appendDict[d][i]:
# subsys = frappe.db.sql('''select `tabSystem Mapping_Sub System`.idx as subSystemdisplayorder, systems,sub_systems, symptom,
# subsys = frappe.db.sql('''select `tabSystem Mapping_Sub System`.idx as subSystemdisplayorder, systems,sub_systems, symptom,
# component, estimate_time as estimated_time, rts, mat, cover_image, `tabSub Systems`.myid,`tabSystem Mapping_Sub System`.active_status,
# `tabSystem Mapping_Sub System`.cover_image from {4}.`tabSystem Mapping_Sub System` inner join {4}.`tabSub Systems` on
# `tabSystem Mapping_Sub System`.sub_systems = `tabSub Systems`.name where `tabSystem Mapping_Sub System`.parent like '{0}-{3}%' and
# `tabSystem Mapping_Sub System`.cover_image from {4}.`tabSystem Mapping_Sub System` inner join {4}.`tabSub Systems` on
# `tabSystem Mapping_Sub System`.sub_systems = `tabSub Systems`.name where `tabSystem Mapping_Sub System`.parent like '{0}-{3}%' and
# systems='{1}' and sub_systems='{2}' and `tabSystem Mapping_Sub System`.active_status = 'Active';'''.format(
# d, i, j, l_id, current_db_name), as_dict=True)
@ -639,17 +695,17 @@ def get_publish_ver(vehicle,l_id):
# else:
# subsys['active_status'] = False
# kms = frappe.db.sql('''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable
# FROM {}.`tabKilometer Mapping_Items` where sub_systems='{}' and parent Like '{}' and substring(parent,-5,2) = '{}'
# kms = frappe.db.sql('''SELECT kilometer as kilometer_name, idx as kilometer_IDX, applicable as kilometers_applicable
# FROM {}.`tabKilometer Mapping_Items` where sub_systems='{}' and parent Like '{}' and substring(parent,-5,2) = '{}'
# order by kilometer_IDX;'''.format(current_db_name, j, d + "%",
# l_id),
# as_dict=True)
# total_count += len(kms)
# subsys['Config Kilometer'] = kms
# for k in appendDict[d][i][j]:
# proc_details = frappe.db.sql('''select procedure_name, step_name, content_type,
# proc_details = frappe.db.sql('''select procedure_name, step_name, content_type,
# GROUP_CONCAT(case when content_type='Link' Then system_id else content end) as content,
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# GROUP_CONCAT(file) as file,GROUP_CONCAT(DISTINCT idx order by idx) as display_order, idx from {}.tabProcedure_Details
# where parent ='{}' group by procedure_name,step_name,content_type,content order by idx asc; '''
# .format(current_db_name, k), as_dict=True)
@ -689,14 +745,14 @@ def get_publish_ver(vehicle,l_id):
# with open(base_url + file_name, 'w') as outfile:
# outfile.write(json.dumps(dicfinal))
# file_size = os.path.getsize(base_url + file_name)
# res['JsonURL'] = file_name
# res['FileSize'] = file_size
# res['Error'] = None
# except:
# res['JsonURL'] = None
# res['FileSize'] = None
@ -707,7 +763,7 @@ def get_publish_ver(vehicle,l_id):
# Vehicle_req_list.append(
# {'Language': l_id, 'IsUpdateAvailable': 'false', 'CurrentVersion': float(current_version)})
# response['Vehicle'] = vehicle
# response['VehicleReqList'] = Vehicle_req_list
# return response
@ -724,28 +780,28 @@ def get_publish_ver(vehicle,l_id):
@frappe . whitelist ( )
def update_completed ( FileName = None ) :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
val = input_validation ( vehicle_list = vehicle_list )
if val != ' ' :
return { " status " : 0 , " error " : " Parameter missing: " + val }
# if FileName == None:
# return {'status': 0, 'error': "Parameter missing: FileName"}
if FileName :
try :
os . remove ( base_url + FileName )
return { ' isSuccessful ' : True }
except Exception as e :
return { ' isSuccessful ' : False , " status " : 0 , ' error ' : e }
return { ' isSuccessful ' : False , " status " : 0 , ' error ' : e }
else :
return { " status " : 0 , " error " : " Parameter: FileName is null " }
@frappe . whitelist ( )
def delete_complete ( doc = None , method = None ) :
base_url1 = os . path . expanduser ( " ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
base_url1 = os . path . expanduser (
" ~ " ) + " /frappe-bench/sites/ " + site_name + " /public "
path = base_url1 + ' /files/json_files/temp/ '
path_file = os . listdir ( path )
if path_file :
for file in path_file :
os . remove ( str ( path ) + str ( file ) )