Esempio n. 1
0
    def save(self):
        """ Save the current override-only configuration to the override config
    file

    :raises TypeError: if mode != MODE_OVERRIDE_ONLY
    """
        if self._mode != self.MODE_OVERRIDE_ONLY:
            raise TypeError(
                "Config=%s was not loaded in MODE_OVERRIDE_ONLY; mode=%s" %
                (self._configName, self._mode))

        configOverrideDir = self._getConfigOverrideDir()
        makeDirectoryFromAbsolutePath(configOverrideDir)

        overrideConfigPath = os.path.join(configOverrideDir, self._configName)

        # NOTE: we open with os.O_RDWR | os.O_CREAT so that we can acquire the
        # file lock before altering contents of the file
        with os.fdopen(
                os.open(overrideConfigPath, os.O_RDWR | os.O_CREAT, 0644),
                "w") as fileObj:
            with file_lock.ExclusiveFileLock(fileObj):
                self.write(fileObj)
                fileObj.flush()
                fileObj.truncate()
Esempio n. 2
0
 def testExclusiveLock(self):
     flock = file_lock.ExclusiveFileLock(self._tempFileID)
     self.assertEqual(type(flock), file_lock._FileLock)