Author: pquerna
Date: Mon Aug 24 01:39:14 2009
New Revision: 807037

URL: http://svn.apache.org/viewvc?rev=807037&view=rev
Log:
Load sqlalchemy, make a basic model for the tables I will need.

Modified:
    labs/mboxed/trunk/mboxed/mboxed/config/deployment.ini_tmpl
    labs/mboxed/trunk/mboxed/mboxed/config/environment.py
    labs/mboxed/trunk/mboxed/mboxed/lib/base.py
    labs/mboxed/trunk/mboxed/mboxed/model/__init__.py

Modified: labs/mboxed/trunk/mboxed/mboxed/config/deployment.ini_tmpl
URL: 
http://svn.apache.org/viewvc/labs/mboxed/trunk/mboxed/mboxed/config/deployment.ini_tmpl?rev=807037&r1=807036&r2=807037&view=diff
==============================================================================
--- labs/mboxed/trunk/mboxed/mboxed/config/deployment.ini_tmpl (original)
+++ labs/mboxed/trunk/mboxed/mboxed/config/deployment.ini_tmpl Mon Aug 24 
01:39:14 2009
@@ -8,6 +8,7 @@
 email_to = [email protected]
 smtp_server = localhost
 error_email_from = pa...@localhost
+mbox_path = /opt/mboxed
 
 [server:main]
 use = egg:Paste#http

Modified: labs/mboxed/trunk/mboxed/mboxed/config/environment.py
URL: 
http://svn.apache.org/viewvc/labs/mboxed/trunk/mboxed/mboxed/config/environment.py?rev=807037&r1=807036&r2=807037&view=diff
==============================================================================
--- labs/mboxed/trunk/mboxed/mboxed/config/environment.py (original)
+++ labs/mboxed/trunk/mboxed/mboxed/config/environment.py Mon Aug 24 01:39:14 
2009
@@ -5,9 +5,12 @@
 from pylons import config
 from pylons.error import handle_mako_error
 
+from sqlalchemy import engine_from_config
+
 import mboxed.lib.app_globals as app_globals
 import mboxed.lib.helpers
 from mboxed.config.routing import make_map
+from mboxed import model
 
 def load_environment(global_conf, app_conf):
     """Configure the Pylons environment via the ``pylons.config``
@@ -37,3 +40,6 @@
 
     # CONFIGURATION OPTIONS HERE (note: all config options will override
     # any Pylons config options)
+
+    engine = engine_from_config(config, 'sqlalchemy.')
+    model.init_model(engine)

Modified: labs/mboxed/trunk/mboxed/mboxed/lib/base.py
URL: 
http://svn.apache.org/viewvc/labs/mboxed/trunk/mboxed/mboxed/lib/base.py?rev=807037&r1=807036&r2=807037&view=diff
==============================================================================
--- labs/mboxed/trunk/mboxed/mboxed/lib/base.py (original)
+++ labs/mboxed/trunk/mboxed/mboxed/lib/base.py Mon Aug 24 01:39:14 2009
@@ -4,6 +4,7 @@
 """
 from pylons.controllers import WSGIController
 from pylons.templating import render_mako as render
+from mboxed import model
 
 class BaseController(WSGIController):
 
@@ -12,4 +13,7 @@
         # WSGIController.__call__ dispatches to the Controller method
         # the request is routed to. This routing information is
         # available in environ['pylons.routes_dict']
-        return WSGIController.__call__(self, environ, start_response)
+        try:
+            return WSGIController.__call__(self, environ, start_response)
+        finally:
+            model.Session.remove()

Modified: labs/mboxed/trunk/mboxed/mboxed/model/__init__.py
URL: 
http://svn.apache.org/viewvc/labs/mboxed/trunk/mboxed/mboxed/model/__init__.py?rev=807037&r1=807036&r2=807037&view=diff
==============================================================================
--- labs/mboxed/trunk/mboxed/mboxed/model/__init__.py (original)
+++ labs/mboxed/trunk/mboxed/mboxed/model/__init__.py Mon Aug 24 01:39:14 2009
@@ -0,0 +1,53 @@
+import sqlalchemy as sa
+from sqlalchemy import orm
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy import MetaData
+
+__all__ = ['engine', 'metadata', 'Session', 'init_model',
+            'Lists', 'MboxFile', 'MboxMessage']
+
+# SQLAlchemy database engine.  Updated by model.init_model().
+engine = None
+
+# SQLAlchemy session manager.  Updated by model.init_model().
+Session = None
+
+# Global metadata. If you have multiple databases with overlapping table 
+# names, you'll need a metadata for each database.
+_Base = declarative_base()
+metadata = _Base.metadata
+
+def init_model(_engine):
+    """Call me before using any of the tables or classes in the model"""
+    global Session,engine
+    engine = _engine
+    sm = orm.sessionmaker(autoflush=True, autocommit=True, bind=engine)
+    Session = orm.scoped_session(sm)
+    Session.configure(bind=engine)
+
+class Lists(_Base):
+    __tablename__ = "lists"
+    id = sa.Column(sa.types.Integer, primary_key=True)
+    name = sa.Column(sa.types.Unicode(100), unique=True)
+    domain = sa.Column(sa.types.Unicode(50))
+    # Relative path to the root of the lists
+    path = sa.Column(sa.types.Unicode(255), unique=True, index=True)
+    mtime = sa.Column(sa.types.DateTime())
+
+class MboxFile(_Base):
+    __tablename__ = "files"
+    id = sa.Column(sa.types.Integer, primary_key=True)
+    name = sa.Column(sa.types.Unicode(100), index=True)
+    list = sa.Column(sa.ForeignKey("lists.id"), index=True)
+    mtime = sa.Column(sa.types.DateTime())
+
+class MboxMessage(_Base):
+    __tablename__ = "messages"
+    id = sa.Column(sa.types.Integer, primary_key=True)
+    file = sa.Column(sa.ForeignKey("files.id"), index=True)
+    msgid = sa.Column(sa.types.Unicode(256), index=True)
+    offset = sa.Column(sa.types.Integer)
+    length = sa.Column(sa.types.Integer)
+    
+
+    
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to