Skip to content

Commit 410aa57

Browse files
committed
[KiBot Check][Added] Multiple tool detection
Now reports if the same tool is more than once in the PATH
1 parent 57e5a32 commit 410aa57

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/kibot-check

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ BOGUS_PDF = """%PDF-1.0
15381538
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>
15391539
endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj
15401540
trailer<</Root 1 0 R>>"""
1541+
checked_multiple = set()
15411542

15421543

15431544
def check_tool_binary_python(name):
@@ -1568,13 +1569,32 @@ def look_for_command(command):
15681569
return cmd_full
15691570

15701571

1572+
def check_multiple_installs(command):
1573+
if command in checked_multiple:
1574+
return
1575+
checked_multiple.add(command)
1576+
path_components = os.environ.get('PATH', '').split(os.pathsep)
1577+
found = set([os.path.realpath(os.path.join(p, command)) for p in path_components if os.path.isfile(os.path.join(p, command))])
1578+
other = check_tool_binary_python(command)
1579+
if other:
1580+
found.add(other)
1581+
other = check_tool_binary_local(command)
1582+
if other:
1583+
found.add(other)
1584+
if len(found) > 1:
1585+
print(do_color(f'Multiple installations for `{command}` please keep only one', 1))
1586+
for f in found:
1587+
print(do_color('- '+f, 1))
1588+
1589+
15711590
def run_command(cmd, only_first_line=False, pre_ver_text=None, no_err_2=False, no_err_msg=False):
15721591
global last_ok
15731592
global last_cmd
15741593
cmd_full = look_for_command(cmd[0])
15751594
if not cmd_full:
15761595
last_ok = False
15771596
return NOT_AVAIL
1597+
check_multiple_installs(cmd[0])
15781598
cmd[0] = cmd_full
15791599
last_cmd = None
15801600
try:

src/kibot-check.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ BOGUS_PDF = """%PDF-1.0
4545
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>
4646
endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj
4747
trailer<</Root 1 0 R>>"""
48+
checked_multiple = set()
4849

4950

5051
def check_tool_binary_python(name):
@@ -75,13 +76,32 @@ def look_for_command(command):
7576
return cmd_full
7677

7778

79+
def check_multiple_installs(command):
80+
if command in checked_multiple:
81+
return
82+
checked_multiple.add(command)
83+
path_components = os.environ.get('PATH', '').split(os.pathsep)
84+
found = set([os.path.realpath(os.path.join(p, command)) for p in path_components if os.path.isfile(os.path.join(p, command))])
85+
other = check_tool_binary_python(command)
86+
if other:
87+
found.add(other)
88+
other = check_tool_binary_local(command)
89+
if other:
90+
found.add(other)
91+
if len(found) > 1:
92+
print(do_color(f'Multiple installations for `{command}` please keep only one', 1))
93+
for f in found:
94+
print(do_color('- '+f, 1))
95+
96+
7897
def run_command(cmd, only_first_line=False, pre_ver_text=None, no_err_2=False, no_err_msg=False):
7998
global last_ok
8099
global last_cmd
81100
cmd_full = look_for_command(cmd[0])
82101
if not cmd_full:
83102
last_ok = False
84103
return NOT_AVAIL
104+
check_multiple_installs(cmd[0])
85105
cmd[0] = cmd_full
86106
last_cmd = None
87107
try:

0 commit comments

Comments
 (0)