Author: dmeyer
Date: Fri Jan 27 20:29:29 2006
New Revision: 7885

Added:
   trunk/WIP/webserver/
   trunk/WIP/webserver/bin/
   trunk/WIP/webserver/bin/freevo-webserver2   (contents, props changed)
   trunk/WIP/webserver/setup.py
   trunk/WIP/webserver/src/
   trunk/WIP/webserver/src/__init__.py
   trunk/WIP/webserver/src/browse/
   trunk/WIP/webserver/src/browse/__init__.py
   trunk/WIP/webserver/src/browse/listing.kid
   trunk/WIP/webserver/src/config.py
   trunk/WIP/webserver/src/foo.tmpl
   trunk/WIP/webserver/src/root.py

Log:
some framework for a new webserver

Added: trunk/WIP/webserver/bin/freevo-webserver2
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/bin/freevo-webserver2   Fri Jan 27 20:29:29 2006
@@ -0,0 +1,19 @@
+#! /usr/bin/python
+
+import sys
+import os
+
+# insert freevo path information
+__site__ = '../lib/python%s.%s/site-packages' % sys.version_info[:2]
+__site__ = os.path.normpath(os.path.join(os.path.dirname(__file__), __site__))
+if not __site__ in sys.path:
+    sys.path.insert(0, __site__)
+
+import kaa.cherrypy
+
+from freevo.webserver2 import Root
+
+kaa.cherrypy.config.debug = True
+kaa.cherrypy.start(Root)
+
+kaa.notifier.loop()

Added: trunk/WIP/webserver/setup.py
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/setup.py        Fri Jan 27 20:29:29 2006
@@ -0,0 +1,94 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# setup.py - setup script for installing the freevo module
+# -----------------------------------------------------------------------------
+# $Id: setup.py 7806 2005-11-23 19:27:23Z dmeyer $
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file doc/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+import os
+import glob
+import types
+
+from distutils import core
+from distutils.command.build_py import build_py as _build_py
+
+from freevo.distribution import setup
+
+class build_py(_build_py):
+
+    template_compiler = {
+        'kid':  'kidc -s',
+        'tmpl': 'cheetah -c'
+        }
+
+    def build_template(self, module, module_file, package):
+        if type(package) is types.StringType:
+            package = package.split('.')
+        elif type(package) not in (types.ListType, types.TupleType):
+            raise TypeError, \
+                  "'package' must be a string (dot-separated), list, or tuple"
+        ttype = os.path.splitext(module_file)[1][1:]
+        outfile = self.get_module_outfile(self.build_lib, package, module)
+        tmpfile = outfile[:-2] + ttype
+        self.copy_file(module_file, tmpfile, preserve_mode=0)
+        os.system('%s %s' % (self.template_compiler[ttype], tmpfile))
+        os.unlink(tmpfile)
+        if os.path.isfile(outfile + 'c'):
+            os.unlink(outfile + 'c')
+
+        
+    def build_packages (self):
+        _build_py.build_packages(self)
+        for package in self.packages:
+            package_dir = self.get_package_dir(package)
+            modules = self.find_package_modules_ext(package, package_dir, 
"*.kid") + \
+                      self.find_package_modules_ext(package, package_dir, 
"*.tmpl")
+            for (package_, module, module_file) in modules:
+                assert package == package_
+                self.build_template(module, module_file, package)
+
+    
+    def find_package_modules_ext(self, package, package_dir, ext):
+        modules = []
+        for f in glob.glob(os.path.join(package_dir, ext)):
+            abs_f = os.path.abspath(f)
+            module = os.path.splitext(os.path.basename(f))[0]
+            modules.append((package, module, f))
+        return modules
+
+        
+# now start the python magic
+setup (name         = 'freevo-webserver2',
+       module       = 'webserver2',
+       version      = '2.0',
+       description  = 'Freevo Webserver',
+       author       = 'Dirk Meyer, et al.',
+       author_email = '[email protected]',
+       url          = 'http://www.freevo.org',
+       license      = 'GPL',
+       cmdclass     = { 'build_py': build_py }
+       )

