Exemple #1
0
    def get(self, ename):
        """Get an element data from a locked element.

        Arguments:
            ename - name of an element

        Return:
            dictionary representing an element

        Raise:
            QueueError - schema is unknown; unexpected data type in
                         the schema specification; missing mandatory
                         file of the element

            OSError    - problems opening/closing file
            IOError    - file read error
        """
        if not self.type:
            raise QueueError("unknown schema")
        _check_element(ename)
        if not self._is_locked(ename):
            raise QueueError("cannot get %s: not locked" % ename)
        data = {}
        for dname in self.type.keys():
            path = '%s/%s/%s' % (self.path, ename, dname)
            try:
                os.lstat(path)
            except Exception:
                error = sys.exc_info()[1]
                if error.errno != errno.ENOENT:
                    raise OSError("cannot lstat(%s): %s" % (path, error))
                if dname in self.mandatory:
                    raise QueueError("missing data file: %s" % path)
                else:
                    continue
            if self.type[dname] == 'binary':
                data[dname] = _file_read(path, 0)
            elif self.type[dname] == 'string':
                data[dname] = _file_read(path, 1)
            elif self.type[dname] == 'table':
                data[dname] = _string2hash(_file_read(path, 1))
            else:
                raise QueueError("unexpected data type: %s" % self.type[dname])
        return data
Exemple #2
0
    def get(self, ename):
        """Get an element data from a locked element.

        Arguments:
            ename - name of an element

        Return:
            dictionary representing an element

        Raise:
            QueueError - schema is unknown; unexpected data type in
                         the schema specification; missing mandatory
                         file of the element

            OSError    - problems opening/closing file
            IOError    - file read error
        """
        if not self.type:
            raise QueueError("unknown schema")
        _check_element(ename)
        if not self._is_locked(ename):
            raise QueueError("cannot get %s: not locked" % ename)
        data = {}
        for dname in self.type.keys():
            path = "%s/%s/%s" % (self.path, ename, dname)
            try:
                os.lstat(path)
            except Exception:
                error = sys.exc_info()[1]
                if error.errno != errno.ENOENT:
                    raise OSError("cannot lstat(%s): %s" % (path, error))
                if dname in self.mandatory:
                    raise QueueError("missing data file: %s" % path)
                else:
                    continue
            if self.type[dname] == "binary":
                data[dname] = _file_read(path, 0)
            elif self.type[dname] == "string":
                data[dname] = _file_read(path, 1)
            elif self.type[dname] == "table":
                data[dname] = _string2hash(_file_read(path, 1))
            else:
                raise QueueError("unexpected data type: %s" % self.type[dname])
        return data
Exemple #3
0
 def get(self, name):
     """Get locked element.
     """
     return _file_read('%s/%s%s' % (self.path, name, LOCKED_SUFFIX), False)