Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 280

Show
Ignore:
Timestamp:
08/12/06 01:12:42
Author:
fumanchu
Message:

Logging changes:

  1. Arena.logflags now defaults to ERROR + IO.
  2. SM.db.log now takes a single "msg" arg (no logflags arg).
  3. Removed "rename table" log call.

Plus some docstring updates.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/arenas.py

    r279 r280  
    2727logflags.REPRESS = 1024 
    2828logflags.FORGET = 2048 
    29 logflags.SANDBOX = logflags.MEMORIZE | logflags.RECALL | logflags.VIEW | logflags.REPRESS | logflags.FORGET 
     29logflags.SANDBOX = (logflags.MEMORIZE | logflags.RECALL | logflags.VIEW | 
     30                    logflags.REPRESS | logflags.FORGET) 
    3031 
    3132 
    3233class Arena(object): 
    33     """Arena(). A namespace/workspace for a Dejavu application.""" 
     34    """A namespace/workspace for a Dejavu application.""" 
    3435     
    3536    def __init__(self): 
     
    3940        self.associations = Graph(directed=False) 
    4041        self.engine_functions = {} 
    41         self.logflags = 1 
     42        self.logflags = logflags.ERROR + logflags.IO 
    4243     
    4344    def log(self, message, flag): 
     
    106107     
    107108    def register(self, cls): 
    108         """register(cls) -> Assert that Units of class 'cls' will be handled.""" 
     109        """Assert that Units of class 'cls' will be handled.""" 
    109110        # We must allow modules to register classes before any stores have 
    110111        # been added, but not overwrite a store which has already been found. 
     
    161162     
    162163    def create_storage(self, cls): 
    163         """create_storage(cls). Create storage space for cls.""" 
     164        """Create storage space for cls.""" 
    164165        self.storage(cls).create_storage(cls) 
    165166     
     
    180181     
    181182    def migrate_class(self, cls, new_store): 
    182         """migrate_class(cls, new_store). Copy all units of cls to new_store.""" 
     183        """Copy all units of cls to new_store.""" 
    183184        new_store.create_storage(cls) 
    184185        for unit in self.new_sandbox().xrecall(cls): 
     
    187188     
    188189    def migrate(self, new_store, old_store=None, copy_only=False): 
    189         """migrate(new_store, old_store=None). Copy all units (of old_store) to new_store.""" 
     190        """Copy all units (of old_store) to new_store.""" 
    190191        for cls in self._registered_classes: 
    191192            store = self.storage(cls) 
     
    204205 
    205206class Sandbox(object): 
    206     """Sandbox(arena). Data sandbox for Dejavu arenas. 
     207    """Data sandbox for Dejavu arenas. 
    207208     
    208209    Each consumer (that is, each UI process) maintains a Sandbox for 
     
    248249     
    249250    def memorize(self, unit): 
    250         """memorize(unit). Persist unit in storage.""" 
     251        """Persist unit in storage.""" 
    251252        cls = unit.__class__ 
    252253        unit.sandbox = self 
     
    374375     
    375376    def xmulti(self, classes, expr=None, **kwargs): 
    376         """xmulti(classes, expr) -> [[unit, ...], [unit, ...], ...] 
    377         Recall units of each cls if they together match the expr. 
     377        """Recall units of each cls if they together match the expr. 
    378378         
    379379        Each yielded value will be a list of Units, in the same order as 
     
    521521     
    522522    def count(self, cls, expr): 
    523         """count(cls, expr) -> Number of Units of class 'cls'.""" 
     523        """Number of Units of class 'cls'.""" 
    524524        return len(self.distinct(cls, cls.identifiers, expr)) 
    525525     
     
    529529     
    530530    def _cache(self, cls): 
    531         """cache(cls). Return the cache for the specified class. 
     531        """Return the cache for the specified class. 
    532532         
    533533        This base class creates a new cache for each cls per request. 
     
    538538     
    539539    def purge(self, cls): 
    540         """purge(cls). Drop all cached Units of class 'cls'. Do not save.""" 
     540        """Drop all cached Units of class 'cls'. Do not save.""" 
    541541        del self._caches[cls] 
    542542     
    543543    def repress(self, unit): 
    544         """repress(unit). Remove unit from cache (but don't destroy).""" 
     544        """Remove unit from cache (but don't destroy).""" 
    545545        cls = unit.__class__ 
    546546        id = unit.identity() 
     
    556556     
    557557    def flush_all(self): 
    558         """flush_all(). Repress all units.""" 
     558        """Repress all units.""" 
    559559         
    560560        for cls in self._caches.keys(): 
  • trunk/storage/db.py

    r279 r280  
    114114        name = allOptions.pop('name') 
    115115        self.db = self.databaseclass(name, **allOptions) 
    116         self.db.log = lambda *a, **kw: self.arena.log(*a, **kw
     116        self.db.log = lambda msg: self.arena.log(msg, dejavu.logflags.SQL
    117117         
    118118        adapter = get_option('Type Adapter') 
     
    516516     
    517517    def rename_storage(self, oldname, newname): 
    518         self.arena.log("rename table %s to %s" % (oldname, newname), logflags.SQL) 
    519518        self.db.rename(oldname, newname) 
    520519     
  • trunk/storage/geniusql.py

    r279 r280  
    7272 
    7373import dejavu 
    74 from dejavu import codewalk, errors, logflags 
     74from dejavu import codewalk, errors 
    7575 
    7676 
     
    13851385        if isinstance(query, unicode): 
    13861386            query = query.encode(self.adaptertosql.encoding) 
    1387         self.log(query, logflags.SQL
     1387        self.log(query
    13881388        return conn.query(query) 
    13891389     
  • trunk/storage/storeado.py

    r279 r280  
    506506        if isinstance(query, unicode): 
    507507            query = query.encode(self.adaptertosql.encoding) 
    508         self.log(query, dejavu.logflags.SQL
     508        self.log(query
    509509        try: 
    510510            conn.Execute(query) 
     
    523523                res = conn.OpenSchema(query) 
    524524            else: 
    525                 self.log(query, dejavu.logflags.SQL
     525                self.log(query
    526526                res = win32com.client.Dispatch(r'ADODB.Recordset') 
    527527                if hasattr(conn, "conn"): 
  • trunk/storage/storefirebird.py

    r279 r280  
    7575            if isinstance(query, unicode): 
    7676                query = query.encode(self.toAdapter.encoding) 
    77             self.arena.log(query, dejavu.logflags.SQL
     77            self.log(query
    7878            cur = conn.cursor() 
    7979            cur.execute(query) 
     
    9999            if isinstance(query, unicode): 
    100100                query = query.encode(self.toAdapter.encoding) 
    101             self.arena.log(query, dejavu.logflags.SQL
     101            self.log(query
    102102            cur = conn.cursor() 
    103103            cur.execute(query) 
  • trunk/storage/storemysql.py

    r279 r280  
    1818 
    1919import dejavu 
    20 from dejavu import storage, logic, logflags 
     20from dejavu import storage, logic 
    2121from dejavu.storage import db 
    2222 
     
    405405        if isinstance(query, unicode): 
    406406            query = query.encode(self.adaptertosql.encoding) 
    407         self.log(query, logflags.SQL
     407        self.log(query
    408408        try: 
    409409            return conn.query(query) 
  • trunk/storage/storepypgsql.py

    r279 r280  
    393393    def create_database(self): 
    394394        c = self._template_conn() 
    395         self.execute("CREATE DATABASE %s WITH ENCODING '%s'" 
    396                      % (self.qname, self.encoding), c) 
     395        encoding = self.encoding 
     396        if encoding: 
     397            encoding = " WITH ENCODING '%s'" % encoding 
     398        self.execute("CREATE DATABASE %s%s" % (self.qname, encoding), c) 
    397399        c.finish() 
    398400        self.clear() 
  • trunk/storage/storesqlite.py

    r279 r280  
    515515            if isinstance(query, unicode): 
    516516                query = query.encode(self.adaptertosql.encoding) 
    517             self.log(query, dejavu.logflags.SQL
     517            self.log(query
    518518            while True: 
    519519                try: 
  • trunk/test/zoo_fixture.py

    r279 r280  
    10491049    arena = dejavu.Arena() 
    10501050    arena.log = _djvlog 
    1051     arena.logflags = dejavu.logflags.SQL + dejavu.logflags.IO + dejavu.logflags.RECALL 
     1051    arena.logflags = (dejavu.logflags.ERROR + dejavu.logflags.SQL + 
     1052                      dejavu.logflags.IO + dejavu.logflags.RECALL) 
    10521053 
    10531054