~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: 2010-02-23 05:18:48 UTC
  • Revision ID: matt.giuca@gmail.com-20100223051848-8kxdsitlvkeyl4gt
Added handlers and documentation for Subversion status 'ignored' (we call them 'Temporary file (ignored)'. This was previously handled as an 'unknown status'. Ignored files now can't have svn actions done on them either. This fixes Launchpad bug #526220.

Show diffs side-by-side

added added

removed removed

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