File: PageMain.py

package info (click to toggle)
cherokee 0.7.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,808 kB
  • ctags: 6,577
  • sloc: ansic: 45,071; python: 9,628; sh: 9,468; makefile: 1,639; xml: 61; perl: 32
file content (96 lines) | stat: -rw-r--r-- 2,604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import time

from Page import *
from Table import *
from configured import *
from CherokeeManagement import *

SERVER_RUNNING = """
<div class="dialog-online">
 <form id="run-form" action="/stop" method="post">
  <h2>Server status</h2>
  <p>
   Server is running.
   <div style="float: right;">
    <a class="button" href="#" onclick="this.blur(); $('#run-form').submit(); return false;"><span>Stop</span></a>
   </div>
  </p>
 </form>
 <div class="clearfix"></div>
</div>
"""

SERVER_NOT_RUNNING = """
<div class="dialog-offline">
 <form id="run-form" action="/launch" method="post">
  <h2>Server status</h2>
  <p>
   Server is not running.
   <div style="float: right;">
    <a class="button" href="#" onclick="this.blur(); $('#run-form').submit(); return false;"><span>Launch</span></a>
   </div>
  </p>
 </form>
 <div class="clearfix"></div>
</div>
"""

class PageMain (PageMenu, FormHelper):
    def __init__ (self, cfg=None):
        PageMenu.__init__ (self, 'main', cfg)
        FormHelper.__init__ (self, 'main', cfg)

    def _op_render (self):
        self.AddMacroContent ('title', 'Welcome to Cherokee Admin')
        self.AddMacroContent ('content', self.Read('main.template'))

        manager = cherokee_management_get (self._cfg)
        if manager.is_alive():
            self.AddMacroContent ('status', SERVER_RUNNING)
        else:
            self.AddMacroContent ('status', SERVER_NOT_RUNNING)

        extra_info = self._render_extra_info()
        self.AddMacroContent ('extra_info', extra_info)

        return Page.Render(self)

    def _op_handler (self, uri, post):
        return '/'
    
    def _render_extra_info (self):
        txt = ""

        # Server
        table = Table(2)
        table += ("Server version", VERSION)
        table += ("Server prefix",  PREFIX)
        table += ("Server default path",  WWWROOT)

        manager = cherokee_management_get (self._cfg)
        if manager._pid:
            current_pid = str(manager._pid)
        else:
            current_pid = "Not running"

        table += ("Server PID",  current_pid)

        txt += '<h3>Server</h3>'
        txt += self.Indent(table)

        # Configuraion
        table = Table(2)

        file = self._cfg.file
        if file:
            info = os.stat(file)
            file_status = time.ctime(info.st_ctime)
            table += ("Configuration file", file)
            table += ("Configuration modified", file_status)
        else:
            table += ("Configuration file", 'Not Found')

        txt += '<h3>Configuration</h3>'
        txt += self.Indent(table)

        return txt