Beispiel #1
0
    def createLockfile(self):
        '''
        USAGE: etl.py --action=createLockfile --cfg=<config> --section=<section_pattern>
        It will read the options of each section matched <section_pattern> in conf/actions/createLockfile/<config>.cfg
        EXAMPLE: python2.7 etl.py --action=createLockfile --cfg=sample --section=sample
        '''
        sections = self.getSectionsForAction(CREATE_LOCKFILE_ACTION)
        lockedFiles = []
        for section in sections:
            logging.info("\nStart processing section: %s" % section)
            # Read parameters for moving files
            filename = self._readPatternMandatoryOption(section, FILENAME)

            # Create Lockfile
            lock = Lockfile(filename)
            if lock.exists():
                lockedFiles.append(filename+'.lock')
            else:
                try:
                    lock.create()
                except:
                    logging.error("Error happend when creating lock file '%s'!" % (filename+'.lock'))
                    raise
                logging.info("The lock file '%s.lock' was created successfully." % filename)
        if not lockedFiles:
            logging.info("Created all lock files successfully.")
            return RC_NO_ERROR
        for lockedFile in lockedFiles:
            logging.warn("The lock file: '%s' was already existed." % lockedFile)
        return RC_EXISTING_PROCESS_EXISTS