import os, sys, stat from time import sleep, strftime from tiny import hide_env, say from signal import SIGKILL mode_rw = 384 # u+rw mode_w = 128 # u+w #+ # NAME: # skyd_claim # PURPOSE: # Reads the specified file 'filepath' and adds its content to the # returned status dictionary. # If claim=True then the file is 'claimed' by enabling read protection # This makes the file unavailable until read protection is switched off # CALLING SEQUENCE: # status = skyd_claim(claim,status,filepath) # INPUTS: # claim bool # status dictionary status['number'] should be 0 # filepath string name of configuration file or orbit catalogue # OUTPUTS: # status dictionary on success: # status['number'] and status['message'] are not modified # (should be 0 and blank string, respectively) # status['contents'] is the file contents # as a string array # status['chmod'] is the rwx-mode of filepath # (claim=TRUE only) # on failure # status['number' ] is set to 1 # status['message'] contains error message # status['contents'] and status['chmod'] will not be present. # CALLS: # skyd_status # SEE ALSO: # skyd_release # PROCEDURE: # Used to control updates to the daemon configuration file and to the # catalogue of orbits on which the daemon operates. # # claim=TRUE: # A while loop runs for 5 seconds until is is readable. # On succes the file is read, read protection is switched on. This 'claims' the # conf file until it is 'released' by skyd_release switching read # protection off again. Failure means either that the file was not readable # (presumably because a previous call already claimed it, and the read # protection is still on) or because there was a read error. # claim=FALSE: # One attempt is made to read the file. # Failure means that a read error occurred. # MODIFICATION HISTORY: # DEC-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) #- def skyd_claim(claim,status,filepath): csay = 'skyd_claim' hidepath = hide_env(filepath) if not os.path.isfile(filepath): return skyd_status(status,1,hidepath+' does not exist') # If there is no read access (in use by another skyd_orbit run) then # wait try for 24x5 seconds (2 minutes) for read access to appear count = 0 count_max = 30 naptime = 5 while count < count_max: try: contents = open(filepath,'r').read() except IOError, (errno, strerror): count += 1 say(csay,'W','