~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: drtomc
  • Date: 2008-02-20 09:41:48 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:522
Add quite a lot of stuff to get usrmgt happening.

login.py: A little bit of robustifying logic that logs you out if your account
    is still pending when you try to auth. Basically, this forces usrmgt-server
    to have another try.

authenticate.py: A small code rearrangement to produce the right behaviour
    (a generic login/passwd error) when an unknown user logs in (better than
    an internal server error :-) ).

usrmgt-server, makeuser.py: Lots of stuff to setup users. Quite a bit of stuff
    that should be db-driven is hard coded at the moment. (Only a week and a
    half till students will be hitting it, and we can't do everything!)

setup.py: Add an extra bit of svn related config.

users.sql,user.py,db.py: Add the svn_pass column to allow ivle to auth to the
    subversion server.

studpath.py: update a couple of comments to reflect a newer view of the world.

python-console: Add some timeout magic. Actually, I don't think this works,
    but it's well after bedtime, and I've still got to ride home from work.
    The morning will be soon enough.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import common.chat
18
18
 
 
19
class ExpiryTimer(object):
 
20
    def __init__(self, idle):
 
21
        self.idle = idle
 
22
        signal.signal(signal.SIGALRM, partial(self.timeout,self))
 
23
 
 
24
    def ping(self):
 
25
        signal.alarm(self.idle)
 
26
 
 
27
    def start(self, time):
 
28
        signal.alarm(time)
 
29
 
 
30
    def stop(self):
 
31
        self.ping()
 
32
 
 
33
    def timeout(self, signum, frame):
 
34
        sys.exit(1)
 
35
        
19
36
class StdinFromWeb(object):
20
37
    def __init__(self, cmdQ, lineQ):
21
38
        self.cmdQ = cmdQ
23
40
 
24
41
    def readline(self):
25
42
        # stop the clock!
26
 
        signal.alarm(0)
27
43
        self.cmdQ.put({"input":None})
 
44
        expiry.ping()
28
45
        ln = self.lineQ.get()
29
46
        if 'chat' in ln:
30
 
            # restart the clock:
31
 
            # Some of our 5 seconds may have elapsed, but never mind.
32
 
            signal.alarm(5)
33
47
            return ln['chat']
34
48
 
35
49
class PythonRunner(Thread):
44
58
            sys.stdin = StdinFromWeb(self.cmdQ, self.lineQ)
45
59
            sys.stdout = self.out
46
60
            sys.stderr = self.out
47
 
            signal.alarm(5)
48
61
            res = eval(cmd, self.globs, self.locls)
49
 
            signal.alarm(0)
50
62
            self.cmdQ.put({"okay":(self.out.getvalue(),res)})
51
63
            self.curr_cmd = ''
52
64
            self.out = cStringIO.StringIO()
53
65
        except Exception, exc:
54
 
            signal.alarm(0)
55
66
            self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
56
67
            self.curr_cmd = ''
57
68
            self.out = cStringIO.StringIO()
77
88
                    else:
78
89
                        self.execCmd(cmd)
79
90
                except Exception, exc:
80
 
                    signal.alarm(0)
81
91
                    self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
82
92
                    self.curr_cmd = ''
83
93
                    self.out = cStringIO.StringIO()
87
97
                    cmd = compile(ln['block'], "<web session>", 'exec');
88
98
                    self.execCmd(cmd)
89
99
                except Exception, exc:
90
 
                    signal.alarm(0)
91
100
                    self.cmdQ.put({"exc":(self.out.getvalue(),str(exc))})
92
101
                    self.curr_cmd = ''
93
102
                    self.out = cStringIO.StringIO()
115
124
lineQ = Queue.Queue()
116
125
interpThread = PythonRunner(cmdQ, lineQ)
117
126
 
 
127
# Default expiry time of 15 minutes
 
128
expiry = ExpiryTimer(15 * 60)
 
129
 
118
130
def initializer():
119
131
    interpThread.setDaemon(True)
120
132
    interpThread.start()
 
133
    expiry.ping()
121
134
 
122
135
def dispatch_msg(msg):
 
136
    expiry.ping()
123
137
    lineQ.put({msg['cmd']:msg['text']})
124
138
    return cmdQ.get()
125
139