From 5dfa7e2d7e15c8821054de045c33a1c7e2f777b7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 Feb 2020 08:44:36 -0600 Subject: [PATCH] cephadm: remove distutils dependency Signed-off-by: Sage Weil --- src/cephadm/cephadm | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index a312c1b3dd9f6..36a35a7f40a8d 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -57,7 +57,6 @@ except ImportError: pass import uuid -from distutils.spawn import find_executable from functools import wraps from glob import glob from threading import Thread @@ -809,6 +808,42 @@ def move_files(src, dst, uid=None, gid=None): logger.debug('chown %s:%s \'%s\'' % (uid, gid, dst_file)) os.chown(dst_file, uid, gid) +## copied from distutils ## +def find_executable(executable, path=None): + """Tries to find 'executable' in the directories listed in 'path'. + A string listing directories separated by 'os.pathsep'; defaults to + os.environ['PATH']. Returns the complete filename or None if not found. + """ + _, ext = os.path.splitext(executable) + if (sys.platform == 'win32') and (ext != '.exe'): + executable = executable + '.exe' + + if os.path.isfile(executable): + return executable + + if path is None: + path = os.environ.get('PATH', None) + if path is None: + try: + path = os.confstr("CS_PATH") + except (AttributeError, ValueError): + # os.confstr() or CS_PATH is not available + path = os.defpath + # bpo-35755: Don't use os.defpath if the PATH environment variable is + # set to an empty string + + # PATH='' doesn't match, whereas PATH=':' looks in the current directory + if not path: + return None + + paths = path.split(os.pathsep) + for p in paths: + f = os.path.join(p, executable) + if os.path.isfile(f): + # the file exists, we have a shot at spawn working + return f + return None + def find_program(filename): # type: (str) -> str name = find_executable(filename) -- 2.39.5