@@ -238,6 +238,13 @@ class Base:
238238 dict1 [i ] = dict2 [i ]
239239 return dict1
240240
241+ def format_time (self , milliseconds ):
242+ """convert milliseconds to format like \' Wed Aug 2 16:50:25 2023\' """
243+ if milliseconds is not None and isinstance (milliseconds , int ):
244+ return time .ctime (milliseconds / 1000 )
245+ else :
246+ return milliseconds
247+
241248 def exit_synctl (self , error_code = - 1 , message = '' ):
242249 """exit synctl"""
243250 if message != '' :
@@ -1001,6 +1008,23 @@ class SyntheticPoP(Base):
10011008 else :
10021009 return None
10031010
1011+ def __get_max_lo_label_length (self , loc_list , max_len = 60 ):
1012+ label_len = 12
1013+ display_label_len = 12
1014+ max_result = {
1015+ "max_label" : 35 ,
1016+ "max_display_label" : 50
1017+ }
1018+ if loc_list is not None and isinstance (loc_list , list ):
1019+ for lo in loc_list :
1020+ if lo is not None and label_len < len (lo ["label" ]):
1021+ label_len = len (lo ["label" ])
1022+ if lo is not None and display_label_len < len (lo ["displayLabel" ]):
1023+ display_label_len = len (lo ["displayLabel" ])
1024+ max_result ["max_label" ] = label_len if label_len < 60 else 60
1025+ max_result ["max_display_label" ] = display_label_len if display_label_len < 60 else 60
1026+ return max_result
1027+
10041028 def print_a_location_details (self , location_id , single_location , show_details = False ):
10051029 """show a Synthetic location details data"""
10061030 if single_location is None or len (single_location ) == 0 or location_id is None :
@@ -1010,7 +1034,10 @@ class SyntheticPoP(Base):
10101034 a_single_location = single_location [0 ]
10111035 print (self .fill_space ("Name" .upper (), 30 ), "value" .upper ())
10121036 for key , value in a_single_location .items ():
1013- print (self .fill_space (key , 30 ), value )
1037+ if key == 'createdAt' or key == 'modifiedAt' or key == 'observedAt' :
1038+ print (self .fill_space (key , 30 ), self .format_time (value ))
1039+ else :
1040+ print (self .fill_space (key , 30 ), value )
10141041
10151042 def delete_a_synthetic_pop (self , pop_id = "" ):
10161043 if pop_id != "" :
@@ -1060,17 +1087,19 @@ class SyntheticPoP(Base):
10601087 self .__print_pop (locations , locations_summary )
10611088
10621089 def __print_pop (self , pop_data : list , pop_locations_summary ):
1063-
1064- id_length = 30
1090+ id_length = 22
10651091 label_length = 35
10661092 display_label_length = 50
1067- status_length = 15
1068- no_of_tests_length = 15
1093+ status_length = 10
1094+ no_of_tests_length = 13
1095+ max_length = self .__get_max_lo_label_length (pop_data )
1096+ label_length = max_length ["max_label" ]
1097+ display_label_length = max_length ["max_display_label" ]
10691098 print (self .fill_space ("ID" .upper (), id_length ),
10701099 self .fill_space ("Label" .upper (), label_length ),
10711100 self .fill_space ("DisplayLabel" .upper (), display_label_length ),
10721101 self .fill_space ("Status" .upper (), status_length ),
1073- self .fill_space ("No. of tests " .upper (), no_of_tests_length ),
1102+ self .fill_space ("No. of Tests " .upper (), no_of_tests_length ),
10741103 "Description" .upper ())
10751104 if len (pop_data ) > 0 and pop_locations_summary is not None :
10761105 for pop in pop_data :
@@ -1411,13 +1440,12 @@ class SyntheticTest(Base):
14111440 label_1 = syn ["label" ]
14121441 match_result1 = prog .match (label_1 )
14131442 if match_result1 is not None :
1414- print (f"{ label_1 } is to delete " )
1443+ print (f"test \" { label_1 } \" " )
14151444 # delete it
14161445 delete_syn_id_lists .append (syn ["id" ])
14171446 print ('total match:' , len (delete_syn_id_lists ))
1418- if len (delete_syn_id_lists ) > 0 :
1419- if self .ask_answer ("are you sure to delete these tests?" ):
1420- self .delete_multiple_synthetic_tests (delete_syn_id_lists )
1447+ if len (delete_syn_id_lists ) > 0 and self .ask_answer ("are you sure to delete these tests?" ):
1448+ self .delete_multiple_synthetic_tests (delete_syn_id_lists )
14211449
14221450 def delete_tests_match_location (self , match_location = None ):
14231451 """delete all tests match location"""
@@ -1433,12 +1461,12 @@ class SyntheticTest(Base):
14331461 label_1 = syn ["label" ]
14341462 syn_locations = syn ["locations" ]
14351463 if syn_locations is not None and len (syn_locations ) == 1 and syn_locations [0 ] == match_location :
1436- print (f"{ label_1 } is to delete " )
1464+ print (f"test \" { label_1 } \" " )
14371465 # add to delete list
14381466 delete_syn_id_lists .append (syn ["id" ])
1439- print (f'total test with location { match_location } :' , len (
1467+ print (f'Total tests with location id \" { match_location } \" :' , len (
14401468 delete_syn_id_lists ))
1441- if self .ask_answer ("are you sure to delete these tests?" ):
1469+ if len ( delete_syn_id_lists ) > 0 and self .ask_answer ("are you sure to delete these tests?" ):
14421470 self .delete_multiple_synthetic_tests (delete_syn_id_lists )
14431471
14441472 def delete_tests_without_location (self ):
@@ -1450,11 +1478,14 @@ class SyntheticTest(Base):
14501478 label_1 = syn ["label" ]
14511479 syn_locations = syn ["locations" ]
14521480 if len (syn_locations ) == 0 :
1453- print (f"{ label_1 } is to delete " )
1481+ print (f"test \" { label_1 } \" " )
14541482 # delete it
14551483 delete_syn_id_lists .append (syn ["id" ])
1456- print ('total tests:' , len (delete_syn_id_lists ))
1457- if self .ask_answer ("are you sure to delete these tests?" ):
1484+ if len (delete_syn_id_lists ) > 0 :
1485+ print ('Total tests:' , len (delete_syn_id_lists ))
1486+ else :
1487+ print ('no tests match no locations' )
1488+ if len (delete_syn_id_lists ) > 0 and self .ask_answer ("are you sure to delete these tests?" ):
14581489 self .delete_multiple_synthetic_tests (delete_syn_id_lists )
14591490
14601491 def delete_a_credential (self , cred ):
@@ -1667,7 +1698,10 @@ class SyntheticTest(Base):
16671698 if key == "configuration" :
16681699 config_details = value
16691700 else :
1670- print (self .fill_space (key , 30 ), value )
1701+ if key == 'createdAt' or key == 'modifiedAt' :
1702+ print (self .fill_space (key , 30 ), self .format_time (value ))
1703+ else :
1704+ print (self .fill_space (key , 30 ), value )
16711705
16721706 print ("---- CONFIGURATION ----" )
16731707 # show script content
@@ -2616,14 +2650,15 @@ class ParseParameter:
26162650 self .parser_delete .add_argument (
26172651 'id' , type = str , nargs = "*" , metavar = "<id>" , help = 'Synthetic test id, location id, credential name' )
26182652
2619- # other options
2620- self .parser_delete .add_argument (
2621- '--match-regex' , type = str , default = None ,metavar = "<regex>" , help = 'use a regex to match Synthetic label' )
2653+ # delete test in batch options
2654+ delete_exclusive_group = self .parser_delete .add_mutually_exclusive_group ()
2655+ delete_exclusive_group .add_argument (
2656+ '--match-regex' , type = str , default = None , metavar = "<regex>" , help = 'use a regex to match Synthetic label' )
26222657 # only deletes tests full match location, if a test has two locations, include this, will
26232658 # not be deleted
2624- self . parser_delete .add_argument (
2659+ delete_exclusive_group .add_argument (
26252660 '--match-location' , type = str , default = None , metavar = "<id>" , help = 'delete tests match this location id' )
2626- self . parser_delete .add_argument (
2661+ delete_exclusive_group .add_argument (
26272662 '--no-locations' , action = "store_true" , help = "delete tests with no locations" )
26282663
26292664 self .parser_delete .add_argument (
0 commit comments