[Repoze-checkins] r878 - in playground/paul/agility/osx: . mobilib

Paul Everitt paul at agendaless.com
Sat Mar 29 12:41:11 EDT 2008


Author: Paul Everitt <paul at agendaless.com>
Date: Sat Mar 29 12:41:11 2008
New Revision: 878

Log:
First cut at removing the previous runtime importing stuff

Modified:
   playground/paul/agility/osx/MobiProtocolHandler.py
   playground/paul/agility/osx/PyMofoPloAppDelegate.py
   playground/paul/agility/osx/mobilib/__init__.py
   playground/paul/agility/osx/mobilib/desktopserver.py

Modified: playground/paul/agility/osx/MobiProtocolHandler.py
==============================================================================
--- playground/paul/agility/osx/MobiProtocolHandler.py	(original)
+++ playground/paul/agility/osx/MobiProtocolHandler.py	Sat Mar 29 12:41:11 2008
@@ -39,9 +39,7 @@
 
         try:
 	    path = modpath.encode('utf-8')
-            print "\nBefore"
-	    data, mimetype = "<p>here</p>", "text/htl"#self.getResource(request, path)
-            print "\nAfter"
+	    data, mimetype = self.getResource(request, path)
         except Exception, e:
             client.URLProtocol_didFailWithError_(
                 self,

Modified: playground/paul/agility/osx/PyMofoPloAppDelegate.py
==============================================================================
--- playground/paul/agility/osx/PyMofoPloAppDelegate.py	(original)
+++ playground/paul/agility/osx/PyMofoPloAppDelegate.py	Sat Mar 29 12:41:11 2008
@@ -5,6 +5,7 @@
 from PyObjCTools import NibClassBuilder, AppHelper
 
 import MobiProtocolHandler
+from mobilib import desktopserver
 
 class MofoPloAppDelegate(NibClassBuilder.AutoBaseClass):
     
@@ -30,29 +31,8 @@
         # Inject the mobi:/// custom protocol
         mobihandler = MobiProtocolHandler.setup()
         
-        # Is ~/Application Support/Mobility setup?
-        ad = os.path.expanduser("~/Library/Application Support/Mobility")
-        if not os.path.exists(ad):
-            # First time install, copy stuff into the application area
-            os.mkdir(ad)
-
-        mobilibdir = os.path.join(ad, "mobilib")
-        # If the dst directory exists, wipe it so we can copy over it
-        if os.path.exists(mobilibdir):
-            shutil.rmtree(mobilibdir)
-            
-        src = os.path.join(os.getcwd(), "mobilib")
-        shutil.copytree(src, mobilibdir)
-        
-        # Most of the app goes into ~/Library to avoid freezing into the
-        # the executable, so import it
-
-        #sys.path.insert(0, mobilibdir)
-        sys.path.insert(0, "..")
-        import mobilib
-
         # Now setup the reactor
-        mobilib.setupServer(reactor, mobilibdir=mobilibdir)
+        desktopserver.setupServer(reactor)
         reactor.root.setGUI(gui)
         reactor.root.setStatus("Mobispace imported")
 

Modified: playground/paul/agility/osx/mobilib/__init__.py
==============================================================================
--- playground/paul/agility/osx/mobilib/__init__.py	(original)
+++ playground/paul/agility/osx/mobilib/__init__.py	Sat Mar 29 12:41:11 2008
@@ -1,70 +1 @@
-
-import config, publisher
-
-
-from twisted.web2 import server, wsgi
-from twisted.web2.channel import http
-from twisted.internet import reactor
-
-### A demo WSGI application.
-def simple_wsgi_app(environ, start_response):
-    status = '200 OK'
-    response_headers = [('Content-type','text/html; charset=ISO-8859-1')]
-    start_response(status, response_headers)
-    data = environ['wsgi.input'].read()
-    environ['wsgi.errors'].write("This is an example wsgi error message\n")
-    s = '<h2>YAH</h2><pre>'
-    items=environ.items()
-    items.sort()
-    for k,v in items:
-        s += repr(k)+': '+repr(v)+'\n'
-    return [s, '<p><form method="POST" enctype="multipart/form-data"><input name="fo&quot;o" />\nData:<pre><input type="file" name="file"/><br/><input type="submit" /><br /></form>', data, '</pre>']
-
-def serve_with_twisted(app, **kw):
-    """Serve wsgi_app indefinitely"""
-    
-    factory = http.HTTPFactory(server.Site(wsgi.WSGIResource(app)))
-    reactor.listenTCP(8090, factory, interface="localhost")
-    reactor.run()
-
-def setupServer(thisreactor, mobilibdir="."):
-
-    # These are the important lines:
-    #   - Connect to the database
-    #   - Start the Twisted server
-    #dc = dbxmlcontainer.DbxmlContainer()
-    
-    root = publisher.RootResource()
-    #root.attachDbxmlContainer(dc)
-    #dc.addRoot(root)
-
-    class R:
-        def setStatus(self, msg):
-            import time
-            response = str(time.time()) + ": " + msg
-            if self.gui:
-                self.gui.statusMessage = response
-            else:
-                print response
-        
-        def setGUI(self, g):
-            self.gui = g
-    #root = R()
-
-    # Now start the server
-    root.PORT = config.PORT
-    
-    def hello_world(environ, start_response):  
-        start_response("200 OK", [('Content-type', 'text/plain')])  
-        return ["World"]
-      
-
-    app = hello_world
-    
-    site = server.Site(wsgi.WSGIResource(app))
-    factory = http.HTTPFactory(site)
-    thisreactor.listenTCP(root.PORT, factory, interface="localhost")
-    thisreactor.root = root
-    
-    print "Started Mobility on port", root.PORT
-    return
+#

Modified: playground/paul/agility/osx/mobilib/desktopserver.py
==============================================================================
--- playground/paul/agility/osx/mobilib/desktopserver.py	(original)
+++ playground/paul/agility/osx/mobilib/desktopserver.py	Sat Mar 29 12:41:11 2008
@@ -1,9 +1,32 @@
 """
-Convenience function to start server without GUI
+Setup server, plus onvenience function to serve without GUI
 """
 
+import config, publisher
+
+from twisted.web2 import server, wsgi
+from twisted.web2.channel import http
 from twisted.internet import reactor
-from mobilib import setupServer
+
+def setupServer(thisreactor):
+
+    root = publisher.RootResource()
+    root.PORT = config.PORT
+    
+    def hello_world(environ, start_response):  
+        start_response("200 OK", [('Content-type', 'text/plain')])  
+        return ["World"]      
+
+    app = hello_world
+    
+    site = server.Site(wsgi.WSGIResource(app))
+    factory = http.HTTPFactory(site)
+    thisreactor.listenTCP(root.PORT, factory, interface="localhost")
+    thisreactor.root = root
+    
+    print "Started Mobility on port", root.PORT
+    return
+
 
 if __name__ == "__main__":
     setupServer(reactor)


More information about the Repoze-checkins mailing list