@ -245,6 +245,7 @@ def new_publish(args, publish_type, vehicle, language, version):
# Save file (Internal/Global)
with open ( file_name , ' w ' ) as outfile :
outfile . write ( json . dumps ( json_file ) )
get_step_total_count ( file_name )
# Remove previous internal publish file
if publish_type . lower ( ) == ' internal ' :
@ -262,7 +263,10 @@ def new_publish(args, publish_type, vehicle, language, version):
and publish_type = ' Global ' AND ` language ` = ' {} ' order by version desc limit 2 ; ''' .format(vehicle,language),as_dict=True)
if pub_ver :
if pub_ver [ 0 ] [ ' version ' ] != ' 1.00 ' :
prev_update_ver = pub_ver [ 1 ] [ ' version ' ]
else :
prev_update_ver = pub_ver [ 0 ] [ ' version ' ]
full_update_file_name = full_update_path + vehicle + ' / ' + ' %s - %s -full_v %s .json ' % ( vehicle , language , version )
@ -270,6 +274,7 @@ def new_publish(args, publish_type, vehicle, language, version):
if version == ' 1.00 ' :
with open ( full_update_file_name , ' w ' ) as outfile :
outfile . write ( json . dumps ( json_file ) )
get_step_total_count ( full_update_file_name )
else :
prev_full_update_file = full_update_path + vehicle + ' / ' + ' %s - %s -full_v %s .json ' % ( vehicle , language , prev_update_ver )
@ -277,7 +282,9 @@ def new_publish(args, publish_type, vehicle, language, version):
list1 . append ( file_name )
list1 . append ( full_update_file_name )
final_update_file = merge_json_files ( prev_full_update_file , file_name , full_update_file_name )
return file_name . split ( ' public ' ) [ 1 ] , list1
get_step_total_count ( final_update_file )
return file_name . split ( ' public ' ) [ 1 ]
except :
return " Failed to save file "
@ -513,6 +520,51 @@ def merge_json_files(old_json_path,new_json_path,out_file_path):
except Exception as e :
return e
def get_step_total_count ( json_path ) :
with open ( json_path ) as json_file :
data = json . load ( json_file )
total_count = calculate_total ( data )
generate_json ( data , json_path )
return total_count
def generate_json ( data , json_path ) :
json_object = json . dumps ( data )
with open ( json_path , " w " ) as outfile :
outfile . write ( json_object )
def calculate_total ( data ) :
for variant in data [ ' JSON ' ] :
total_count = 0
step_count = 0
total_count + = len ( variant [ ' Variant ' ] [ ' Assets ' ] )
total_count + = len ( variant [ ' Variant ' ] [ ' Systems ' ] )
for system in variant [ ' Variant ' ] [ ' Systems ' ] :
total_count + = len ( system [ ' Assets ' ] )
total_count + = len ( system [ ' Subsystems ' ] )
for subsystem in system [ ' Subsystems ' ] :
try :
total_count + = len ( subsystem [ ' Config Kilometer ' ] )
except Exception as e :
pass
try :
total_count + = len ( subsystem [ ' Procedure_details ' ] )
except Exception as e :
pass
try :
for step in subsystem [ ' Procedure_details ' ] :
total_count + = len ( step [ ' steps ' ] )
step_count + = len ( step [ ' steps ' ] )
except Exception as e :
pass
variant [ ' TotalCount ' ] = total_count
variant [ ' StepCount ' ] = step_count
return data
# def get_data(args):
# try:
# docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},