''' Resolve the ObjectSpec to the object(s) specified using the specified session. Every ObjectSpec specifies a one or more Object Instances (Entity Class, Element instance, Attribute value ) . Resolve uses the session to return a Generator to iterate over these. ''' raise NotImplemented() @property def object_name(self): raise NotImplemented() def __str__(self): return self.object_name class_logger(ObjectSpec) class EntitySpec(ObjectSpec): ENTITY_NAME = '([A-Za-z]+)' @staticmethod def spec_types(): return (EntityQuery, EntityName) def __init__(self, entity_name): self.entity_name = entity_name #class EntityAll(EntitySpec): # REGEX = re.compile("^elements$" % EntitySpec.ENTITY_NAME, re.IGNORECASE)
if rel_prop.uselist: return "[ " + target_cls.__name__ + ", ... ]" else: return target_cls.__name__ class FormDisplayProcessor(DisplayProcessor): ''' Default DisplayProcessor using an ElementFormProcessor ''' def show(self, instance): from dino.db.element_form import ElementFormProcessor session = object_session(instance) processor = ElementFormProcessor.create(session, show_headers=True) return processor.to_form(instance) class_logger(FormDisplayProcessor) class RackDisplayProcessor(DisplayProcessor): def show(self, rack): from dino.db.schema import Rack assert isinstance(rack, Rack) rack_list = self.RackElementList(self, rack) rowlist = list( rack_list.row_list() ) rowlist.reverse() return [ "%02d %s" % (i, r) for i,r in rowlist ]
if instance.object_id in self.element_cache: del self.element_cache[instance.object_id] self.log.info("CACHE END DELETE: %s", instance.object_id) class ElementSessionExtension(sqlalchemy.orm.session.SessionExtension): def before_flush(self, session, flush_context, instances): from dino.db.element import Element for element in session.new: if isinstance(element, Element): if session.query(element.__class__).filter_by(instance_name=element.instance_name).count() > 0: raise ElementExistsError("Element already exists: %s" % element.element_name) class_logger(ElementSession) class ChangeDescription(list): def __init__(self, session): for inst in session.new: if session.is_changeset(inst): continue self.append(AddInstance(inst)) for inst in session.deleted: self.append(DeleteInstance(inst)) for inst in session.dirty: for attr in inst.mapper.class_manager.attributes: self._read_attr(inst, attr)
#if self.db is None: # raise connection = self.engine.connect() connection.execute("SET FOREIGN_KEY_CHECKS = 0") t = connection.begin() #tables_stmt = "SELECT table_name FROM information_schema.tables WHERE table_schema = '%s';" % self.db_config.db tables_stmt = "SHOW TABLES" for row in connection.execute(tables_stmt): self.log.fine("Drop Table: %s" % row[0]) connection.execute("DROP TABLE %s" % row[0]) t.commit() connection.execute("SET FOREIGN_KEY_CHECKS = 1") def dump_schema(self): import StringIO buf = StringIO.StringIO() engine = sqlalchemy.engine.create_engine('mysql://', strategy='mock', executor=lambda s: buf.write(s + ";\n")) for md in self.metadata_set: md.create_all(engine) return buf.getvalue() class_logger(DbConfig)
return self._map[key] def __setitem__(self, key, item): raise NotImplemented() def __delitem__(self, key): self.remove(self._map[key]) def keys(self): return self._map.keys() def values(self): return self._map.values() def items(self): return self._map.items() def get(self, key, default=None): return self._map.get(key, default) class_logger(IndexedList) class DerivedField(Field): """ Like elixir.Field, used to create a property of <name> on an elixir.Entity class. Unlike elixir.Field, the value is derived from a method specified by the derive_method argument. Usage: class Foo(elixir.Entity): <name> = DerivedField( <type>, derive_method=<method_name>, **kwargs) Like Field, this creates a sqlalchemy.orm.Property on the class called <name>. However, the original sqlalchemy.orm.Property is moved to "_<name>" to be accessed by the mapper extension. The field value is then stored in the