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

« back to all changes in this revision

Viewing changes to ivle/webapp/console/service.py

  • Committer: Matt Giuca
  • Date: 2009-04-28 10:43:41 UTC
  • Revision ID: matt.giuca@gmail.com-20090428104341-gb7721sqfr5zwmzz
ivle.makeuser: make_svn_auth now requires a config argument.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        # Start the server
53
53
        jail_path = os.path.join(req.config['paths']['jails']['mounts'],
54
54
                                 req.user.login)
55
 
        cons = ivle.console.Console(req.config, uid, jail_path, working_dir)
 
55
        cons = ivle.console.Console(uid, jail_path, working_dir)
56
56
 
57
57
        # Assemble the key and return it. Yes, it is double-encoded.
58
58
        return {'key': cjson.encode({"host": cons.host,
81
81
        working_dir = os.path.join("/home", req.user.login)   # Within jail
82
82
        uid = req.user.unixid
83
83
 
84
 
        # XXX: JSONRESTView should do this for us.
85
 
        text = text.decode('utf-8')
86
 
 
87
84
        msg = {'cmd':kind, 'text':text}
88
85
        try:
89
86
            json_response = ivle.chat.chat(host, port, msg, magic,decode=False)
96
93
                response = {"terminate":
97
94
                    "Communication to console process lost"}
98
95
            if "terminate" in response:
99
 
                response = restart_console(req.config, uid, jail_path,
100
 
                    working_dir, response["terminate"])
 
96
                response = restart_console(uid, jail_path, working_dir,
 
97
                    response["terminate"])
101
98
        except socket.error, (enumber, estring):
102
99
            if enumber == errno.ECONNREFUSED:
103
100
                # Timeout: Restart the session
104
 
                response = restart_console(req.config, uid, jail_path,
105
 
                    working_dir,
 
101
                response = restart_console(uid, jail_path, working_dir,
106
102
                    "The IVLE console has timed out due to inactivity")
107
103
            elif enumber == errno.ECONNRESET:
108
104
                # Communication issue: Restart the session
109
 
                response = restart_console(req.config, uid, jail_path,
110
 
                    working_dir,
 
105
                response = restart_console(uid, jail_path, working_dir,
111
106
                    "Connection with the console has been reset")
112
107
            else:
113
108
                # Some other error - probably serious
115
110
        return response
116
111
 
117
112
 
118
 
def restart_console(config, uid, jail_path, working_dir, reason):
 
113
def restart_console(uid, jail_path, working_dir, reason):
119
114
    """Tells the client that it must be issued a new console since the old 
120
115
    console is no longer availible. The client must accept the new key.
121
116
    Returns the JSON response to be given to the client.
122
117
    """
123
118
    # Start a new console server console
124
 
    cons = ivle.console.Console(config, uid, jail_path, working_dir)
 
119
    cons = ivle.console.Console(uid, jail_path, working_dir)
125
120
 
126
121
    # Make a JSON object to tell the browser to restart its console client
127
122
    new_key = cjson.encode(