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)
def _deletePID(self): pid_path = os.path.abspath(self.options.pid) pid_segments = local_filesystem.getSegmentsFromRealPath(pid_path) try: local_filesystem.deleteFile(pid_segments) except Exception: # We don't care if remove operation fail or success. # We are going to close the server anyway. # Just change the exit value to signal that something went # wrong. self.onStop(1)