Not logged in
Check-in [29adb27577]

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

Overview
Comment:Application is now using python logging.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:29adb2757709473b915ad5d8a1f77cb857045c2f
User & Date: petr 2010-11-12 18:10:38
Context
2010-11-12
18:30
Handle get requests with parameters. check-in: 72aecd3a47 user: petr tags: trunk
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
Changes

Added logging.conf.













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[loggers]
keys=root

[handlers]
keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

Changes to web.py.

1
2

3

4
5
6
7
8



9

10
11


12
13
14
15
16
17
18
...
100
101
102
103
104
105
106

107
108
109
110
111
112
113
...
119
120
121
122
123
124
125

126
127
128
129
130
131
132
...
138
139
140
141
142
143
144

145
146
147
148
149
150
151
...
177
178
179
180
181
182
183

184
185
186
187
188
189
190
...
195
196
197
198
199
200
201

202
203
204
205
206
207
208
...
278
279
280
281
282
283
284
285


286
287
288

289


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304


305
306
307
308
309
310
311











312
313
314
315
316
317
318
import sys
import os

sys.path.append("lib")

import time
import BaseHTTPServer
from template import Template
import SimpleHTTPServer
import glob



from optparse import OptionParser

import elementtree.ElementTree as ET
from daemon import Daemon



VERSION = 0.1

def loadDSV(data, separator=",", strip=True):
    out = []
    for line in data:
        if strip:
................................................................................
                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

................................................................................
                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

................................................................................
                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

................................................................................
                        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


................................................................................
            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


................................................................................

    def run(self):
        runmain(self.options)


def runmain(options):
    # listen on all interfaces on port 8080
    if not os.getenv("NORTEL_BIND"):


        NORTEL_BIND = "0.0.0.0"
    else:
        NORTEL_BIND = os.getenv("NORTEL_BIND")

    if not os.getenv("NORTEL_PORT"):


        NORTEL_PORT = 8080
    else:
        NORTEL_PORT = int(os.getenv("NORTEL_PORT"))

    server_class = BaseHTTPServer.HTTPServer
    httpd = server_class((NORTEL_BIND, NORTEL_PORT), App)
    print time.asctime(), "Server Starts - %s:%s" % (NORTEL_BIND, NORTEL_PORT)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print time.asctime(), "Server Stops - %s:%s" % (NORTEL_BIND, NORTEL_PORT)

if __name__ == '__main__':


    parser = OptionParser(usage="%prog [options] start|stop|restart",
                          version="Nortel 1535 Web Interface %s" % VERSION)
    parser.add_option("-d", "--debug",
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="do not fork")












    (options, args) = parser.parse_args()

    if (not options.debug) and (len(args) != 1):
        print "Incorrect number of arguments.\n"
        print parser.print_help()
        sys.exit(2)


>

>


<


>
>
>

>


>
>







 







>







 







>







 







>







 







>







 







>







 







|
>
>
|

|
>
|
>
>
|

|



|





|


>
>






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







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
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import sys
import os

sys.path.append("lib")

import time
import BaseHTTPServer

import SimpleHTTPServer
import glob
import logging
import logging.config
import traceback as tb
from optparse import OptionParser

import elementtree.ElementTree as ET
from daemon import Daemon

from template import Template

VERSION = 0.1

def loadDSV(data, separator=",", strip=True):
    out = []
    for line in data:
        if strip:
................................................................................
                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)
                tb.print_exc()
        finally:
            try:
                p.close()
            except:
                pass
        return calls

................................................................................
                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)
                tb.print_exc()
        finally:
            try:
                p.close()
            except:
                pass
        return calls

................................................................................
                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)
                tb.print_exc()
        finally:
            try:
                p.close()
            except:
                pass
        return calls

................................................................................
                        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)
                    tb.print_exc()
            finally:
                try:
                    p.close()
                except:
                    pass


................................................................................
            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)
                tb.print_exc()
        finally:
            try:
                p.close()
            except:
                pass


................................................................................

    def run(self):
        runmain(self.options)


def runmain(options):
    # listen on all interfaces on port 8080
    if os.getenv("NORTEL_BIND"):
        NORTEL_BIND = os.getenv("NORTEL_BIND")
    elif options.address:
        NORTEL_BIND = options.address
    else:
        NORTEL_BIND = "0.0.0.0"

    if os.getenv("NORTEL_PORT"):
        NORTEL_PORT = int(os.getenv("NORTEL_PORT"))
    elif options.port:
        NORTEL_PORT = options.port
    else:
        NORTEL_PORT = 8080

    server_class = BaseHTTPServer.HTTPServer
    httpd = server_class((NORTEL_BIND, NORTEL_PORT), App)
    logging.info("Server Starts - %s:%s" % (NORTEL_BIND, NORTEL_PORT))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    logging.info("Server Stops - %s:%s" % (NORTEL_BIND, NORTEL_PORT))

if __name__ == '__main__':
    logging.config.fileConfig("logging.conf")

    parser = OptionParser(usage="%prog [options] start|stop|restart",
                          version="Nortel 1535 Web Interface %s" % VERSION)
    parser.add_option("-d", "--debug",
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="Do not fork.")

    parser.add_option("-p", "--port",
                      action="store",
                      type="int",
                      dest="port",
                      help="Port. Default 8080.")

    parser.add_option("-a", "--address",
                      action="store",
                      dest="address",
                      help="Address to bind to. Default 0.0.0.0.")

    (options, args) = parser.parse_args()

    if (not options.debug) and (len(args) != 1):
        print "Incorrect number of arguments.\n"
        print parser.print_help()
        sys.exit(2)