mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-08 03:01:24 +00:00
25 lines
643 B
Python
25 lines
643 B
Python
import os
|
|
from typing import Optional
|
|
|
|
|
|
class Command:
|
|
def __init__(self, cmd: str) -> None:
|
|
self.command = cmd
|
|
|
|
@staticmethod
|
|
def executable(cmd: str) -> bool:
|
|
return os.path.isfile(cmd) and os.access(cmd, os.X_OK)
|
|
|
|
def locate(self) -> Optional[str]:
|
|
path, _ = os.path.split(self.command)
|
|
if path and self.executable(self.command):
|
|
return self.command
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
path = path.strip('"')
|
|
exe = os.path.join(path, self.command)
|
|
if self.executable(exe):
|
|
return exe
|
|
|
|
return None
|