Beispiel #1
0
    def close(self):
        """Emulate local method of same name"""

        if self.locking != LOCK_UN:
            self.unlock()
        self.__close_remote_file(self.path)

        # Again we need parent method to manipulate read-only attributes

        ServerFile.close(self)
Beispiel #2
0
    def __init__(
        self,
        path,
        mode='r',
        bufsize=-1,
    ):
        """Setup DistFile object"""

        # Make sure we don't run into trouble if server doesn't recognize
        # that /test//file/ is equivalent to /test/file

        path = _normpath(path)

        # Some of the file attributes inherited from file are
        # read-only (mode, closed, ...) so we must call parent
        # constructor to set them. However, we don't want to
        # create actual local file so we use a dummy.

        ServerFile.__init__(self, _devnull, mode, bufsize)

        self.providers = []

        # semi random session id for now - we should use cert access
        # instead!

        self.session_id = BASE_ID
        self.session_home = BASE_HOME
        self.session_type = None
        self.path = path
        self.bufsize = bufsize
        self.offset = 0
        self.locking = LOCK_UN

        (status, data) = self.__open_remote_file(path, mode)
        if status == 0:
            self.providers = data.split()
        else:

            # TODO: Dist FS always sets exclusive access on open for
            # now

            raise IOError('Distfile: init failed with error %s: %s' %
                          (status, data))
        if mode.startswith('w'):

            # Mimic standard python behaviour of truncating files
            # opened in write mode. Use "r+" to avoid truncating!

            self.__truncate_remote_file(self.providers, path, 0)