mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Replace os.access with stat calls for determining the executability of a given path.
This commit is contained in:
parent
734db4ffe9
commit
29ac1a8efc
3 changed files with 16 additions and 2 deletions
|
@ -76,7 +76,7 @@ class Inventory(object):
|
|||
all.add_host(Host(tokens[0], tokens[1]))
|
||||
else:
|
||||
all.add_host(Host(x))
|
||||
elif os.access(host_list, os.X_OK):
|
||||
elif utils.is_executable(host_list):
|
||||
self._is_script = True
|
||||
self.parser = InventoryScript(filename=host_list)
|
||||
self.groups = self.parser.groups.values()
|
||||
|
|
|
@ -49,6 +49,7 @@ import syslog
|
|||
import types
|
||||
import time
|
||||
import shutil
|
||||
import stat
|
||||
|
||||
try:
|
||||
from hashlib import md5 as _md5
|
||||
|
@ -247,7 +248,7 @@ class AnsibleModule(object):
|
|||
paths.append(p)
|
||||
for d in paths:
|
||||
path = os.path.join(d, arg)
|
||||
if os.path.exists(path) and os.access(path, os.X_OK):
|
||||
if os.path.exists(path) and self.is_executable(path):
|
||||
bin_path = path
|
||||
break
|
||||
if required and bin_path is None:
|
||||
|
@ -282,6 +283,12 @@ class AnsibleModule(object):
|
|||
print self.jsonify(kwargs)
|
||||
sys.exit(1)
|
||||
|
||||
def is_executable(path):
|
||||
'''is the given path executable?'''
|
||||
return (stat.S_IXUSR & os.stat(path)[stat.ST_MODE]
|
||||
or stat.S_IXGRP & os.stat(path)[stat.ST_MODE]
|
||||
or stat.S_IXOTH & os.stat(path)[stat.ST_MODE])
|
||||
|
||||
def md5(self, filename):
|
||||
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
||||
if not os.path.exists(filename):
|
||||
|
|
|
@ -32,6 +32,7 @@ import StringIO
|
|||
import imp
|
||||
import glob
|
||||
import subprocess
|
||||
import stat
|
||||
|
||||
VERBOSITY=0
|
||||
|
||||
|
@ -100,6 +101,12 @@ def check_conditional(conditional):
|
|||
return var.startswith("$")
|
||||
return eval(conditional)
|
||||
|
||||
def is_executable(path):
|
||||
'''is the given path executable?'''
|
||||
return (stat.S_IXUSR & os.stat(path)[stat.ST_MODE]
|
||||
or stat.S_IXGRP & os.stat(path)[stat.ST_MODE]
|
||||
or stat.S_IXOTH & os.stat(path)[stat.ST_MODE])
|
||||
|
||||
def prepare_writeable_dir(tree):
|
||||
''' make sure a directory exists and is writeable '''
|
||||
|
||||
|
|
Loading…
Reference in a new issue