14
14
-p / --print (Print translation output to the screen)
15
15
-o / --overwrite (Overwrite the file being translated)
16
16
-c / --copy (Copy the translation to a new .py file)
17
+ Options:
18
+ -n (include line Numbers when using the Print action)
17
19
Output:
18
20
Translates a SeleniumBase Python file into the language
19
21
specified. Method calls and "import" lines get swapped.
@@ -52,6 +54,8 @@ def invalid_run_command(msg=None):
52
54
exp += " -p / --print (Print translation output to the screen)\n "
53
55
exp += " -o / --overwrite (Overwrite the file being translated)\n "
54
56
exp += " -c / --copy (Copy the translation to a new .py file)\n "
57
+ exp += " Options:\n "
58
+ exp += " -n (include line Numbers when using the Print action)\n "
55
59
exp += " Output:\n "
56
60
exp += " Translates a SeleniumBase Python file into the language\n "
57
61
exp += ' specified. Method calls and "import" lines get swapped.\n '
@@ -68,8 +72,8 @@ def invalid_run_command(msg=None):
68
72
raise Exception ('INVALID RUN COMMAND!\n %s\n \n %s' % (msg , exp ))
69
73
70
74
71
- def ranges ():
72
- # Get the ranges of special characters of Chinese, Japanese, and Korean
75
+ def sc_ranges ():
76
+ # Get the ranges of special characters of Chinese, Japanese, and Korean.
73
77
special_char_ranges = ([
74
78
{"from" : ord (u"\u3300 " ), "to" : ord (u"\u33ff " )},
75
79
{"from" : ord (u"\ufe30 " ), "to" : ord (u"\ufe4f " )},
@@ -89,13 +93,15 @@ def ranges():
89
93
90
94
91
95
def is_cjk (char ):
92
- # Returns True if the special character is Chinese, Japanese, or Korean
93
- sc = any ([range ["from" ] <= ord (char ) <= range ["to" ] for range in ranges ()])
96
+ # Returns True if the special character is Chinese, Japanese, or Korean.
97
+ sc = any (
98
+ [range ["from" ] <= ord (char ) <= range ["to" ] for range in sc_ranges ()])
94
99
return sc
95
100
96
101
97
102
def get_width (line ):
98
- # Chinese/Japanese/Korean characters take up double width visually
103
+ # Return the true width of the line. Not the same as line length.
104
+ # Chinese/Japanese/Korean characters take up double width visually.
99
105
line_length = len (line )
100
106
for char in line :
101
107
if is_cjk (char ):
@@ -253,6 +259,7 @@ def main():
253
259
print_only = False
254
260
help_me = False
255
261
invalid_cmd = None
262
+ line_numbers = False
256
263
257
264
expected_arg = ("A SeleniumBase Python file" )
258
265
command_args = sys .argv [2 :]
@@ -284,6 +291,8 @@ def main():
284
291
copy = True
285
292
elif option == "-p" or option == "--print" :
286
293
print_only = True
294
+ elif option == "-n" :
295
+ line_numbers = True
287
296
elif option == "--en" or option == "--english" :
288
297
new_lang = "English"
289
298
elif option == "--zh" or option == "--chinese" :
@@ -444,6 +453,7 @@ def main():
444
453
raise Exception ("\n \n `%s` is not a valid SeleniumBase test file!\n "
445
454
"\n Expecting: [%s]\n "
446
455
% (seleniumbase_file , expected_arg ))
456
+ all_code = all_code .replace ("\t " , " " )
447
457
code_lines = all_code .split ('\n ' )
448
458
449
459
seleniumbase_lines , changed , d_l = process_test_file (code_lines , new_lang )
@@ -482,14 +492,16 @@ def main():
482
492
python_code = "\n " .join (seleniumbase_lines )
483
493
code_width = 1
484
494
485
- w = 4 # line number whitespace
486
- num_lines = len (seleniumbase_lines )
487
- if num_lines >= 10 :
488
- w = 5
489
- if num_lines >= 100 :
490
- w = 6
491
- if num_lines >= 1000 :
492
- w = 7
495
+ w = 0 # line number whitespace
496
+ if line_numbers :
497
+ w = 4
498
+ num_lines = len (code_lines )
499
+ if num_lines >= 10 :
500
+ w = 5
501
+ if num_lines >= 100 :
502
+ w = 6
503
+ if num_lines >= 1000 :
504
+ w = 7
493
505
494
506
new_sb_lines = []
495
507
for line in seleniumbase_lines :
@@ -626,7 +638,8 @@ def main():
626
638
627
639
magic_syntax = Syntax (
628
640
python_code , "python" , theme = "monokai" ,
629
- line_numbers = True , code_width = used_width , word_wrap = False )
641
+ line_numbers = line_numbers , code_width = used_width ,
642
+ word_wrap = False )
630
643
magic_console = Console ()
631
644
print ("" )
632
645
print (save_line )
0 commit comments