@@ -103,6 +103,7 @@ def get_width(line):
103
103
def process_test_file (code_lines , new_lang ):
104
104
detected_lang = None
105
105
changed = False
106
+ found_bc = False # Found BaseCase or a translation
106
107
seleniumbase_lines = []
107
108
lang_codes = MD_L_Codes .lang
108
109
nl_code = lang_codes [new_lang ] # new_lang language code
@@ -127,6 +128,7 @@ def process_test_file(code_lines, new_lang):
127
128
changed = True
128
129
new_line = MD_F .get_import_line (new_lang ) + comments
129
130
else :
131
+ found_bc = True
130
132
new_line = line
131
133
if new_line .endswith (" # noqa" ): # Remove flake8 skip
132
134
new_line = new_line [0 :- len (" # noqa" )]
@@ -144,6 +146,7 @@ def process_test_file(code_lines, new_lang):
144
146
changed = True
145
147
new_line = MD_F .get_mqa_im_line (new_lang ) + comments
146
148
else :
149
+ found_bc = True
147
150
new_line = line
148
151
if new_line .endswith (" # noqa" ): # Remove flake8 skip
149
152
new_line = new_line [0 :- len (" # noqa" )]
@@ -176,6 +179,7 @@ def process_test_file(code_lines, new_lang):
176
179
'%sclass %s(%s):%s'
177
180
'' % (whitespace , name , new_parent , comments ))
178
181
else :
182
+ found_bc = True
179
183
new_line = line
180
184
if new_line .endswith (" # noqa" ): # Remove flake8 skip
181
185
new_line = new_line [0 :- len (" # noqa" )]
@@ -192,6 +196,7 @@ def process_test_file(code_lines, new_lang):
192
196
'%sclass %s(%s):%s'
193
197
'' % (whitespace , name , new_parent , comments ))
194
198
else :
199
+ found_bc = True
195
200
new_line = line
196
201
if new_line .endswith (" # noqa" ): # Remove flake8 skip
197
202
new_line = new_line [0 :- len (" # noqa" )]
@@ -231,7 +236,7 @@ def process_test_file(code_lines, new_lang):
231
236
232
237
seleniumbase_lines .append (line )
233
238
234
- return seleniumbase_lines , changed , detected_lang
239
+ return seleniumbase_lines , changed , detected_lang , found_bc
235
240
236
241
237
242
def main ():
@@ -447,17 +452,47 @@ def main():
447
452
all_code = all_code .replace ("\t " , " " )
448
453
code_lines = all_code .split ('\n ' )
449
454
450
- seleniumbase_lines , changed , d_l = process_test_file (code_lines , new_lang )
455
+ sb_lines , changed , d_l , found_bc = process_test_file (code_lines , new_lang )
456
+ seleniumbase_lines = sb_lines
451
457
detected_lang = d_l
458
+ found_basecase = found_bc
452
459
453
- if not changed :
454
- msg = ('\n *> [%s] was already in %s! * No changes were made! <*\n '
455
- '' % (seleniumbase_file , new_lang ))
456
- msg = msg .replace ("*> " , "*> " + c2 ).replace (" <*" , cr + " <*" )
457
- print (msg )
460
+ if not changed and found_basecase :
461
+ print ("" )
462
+ msg1 = (" [[[[%s]]]] was already in [[[%s]]]!\n \n "
463
+ "" % (seleniumbase_file , new_lang ))
464
+ msg1 = msg1 .replace ("[[[[" , "" + c3 ).replace ("]]]]" , cr + "" )
465
+ msg1 = msg1 .replace ("[[[" , "" + c5 ).replace ("]]]" , cr + "" )
466
+ msg2 = None
467
+ if print_only :
468
+ msg2 = '*> *** No changes to display! *** <*'
469
+ elif overwrite :
470
+ msg2 = '*> *** No changes were made! *** <*'
471
+ else : # "copy" action
472
+ msg2 = '*> *** No action was taken! *** <*'
473
+ msg2 = msg2 .replace ("*>" , " " + c6 ).replace ("<*" , cr + '\n ' )
474
+ print (msg1 + msg2 )
475
+ return
476
+
477
+ if not changed and not found_basecase :
478
+ print ("" )
479
+ filename = c3 + seleniumbase_file + cr
480
+ from_sb = c5 + "from seleniumbase" + cr
481
+ msg0 = (' * In order to translate the script,\n ' )
482
+ msg1 = (' %s requires "%s..."\n ' % (filename , from_sb ))
483
+ msg2 = (" and a BaseCase import in a supported language!\n \n " )
484
+ msg3 = None
485
+ if print_only :
486
+ msg3 = '*> *** No changes to display! *** <*'
487
+ elif overwrite :
488
+ msg3 = '*> *** No changes were made! *** <*'
489
+ else : # "copy" action
490
+ msg3 = '*> *** No action was taken! *** <*'
491
+ msg3 = msg3 .replace ("*>" , " " + c6 ).replace ("<*" , cr + '\n ' )
492
+ print (msg0 + msg1 + msg2 + msg3 )
458
493
return
459
494
460
- save_line = ("[[[[%s]]]] was translated to [[[%s]]]! "
495
+ save_line = (" [[[[%s]]]] was translated to [[[%s]]]! "
461
496
"(Previous: %s)\n "
462
497
"" % (seleniumbase_file , new_lang , detected_lang ))
463
498
save_line = save_line .replace ("[[[[" , "" + c4 )
@@ -684,7 +719,7 @@ def main():
684
719
magic_console = Console ()
685
720
print ("" )
686
721
print (save_line )
687
- print (c1 + "* Here are the results: >>>" + cr )
722
+ print (" " + c1 + " *** Here are the results: >>> " + cr )
688
723
# ----------------------------------------
689
724
dash_length = 62 # May change
690
725
if used_width and used_width + w < console_width :
0 commit comments