Not logged in
Check-in [e0e9548c97]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Pages now contain real content. Ripped out template code from string.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e0e9548c971bf0126edb8fe390da62ad964eee72
User & Date: petr 2010-11-06 15:31:51
Context
2010-11-07
13:16
Added icons check-in: 72c2dcfca3 user: petr tags: trunk
2010-11-06
15:31
Pages now contain real content. Ripped out template code from string. check-in: e0e9548c97 user: petr tags: trunk
12:59
forgot to add files... check-in: 9fe218b652 user: petr tags: trunk
Changes

Added Makefile.











>
>
>
>
>
1
2
3
4
5
deploy:
	tar cvf web.tar *
	tar cvf simple.tar simple.py template.py templates/* static/*
	mv simple.tar ~/public/
	mv web.tar ~/public/

Deleted lib/BaseHTTPServer.pyc.

cannot compute difference between binary files

Deleted lib/socket.pyc.

cannot compute difference between binary files

Changes to simple.py.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
..
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
import sys
sys.path.append("lib")
import time
import BaseHTTPServer
from string import Template
import SimpleHTTPServer


# listen on all interfaces on port 80
HOST_NAME = "0.0.0.0"
PORT_NUMBER = 80


class Handler(object):
    def __init__(self, request):
        self.request = request
        self.request.send_response(200)
        self.request.send_header("Content-type", "text/html")
................................................................................
        self.write = self.request.wfile.write


class Index(Handler):
    def get(self):
        f = open("templates/index.html")
        t = Template(f.read())

































        self.write(t.safe_substitute(dict(hello="whatever")))


class Settings(Handler):
    def get(self):
        f = open("templates/settings.html")
        t = Template(f.read())






        self.write(t.safe_substitute(dict(hello="whatever")))


class Phonebook(Handler):
    def get(self):
        f = open("templates/phonebook.html")
        t = Template(f.read())










        self.write(t.safe_substitute(dict(hello="whatever")))


mapping = {"/": Index,
        "/settings": Settings,
        "/phonebook": Phonebook}






|

>



|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|






>
>
>
>
>
>
|






>
>
>
>
>
>
>
>
>
>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
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
97
import sys
sys.path.append("lib")
import time
import BaseHTTPServer
from template import Template
import SimpleHTTPServer
import glob

# listen on all interfaces on port 80
HOST_NAME = "0.0.0.0"
PORT_NUMBER = 8080


class Handler(object):
    def __init__(self, request):
        self.request = request
        self.request.send_response(200)
        self.request.send_header("Content-type", "text/html")
................................................................................
        self.write = self.request.wfile.write


class Index(Handler):
    def get(self):
        f = open("templates/index.html")
        t = Template(f.read())
        p = open("../lgvp/missed.txt", "r")
        n1 = ""
        for line in p:
            c = line.strip().split(",")
            n1 = n1 + "<tr>"
            for x in c:
                n1 = n1 + "<td>"
                n1 = n1 + x
                n1 = n1 + "</td>"
            n1 = n1 + "</tr>"

        p = open("../lgvp/received.txt", "r")
        n2 = ""
        for line in p:
            c = line.strip().split(",")
            n2 = n2 + "<tr>"
            for x in c:
                n2 = n2 + "<td>"
                n2 = n2 + x
                n2 = n2 + "</td>"
            n2 = n2 + "</tr>"

        p = open("../lgvp/dialed.txt", "r")
        n3 = ""
        for line in p:
            c = line.strip().split(",")
            n3 = n3 + "<tr>"
            for x in c:
                n3 = n3 + "<td>"
                n3 = n3 + x
                n3 = n3 + "</td>"
            n3 = n3 + "</tr>"

        self.write(t.safe_substitute({"missed": n1, "received": n2, "dialed": n3}))


class Settings(Handler):
    def get(self):
        f = open("templates/settings.html")
        t = Template(f.read())
        files = glob.glob("../lgvp/*.cfg")
        dump = ""
        for gf in files:
            cfgfile = open(gf, "r")
            for line in cfgfile:
                dump = dump + line + "<br/>"
        self.write(t.safe_substitute({"dump": dump}))


class Phonebook(Handler):
    def get(self):
        f = open("templates/phonebook.html")
        t = Template(f.read())
        p = open("../lgvp/phonenumber.txt", "r")
        n = ""
        for line in p:
            c = line.strip().split("\t")
            n = n + "<tr>"
            for x in c:
                n = n + "<td>"
                n = n + x
                n = n + "</td>"
            n = n + "</tr>"
        self.write(t.safe_substitute(dict(numbers=n)))


mapping = {"/": Index,
        "/settings": Settings,
        "/phonebook": Phonebook}


Added template.py.



























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
####################################################################
import re as _re

class _multimap:
    """Helper class for combining multiple mappings.

    Used by .{safe_,}substitute() to combine the mapping and keyword
    arguments.
    """
    def __init__(self, primary, secondary):
        self._primary = primary
        self._secondary = secondary

    def __getitem__(self, key):
        try:
            return self._primary[key]
        except KeyError:
            return self._secondary[key]


class _TemplateMetaclass(type):
    pattern = r"""
    %(delim)s(?:
      (?P<escaped>%(delim)s) |   # Escape sequence of two delimiters
      (?P<named>%(id)s)      |   # delimiter and a Python identifier
      {(?P<braced>%(id)s)}   |   # delimiter and a braced identifier
      (?P<invalid>)              # Other ill-formed delimiter exprs
    )
    """

    def __init__(cls, name, bases, dct):
        super(_TemplateMetaclass, cls).__init__(name, bases, dct)
        if 'pattern' in dct:
            pattern = cls.pattern
        else:
            pattern = _TemplateMetaclass.pattern % {
                'delim' : _re.escape(cls.delimiter),
                'id'    : cls.idpattern,
                }
        cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)


class Template:
    """A string class for supporting $-substitutions."""
    __metaclass__ = _TemplateMetaclass

    delimiter = '$'
    idpattern = r'[_a-z][_a-z0-9]*'

    def __init__(self, template):
        self.template = template

    # Search for $$, $identifier, ${identifier}, and any bare $'s

    def _invalid(self, mo):
        i = mo.start('invalid')
        lines = self.template[:i].splitlines(True)
        if not lines:
            colno = 1
            lineno = 1
        else:
            colno = i - len(''.join(lines[:-1]))
            lineno = len(lines)
        raise ValueError('Invalid placeholder in string: line %d, col %d' %
                         (lineno, colno))

    def substitute(self, *args, **kws):
        if len(args) > 1:
            raise TypeError('Too many positional arguments')
        if not args:
            mapping = kws
        elif kws:
            mapping = _multimap(kws, args[0])
        else:
            mapping = args[0]
        # Helper function for .sub()
        def convert(mo):
            # Check the most common path first.
            named = mo.group('named') or mo.group('braced')
            if named is not None:
                val = mapping[named]
                # We use this idiom instead of str() because the latter will
                # fail if val is a Unicode containing non-ASCII characters.
                return '%s' % val
            if mo.group('escaped') is not None:
                return self.delimiter
            if mo.group('invalid') is not None:
                self._invalid(mo)
            raise ValueError('Unrecognized named group in pattern',
                             self.pattern)
        return self.pattern.sub(convert, self.template)

    def safe_substitute(self, *args, **kws):
        if len(args) > 1:
            raise TypeError('Too many positional arguments')
        if not args:
            mapping = kws
        elif kws:
            mapping = _multimap(kws, args[0])
        else:
            mapping = args[0]
        # Helper function for .sub()
        def convert(mo):
            named = mo.group('named')
            if named is not None:
                try:
                    # We use this idiom instead of str() because the latter
                    # will fail if val is a Unicode containing non-ASCII
                    return '%s' % mapping[named]
                except KeyError:
                    return self.delimiter + named
            braced = mo.group('braced')
            if braced is not None:
                try:
                    return '%s' % mapping[braced]
                except KeyError:
                    return self.delimiter + '{' + braced + '}'
            if mo.group('escaped') is not None:
                return self.delimiter
            if mo.group('invalid') is not None:
                return self.delimiter
            raise ValueError('Unrecognized named group in pattern',
                             self.pattern)
        return self.pattern.sub(convert, self.template)

Changes to templates/index.html.

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
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                Nortel 1535 Management Interface
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
                <a href="/settings">Settings</a><br/>
            </div>
            <div class="yui3-u" id="content">
                <div class="yui3-g">
                    <div class="yui3-u-1-3">
                        <h3>Missed</h3>
                        $hello<br/>
                        bla<br/>
                        bla<br/>














                    </div>


                    <div class="yui3-u-1-3">
                        <h3>Received</h3>
                        bla<br/>
                        bla<br/>

















                    </div>


                    <div class="yui3-u-1-3">
                        <h3>Called</h3>
                        bla<br/>
                        bla<br/>

















                    </div>
                </div>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>







|











|

|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
|

<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
|

<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                <h1>Nortel 1535 Management Interface</h1>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
                <a href="/settings">Settings</a><br/>
            </div>
            <div class="yui3-u" id="content">
                <div class="yui3-g">
                    <div class="yui3-u-1">
                        <h3>Missed</h3>
                        <table>
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Number</th>
                                    <th>Time</th>
                                    <th>?</th>
                                    <th>End time</th>
                                    <th>?</th>
                                    <th>?</th>
                                    <th>?</th>
                                </tr>
                            </thead>
                            <tbody>
                                $missed
                            </tbody>
                        </table>
                    </div>
                </div>    
                <div class="yui3-g">
                    <div class="yui3-u-1">
                        <h3>Received</h3>


                        <table>
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Number</th>
                                    <th>Time</th>
                                    <th>?</th>
                                    <th>End time</th>
                                    <th>?</th>
                                    <th>?</th>
                                    <th>?</th>
                                </tr>
                            </thead>
                            <tbody>
                                $received
                            </tbody>
                        </table>
                    </div>
                </div>    
                <div class="yui3-g">
                    <div class="yui3-u-1">
                        <h3>Called</h3>


                        <table>
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Number</th>
                                    <th>Time</th>
                                    <th>?</th>
                                    <th>End time</th>
                                    <th>?</th>
                                    <th>?</th>
                                    <th>?</th>
                                </tr>
                            </thead>
                            <tbody>
                                $dialed
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>

Changes to templates/phonebook.html.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                Nortel 1535 Management Interface
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
................................................................................
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Number</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>John Doe</td>
                            <td>1234567890</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>







|







 







|
<
<
<











19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
39
40
41
42
43
44
45
46



47
48
49
50
51
52
53
54
55
56
57
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                <h1>Nortel 1535 Management Interface</h1>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
................................................................................
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Number</th>
                        </tr>
                    </thead>
                    <tbody>
                        $numbers



                    </tbody>
                </table>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>

Changes to templates/settings.html.

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
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                Nortel 1535 Management Interface
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
                <a href="/settings">Settings</a><br/>
            </div>
            <div class="yui3-u" id="content">
                <h1>Settings</h1>
                This is a simple settings page.
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>







|











|









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
                width: 810px;
            }
        </style>
    </head>
    <body>
        <div class="yui3-g">
            <div class="yui3-u-1">
                <h1>Nortel 1535 Management Interface</h1>
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u" id="nav">
                <h3>Menu</h3>
                <a href="/">Home</a><br/>
                <a href="/phonebook">Phonebook</a><br/>
                <a href="/settings">Settings</a><br/>
            </div>
            <div class="yui3-u" id="content">
                <h1>Settings</h1>
                $dump
            </div>
        </div>
        <div class="yui3-g">
            <div class="yui3-u-1">
                &copy; 2010 Petr Man
            </div>
        </div>
    </body>
</html>