Not logged in
Check-in [8ff81bb394]

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

Overview
Comment:Some preliminary error handling.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8ff81bb3940a653f2fb7184541ed3e1a4cd714bb
User & Date: petr 2010-11-12 15:43:47
Context
2010-11-12
18:10
Application is now using python logging. check-in: 29adb27577 user: petr tags: trunk
15:43
Some preliminary error handling. check-in: 8ff81bb394 user: petr tags: trunk
14:40
Converting html generation from strings to et. check-in: deb87d550f user: petr tags: trunk
Changes

Changes to static/general.css.

33
34
35
36
37
38
39

40










41
42
43
44
45
46
47
48
49
}
#footer {
    border-top: 1px solid #ccc;
    padding-top: 15px;
}
table {
    width: 100%;

}










tr:nth-child(odd) {
    background-color: #BBBBBB;
}
tr:nth-child(even) {
    background-color: #F4F4F4;
}
.center {
    text-align: center;
}







>

>
>
>
>
>
>
>
>
>
>

|







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
}
#footer {
    border-top: 1px solid #ccc;
    padding-top: 15px;
}
table {
    width: 100%;
    border-width: 0px;
}
td {
    border-width: 0px;
}
tr {
    border-width: 0px;
}
th {
    border-width: 0px;
    background-color: #BBBBBB;
}
tr:nth-child(odd) {
    background-color: #DDDDDD;
}
tr:nth-child(even) {
    background-color: #F4F4F4;
}
.center {
    text-align: center;
}

Changes to web.py.

58
59
60
61
62
63
64







65
66
67
68
69




70
71
72
73
74
75
76
..
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
126
127
128
129
130
131
...
168
169
170
171
172
173
174
175


176
177
178
179
180
181
182
        out.append("</tr>")
    return "".join(out)


class Handler(object):
    def __init__(self, request):
        self.request = request







        self.request.send_response(200)
        self.request.send_header("Content-type", "text/html")
        self.request.end_headers()
        self.write = self.request.wfile.write






class Index(Handler):
    def get(self):
        t_index = Template("templates/global.tpl", content="templates/index.tpl")
        p = open("../lgvp/missed.txt", "r")
        n1 = missed2table(p)
        p = open("../lgvp/received.txt", "r")
................................................................................
        p = open("../lgvp/dialed.txt", "r")
        n3 = missed2table(p)
        self.write(t_index.safe_substitute({"missed": n1, "received": n2,
            "dialed": n3, "title": "All calls"}))


class Calls(Handler):

























































    def get(self):
        t_calls = Template("templates/global.tpl", content="templates/calls.tpl")
        if self.request.path.endswith("missed"):
            ct = "Missed calls"
            p = open("../lgvp/missed.txt", "r")
            calls = missed2table(p)
        if self.request.path.endswith("dialed"):
            ct = "Dialed calls"
            p = open("../lgvp/dialed.txt", "r")
            calls = missed2table(p)
        if self.request.path.endswith("received"):
            ct = "Received calls"
            p = open("../lgvp/received.txt", "r")
            calls = missed2table(p)

        self.write(t_calls.safe_substitute({"title": ct, "calls": calls}))


class Settings(Handler):
    def get(self):
        t = Template("templates/global.tpl", content="templates/settings.tpl")
        if self.request.path.endswith("sip"):


            cfgfile = open("../lgvp/vdci.cfg", "r")
            form = ET.Element("form")
            formdata = []
            for line in cfgfile:
                name, value = line.strip().split("=")
                formdata.append([name, ET.Element("input", type="text",
                    value=value, **{"class": "iset"})])
            table = maketable(formdata, header=("vdci.cfg", ""))
            form.append(table)
        self.write(t.safe_substitute({"dump": ET.tostring(form), "title": "Settings"}))









class Phonebook(Handler):
    def get(self):
        t = Template("templates/global.tpl", content="templates/phonebook.tpl")


        p = open("../lgvp/phonenumber.txt", "r")
        n = maketable(loadDSV(p, separator="\t"),
                header=("Name","Number"))
        self.write(t.safe_substitute(dict(phonebook=ET.tostring(n), title="Phonebook")))









class Reboot(Handler):
    def get(self):
        self.write("Rebooting...")
        os.system("sync")
        os.system("reboot")
