Esempio n. 1
0
    def save(self, configuration_file=None):
        """
        Store the configuration into file.

        By default, it stores the data, in the same *path* fromw
        which it was loaded from.

        `configuration_file` argument is provided to help with testing.
        """
        if configuration_file:
            self._writeToFile(store_file=configuration_file)
            return

        if not self._configuration_path:
            raise AssertionError(
                'Trying to save a configuration that was not loaded from '
                ' a file from disk.')

        real_segments = local_filesystem.getSegmentsFromRealPath(
            self._configuration_path)
        tmp_segments = real_segments[:]
        tmp_segments[-1] = tmp_segments[-1] + u'.tmp'
        store_file = local_filesystem.openFileForWriting(
                tmp_segments, utf8=True)
        self._writeToFile(store_file=store_file)
        store_file.close()
        # We delete the file first to work around windows problems.
        local_filesystem.deleteFile(real_segments)
        local_filesystem.rename(tmp_segments, real_segments)
Esempio n. 2
0
 def _writePID(self):
     """
     Write process ID in pid file.
     """
     pid_path = os.path.abspath(self.options.pid)
     pid_segments = local_filesystem.getSegmentsFromRealPath(pid_path)
     try:
         pid_file = local_filesystem.openFileForWriting(pid_segments)
         pid_file.write('%d' % os.getpid())
         pid_file.close()
     except (OSError, IOError):
         raise CompatError(
             1008,
             _(u'Could not write PID file at %s.' % (pid_path)),
             )