def get_by_name(name, assert_driver=None): """Return the entity with the given name. parameters: name - string; the name of the entity assert_driver - class; driver class you want to assert this object as """ name = u'%s' % name try: entity = Entity.query().filter_by(name=name).one() retval = Driver(entity) if assert_driver: if not isinstance(retval, assert_driver): raise TypeError("The object %s is not an instance of %s" % (name, assert_driver)) return retval except NoResultFound: raise LookupError(name + " does not exist.") except InvalidRequestError: raise
def get_entities(names=(), clusto_types=(), clusto_drivers=(), attrs=()): """Get entities matching the given criteria parameters: names - list of strings; names to match clustotypes - list of strings or Drivers; clustotypes to match clustodrivers - list of strings or Drivers; clustodrivers to get attrs - list of dicts with the following valid keys: key, number, subkey, value ; attribute parameters """ query = Entity.query() if names: names = [u'%s' % _ for _ in names] query = query.filter(Entity.name.in_(names)) if clusto_types: ctl = [get_type_name(n) for n in clusto_types] query = query.filter(Entity.type.in_(ctl)) if clusto_drivers: cdl = [get_driver_name(n) for n in clusto_drivers] query = query.filter(Entity.driver.in_(cdl)) if attrs: for k, v in attrs[0].items(): if not isinstance(v, basestring): continue attrs[0][k] = u'%s' % v query = query.filter(Attribute.entity_id == Entity.entity_id) query = query.filter( or_(*[Attribute.queryarg(**args) for args in attrs])) return [Driver(entity) for entity in query.all()]
def _set_pgi_image(self, image): """ Setter method for the pgi_image property Automatically keeps track of the previous associated PGI image in self.previous_pgi_image. """ try: clusto.begin_transaction() Driver.__setattr__(self, "previous_pgi_image", self.pgi_image) Driver.__setattr__(self, "pgi_image", image) clusto.commit() except: clusto.rollback_transaction() raise
def get_by_name(name): name = u'%s' % name try: entity = Entity.query().filter_by(name=name).one() retval = Driver(entity) return retval except InvalidRequestError: raise LookupError(name + " does not exist.")
def _set_pgi_image(self, image): """ Setter method for the pgi_image property Automatically keeps track of the previous associated PGI image in self.previous_pgi_image. """ if not isinstance(image, PGIImage): raise TypeError("Only PGIImage entities may be assigned to the pgi_image attribute.") try: clusto.begin_transaction() Driver.__setattr__(self, "previous_pgi_image", self.pgi_image) Driver.__setattr__(self, "pgi_image", image) clusto.commit() except: clusto.rollback_transaction() raise
def _set_pgi_image(self, image): """ Setter method for the pgi_image property Automatically keeps track of the previous associated PGI image in self.previous_pgi_image. """ if not isinstance(image, PGIImage): raise TypeError( "Only PGIImage entities may be assigned to the pgi_image attribute." ) try: clusto.begin_transaction() Driver.__setattr__(self, "previous_pgi_image", self.pgi_image) Driver.__setattr__(self, "pgi_image", image) clusto.commit() except: clusto.rollback_transaction() raise
def get_by_names(names): """Return a list of entities matching the given list of names. This will return the entities in the same order as the passed argument, placing None in the slot with names that don't exist. parameters: name - list of strings; names of the entities """ unicode_names = [unicode(name) for name in names] entities = Entity.query().filter(Entity.name.in_(unicode_names)).all() retvals = [None for x in xrange(len(names))] for entity in entities: try: retvals[names.index(entity.name)] = Driver(entity) except: pass return retvals
def _get_pgi_image(self): """ Getter method for the pgi_image property """ return Driver.__getattr__(self, "pgi_image")