................................................................................
            return
        elif self.path.startswith("/favicon.ico"):
            self.path = "/static/favicon.ico"
            SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
            return
        else:
            if self.path in mapping.keys():
                mapping[self.path](self).get()


            else:
                self.send_error(404)

    def do_HEAD(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()







>
>
>
>
>
>
>



<

>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




<
|
|

<
|
|

<
<
>







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





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







 







|
>
>







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
..
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158

159
160
161


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
        out.append("</tr>")
    return "".join(out)


class Handler(object):
    def __init__(self, request):
        self.request = request
        self.output = ""
        #self.write = self.request.wfile.write

    def write(self, data):
        self.output = self.output + data

    def headers(self):
        self.request.send_response(200)
        self.request.send_header("Content-type", "text/html")
        self.request.end_headers()


    def flush(self):
        # FIXME FIXME FIXME
        self.headers()
        self.request.wfile.write(self.output)

class Index(Handler):
    def get(self):
        t_index = Template("templates/global.tpl", content="templates/index.tpl")
        p = open("../lgvp/missed.txt", "r")
        n1 = missed2table(p)
        p = open("../lgvp/received.txt", "r")
................................................................................
        p = open("../lgvp/dialed.txt", "r")
        n3 = missed2table(p)
        self.write(t_index.safe_substitute({"missed": n1, "received": n2,
            "dialed": n3, "title": "All calls"}))


class Calls(Handler):
    def missed(self):
        # this is oooooooold python
        calls = ""
        try:
            try:
                p = open("../lgvp/missed.txt", "r")
                calls = missed2table(p)
            except (IOError):
                # FIXME this is broken. will send 500 AND the page
                # should probably throw and excepion which would be cought
                # somewhere in flush()
                self.request.send_error(500)
        finally:
            try:
                p.close()
            except:
                pass
        return calls

    def dialed(self):
        # this is oooooooold python
        calls = ""
        try:
            try:
                p = open("../lgvp/dialed.txt", "r")
                calls = missed2table(p)
            except (IOError):
                # FIXME this is broken. will send 500 AND the page
                # should probably throw and excepion which would be cought
                # somewhere in flush()
                self.request.send_error(500)
        finally:
            try:
                p.close()
            except:
                pass
        return calls

    def received(self):
        # this is oooooooold python
        calls = ""
        try:
            try:
                p = open("../lgvp/received.txt", "r")
                calls = missed2table(p)
            except (IOError):
                # FIXME this is broken. will send 500 AND the page
                # should probably throw and excepion which would be cought
                # somewhere in flush()
                self.request.send_error(500)
        finally:
            try:
                p.close()
            except:
                pass
        return calls

    def get(self):
        t_calls = Template("templates/global.tpl", content="templates/calls.tpl")
        if self.request.path.endswith("missed"):
            ct = "Missed calls"

            calls = self.missed()
        elif self.request.path.endswith("dialed"):
            ct = "Dialed calls"

            calls = self.dialed()
        elif self.request.path.endswith("received"):
            ct = "Received calls"


            calls = self.received()
        self.write(t_calls.safe_substitute({"title": ct, "calls": calls}))


class Settings(Handler):
    def get(self):
        t = Template("templates/global.tpl", content="templates/settings.tpl")
        if self.request.path.endswith("sip"):
            try:
                try:
                    cfgfile = open("../lgvp/vdci.cfg", "r")
                    form = ET.Element("form")
                    formdata = []
                    for line in cfgfile:
                        name, value = line.strip().split("=")
                        formdata.append([name, ET.Element("input", type="text",
                            value=value, **{"class": "iset"})])
                    table = maketable(formdata, header=("vdci.cfg", ""))
                    form.append(table)
                    self.write(t.safe_substitute({"dump": ET.tostring(form), "title": "Settings"}))
                except (IOError):
                    self.request.send_error(500)
            finally:
                try:
                    p.close()
                except:
                    pass


class Phonebook(Handler):
    def get(self):
        t = Template("templates/global.tpl", content="templates/phonebook.tpl")
        try:
            try:
                p = open("../lgvp/phonenumber.txt", "r")
                n = maketable(loadDSV(p, separator="\t"),
                            header=("Name","Number"))
                self.write(t.safe_substitute(dict(phonebook=ET.tostring(n), title="Phonebook")))
            except (IOError):
                self.request.send_error(500)
        finally:
            try:
                p.close()
            except:
                pass


class Reboot(Handler):
    def get(self):
        self.write("Rebooting...")
        os.system("sync")
        os.system("reboot")
................................................................................
            return
        elif self.path.startswith("/favicon.ico"):
            self.path = "/static/favicon.ico"
            SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
            return
        else:
            if self.path in mapping.keys():
                h = mapping[self.path](self)
                h.get()
                h.flush()
            else:
                self.send_error(404)

    def do_HEAD(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()