Changeset 1511
- Timestamp:
- Mar 4, 2014 10:27:24 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cssboy_deployment/src/startCSS.py
r1162 r1511 13 13 14 14 import os 15 import fcntl 15 16 16 17 def main(): … … 20 21 except KeyError: 21 22 print "CSS_WORKSPACES environment variable is undefined." 22 23 return 23 24 24 25 # Verify that the CSS workspace diretory exists … … 37 38 if not os.path.isfile(css_bin): 38 39 print "CSS_BIN=%s doesn't exist." % css_bin 39 return40 41 # Get the location of the fuser binary42 fuser_bin = which('fuser')43 if fuser_bin == None:44 print "'fuser' command not found"45 40 return 46 41 … … 68 63 lock_path = workspace + os.sep + '.metadata' + os.sep + '.lock' 69 64 70 cmd_str = "%s -s %s" % (fuser_bin, lock_path) 71 ret_val = os.system(cmd_str) 72 65 if os.path.isfile(lock_path): 66 # Lock file exists 67 68 lfd = open(lock_path, 'r+') 69 70 # Determine if lock file is locked by trying to lock it 71 try: 72 fcntl.flock(lfd, fcntl.LOCK_EX | fcntl.LOCK_NB) 73 except: 74 # The file is locked 75 ret_val = 0 76 else: 77 # The file is NOT locked. 78 fcntl.flock(lfd, fcntl.LOCK_UN) 79 ret_val = 1 80 81 lfd.close() 82 83 else: 84 # lock file doesn't exist, workspace should be available 85 ret_val = 1 86 73 87 #print " ", os.path.basename(workspace), ret_val 74 88 print " ", os.path.basename(workspace) … … 91 105 92 106 93 # http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python94 def which(program):95 import os96 def is_exe(fpath):97 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)98 99 fpath, fname = os.path.split(program)100 if fpath:101 if is_exe(program):102 return program103 else:104 for path in os.environ["PATH"].split(os.pathsep):105 exe_file = os.path.join(path, program)106 if is_exe(exe_file):107 return exe_file108 109 return None110 111 107 if __name__ == '__main__': 112 108 main()
Note: See TracChangeset
for help on using the changeset viewer.