Esempio n. 1
0
 def acquire(self):
     '''Acquire a lock, returning self if successful, False otherwise'''
     if self.islocked():
         if self.debug:
             lock = self._readlock()
             log.critical('Previous lock detected: %s' % self.pddr(lock))
         return False
     try:
         fh = open(self.path, 'w')
         fh.write(self.addr())
         fh.close()
         if self.debug:
             log.debug('Acquired lock: %s' % self.fddr())
     except:
         if os.path.isfile(self.path):
             try:
                 os.unlink(self.path)
             except:
                 pass
         raise (self.FileLockAcquisitionError,
                'Error acquiring lock: %s' % self.fddr())
     return self
Esempio n. 2
0
for i in range(len(sys.argv)):
    if (sys.argv[i] == '-a') or (sys.argv[i] == '--action'):
        action = sys.argv[i+1]

if action == None:
    actionUsage()
    sys.exit()

# Make sure actions are recognised
found = 0
for va in validActions:
    if (action == va) or ((action) and (action).startswith("_")): # this way we allow any custom _XXXX actions
        found=1
        break
if found != 1:
    if (action): log.critical("Unrecognized action '" + action + "'\n")
    actionUsage()
    sys.exit()

# Init Optparser
parser = OptionParser(version="%prog \n\n version: '"+ scriptGlobals.version + "'\n revision: '"+ scriptGlobals.revision + "'\n build date: '" + scriptGlobals.buildDate + "'")

# Init Action Specific Options (but don't add them to the parser yet)
envpropsOption = Option("-e", "--envprops",       dest="envprops",       help="Environment specific properties file (mandatory)",                                                 metavar="<FILENAME>")
moduleOption = Option("-f", "--module",         dest="module",         help="Deployable module filename or file URL (mandatory)",                                               metavar="<FILENAME>")
rollbackOption = Option("-r", "--rollback",       dest="rollback",       help="Rollback filename (mandatory)",                                                                    metavar="<FILENAME>")

# Add common options
if (action):
    # The pinnacle of all options :-) (determines what other options will be added to the parser)
    parser.add_option("-a", "--action",         dest="action",         help="Choose one of the following actions '" +", ".join(validActions) + "' (mandatory)",      metavar="<ACTION>")