Skip to contentSkip to conversation

fencing: add function is_executale

PATCH New Ondrej Mular 1 participant 1 message Dec 30, 2013 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 2/4 fencing: add function is_executale

In reply to a message not in the archive

New function is_executable added to fencing library. Function checks if path is reachable and executable. Used for example in fence_amt to check path to amttool.

---
 fence/agents/lib/fencing.py.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fence/agents/lib/fencing.py.py +8 -1
index ab14cb7..f4150ff 100644
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import sys, getopt, time, os, uuid, pycurl
+import sys, getopt, time, os, uuid, pycurl, stat
 import pexpect, re, atexit, syslog
 import __main__
 
@@ -1065,3 +1065,10 @@ def fence_login(options, re_login_string = "(login\s*: )|(Login Name:  )|(userna
 	except pexpect.TIMEOUT:
 		fail(EC_LOGIN_DENIED)
 	return conn
+
+def is_executable(path):
+	if os.path.exists(path):
+		stats = os.stat(path)
+		if stat.S_ISREG(stats.st_mode) and os.access(path, os.X_OK):
+			return True
+	return False
Signature · 1 line
1.8.3.1