Added: trunk/WIP/webserver/src/__init__.py
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/__init__.py Fri Jan 27 20:29:29 2006
@@ -0,0 +1,29 @@
+import os
+
+from config import config
+from root import Root
+
+def _add_subdirs(node, dirname):
+    """
+    Internal function to add sudirs as nodes to an object.
+    """
+    # add special attribute config
+    node.config = config
+    for name in os.listdir(dirname):
+        filename = os.path.join(dirname, name)
+        if not os.path.isdir(filename):
+            continue
+        module = filename[len(os.path.dirname(__file__))+1:]
+        exec('from %s import Root' % module.replace('/', '.'))
+        # add special attribute basename
+        Root.basename = '/' + module
+        # create object
+        setattr(node, name, Root())
+        # find subdirs
+        _add_subdirs(getattr(node, name), filename)
+
+
+# add special attribute basename
+Root.basename = '/'
+# add all subdirs to Root
+_add_subdirs(Root, os.path.dirname(__file__))

Added: trunk/WIP/webserver/src/browse/__init__.py
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/browse/__init__.py  Fri Jan 27 20:29:29 2006
@@ -0,0 +1,28 @@
+import os
+import kaa.cherrypy
+
+# kid template!
+import listing
+
+# root for browse
+class Root:
+
+    # Hidden feature for all root nodes: There are two variables with
+    # additional information:
+
+    # self.basename is the basename of the class, here browse, so you
+    # know where you are. The second is self.config pointing to the global
+    # config object
+    
+    # notice: pass the _imported_module_ to this function here
+    @kaa.cherrypy.expose(template=listing)
+    def index(self):
+        print 'running on port %s' % self.config.port
+        print 'basename is %s' % self.basename
+        return dict(title = '/', items = os.listdir('/'))
+
+    # notice: pass the _imported_module_ to this function here
+    @kaa.cherrypy.expose(template=listing)
+    def default(self, *args):
+        dir = '/' + '/'.join(args)
+        return dict(title  = dir, items = os.listdir(dir))

Added: trunk/WIP/webserver/src/browse/listing.kid
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/browse/listing.kid  Fri Jan 27 20:29:29 2006
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";
+      xmlns:py="http://purl.org/kid/ns#";>
+<head>
+<title py:content="title">Title</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+</head>
+<body>
+
+<h1 py:content="title">There should be content</h1>
+
+<ol py:if="title">
+  <li py:for="item in items">
+       <span py:replace="item"></span>
+  </li>
+</ol>
+
+</body>
+</html>

Added: trunk/WIP/webserver/src/config.py
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/config.py   Fri Jan 27 20:29:29 2006
@@ -0,0 +1,2 @@
+# just use the normal cherrypy config for now
+from kaa.cherrypy.config import config

Added: trunk/WIP/webserver/src/foo.tmpl
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/foo.tmpl    Fri Jan 27 20:29:29 2006
@@ -0,0 +1,12 @@
+<html>
+  <head>
+    <title>Cheetah Test</title>
+  </head>
+  <body>
+    <ul>
+      #for $line in $lines
+      <li>$line</li>
+      #end for
+    </ul>
+  </body>
+</html>

Added: trunk/WIP/webserver/src/root.py
==============================================================================
--- (empty file)
+++ trunk/WIP/webserver/src/root.py     Fri Jan 27 20:29:29 2006
@@ -0,0 +1,20 @@
+# Define root functions here. No objects (subdirs). Use a real subdir
+# with a new Root dir instead
+
+import kaa.cherrypy
+
+# cheetah template!
+import foo
+
+class Root:
+
+    # add other functions here
+    
+    @kaa.cherrypy.expose()
+    def index(self):
+        return 'running on port %s' % self.config.port
+
+    # notice: pass the _imported_module_ to this function here
+    @kaa.cherrypy.expose(template=foo)
+    def test(self):
+        return dict(lines=['a', 'b'])


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to