root/oss/opkee/opkee.py

Revision 12, 3.7 kB (checked in by sylvain, 3 years ago)

first import of opkee

Line 
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 __authors__ = ["Sylvain Hellegouarch (sh@defuze.org)"]
5 __version__ = "1.0"
6 __date__ = "2005/10/18"
7 __copyright__ = """
8 Copyright (c) 2005, Sylvain Hellegouarch
9 All rights reserved.
10 """
11 __license__ = """
12 Redistribution and use in source and binary forms, with or without modification,
13 are permitted provided that the following conditions are met:
14
15      * Redistributions of source code must retain the above copyright notice,
16        this list of conditions and the following disclaimer.
17      * Redistributions in binary form must reproduce the above copyright notice,
18        this list of conditions and the following disclaimer in the documentation
19        and/or other materials provided with the distribution.
20      * Neither the name of Sylvain Hellegouarch nor the names of his contributors
21        may be used to endorse or promote products derived from this software
22        without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 """
35
36 import sys
37 import os.path
38
39 sys.path.append('src')
40
41 import cherrypy
42 from cherrypy.lib import cptools
43
44 # Opkee imports
45 from archive import OpkeeArchive
46 from admin import OpkeeAdmin
47 from ui_helper import OpkeeUIHelper
48 from ctfilter import OpkeeTemplate, OpkeeTemplateFilter
49 import backend
50 import feed
51 import utility
52
53 # Will be called by CherryPy when starting up the server
54 def initialize():
55     backend.initialize()
56     feed.initialize_feeds()
57
58 # Will be called by CherryPy when stopping down the server
59 def shutdown():
60     backend.shutdown()
61
62 class Opkee:
63     _cp_filters = [ OpkeeTemplateFilter() ]
64
65     def __init__(self):
66         self.archives = OpkeeArchive()
67         self.admin = OpkeeAdmin()
68         self.uihelper = OpkeeUIHelper()
69    
70     def default(self):
71         # on the index page of the blog we'll show up to 10 entries
72         entries = backend.current().fetch_up_to(10, 'entries')
73         entries.sort() # make sure we sort them by creation date
74         entries.reverse() # we display them in reverse creation date order
75         return OpkeeTemplate('index.tpl', params={'entries': entries})
76     default.exposed = True
77
78     def feed(self, feed):
79         feed_path = os.path.join('media', 'feed', feed)
80         if 'atom' in feed:
81             contentType = 'application/atom+xml'
82         elif 'rss' in feed:
83             contentType = 'application/rss+xml'
84         if os.path.exists(feed_path):
85             return cptools.serveFile(feed_path, contentType=contentType)
86
87         return cherrypy.NotFound
88     feed.exposed = True
89
90 def main():
91     # Let's load the config settings
92     cherrypy.config.update(file=os.path.join('media','conf','opkee.conf'))
93    
94     # Ask CherryPy to run some functions when starting and stopping
95     cherrypy.server.on_start_server_list = [initialize]
96     cherrypy.server.on_stop_server_list = [shutdown]
97
98     # Let's build the CherryPy objects tree
99     cherrypy.tree.mount(Opkee(), '/')
100    
101     # Let's go!
102     cherrypy.server.start()
103
104 if __name__ == '__main__':
105     main()
Note: See TracBrowser for help on using the browser.