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

« back to all changes in this revision

Viewing changes to ivle/console.py

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
import cjson
34
34
 
35
 
import ivle.conf
36
35
from ivle import chat
37
36
 
38
 
# Outside Jail
39
 
trampoline_path = os.path.join(ivle.conf.lib_path, "trampoline")
40
 
# Inside Jail
41
 
python_path = "/usr/bin/python"
42
 
console_dir = os.path.join(ivle.conf.share_path, 'services')
43
 
console_path = os.path.join(console_dir, 'python-console')
44
 
 
45
37
class ConsoleError(Exception):
46
38
    """ The console failed in some way. This is bad. """
47
39
    def __init__(self, value):
122
114
class Console(object):
123
115
    """ Provides a nice python interface to the console
124
116
    """
125
 
    def __init__(self, uid, jail_path, working_dir):
 
117
    def __init__(self, config, uid, jail_path, working_dir):
126
118
        """Starts up a console service for user uid, inside chroot jail 
127
119
        jail_path with work directory of working_dir
128
120
        """
129
121
        super(Console, self).__init__()
130
122
 
 
123
        self.config = config
131
124
        self.uid = uid
132
125
        self.jail_path = jail_path
133
126
        self.working_dir = working_dir
168
161
        while tries < 5:
169
162
            self.port = int(random.uniform(3000, 8000))
170
163
 
 
164
            trampoline_path = os.path.join(self.config['paths']['lib'],
 
165
                                           "trampoline")
 
166
 
171
167
            # Start the console server (port, magic)
172
168
            # trampoline usage: tramp uid jail_dir working_dir script_path args
173
169
            # console usage:    python-console port magic
174
170
            res = os.spawnv(os.P_WAIT, trampoline_path, [
175
171
                trampoline_path,
176
172
                str(self.uid),
177
 
                ivle.conf.jail_base,
178
 
                ivle.conf.jail_src_base,
179
 
                ivle.conf.jail_system,
 
173
                self.config['paths']['jails']['mounts'],
 
174
                self.config['paths']['jails']['src'],
 
175
                self.config['paths']['jails']['template'],
180
176
                self.jail_path,
181
 
                console_dir,
182
 
                python_path,
183
 
                console_path,
 
177
                os.path.join(self.config['paths']['share'], 'services'),
 
178
                "/usr/bin/python",
 
179
                os.path.join(self.config['paths']['share'],
 
180
                             'services/python-console'),
184
181
                str(self.port),
185
182
                str(self.magic),
186
183
                self.working_dir
300
297
              
301
298
        # Unpickle any exceptions
302
299
        if 'exception' in execute:
303
 
            return cPickle.loads(execute['exception'])
304
 
        else:
305
 
            return execute
 
300
            execute['exception'] = cPickle.loads(execute['exception'])
 
301
        return execute
306
302
 
307
303
 
308
304
    def set_vars(self, variables):