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

« back to all changes in this revision

Viewing changes to ivle/console.py

  • Committer: David Coles
  • Date: 2009-12-10 01:18:36 UTC
  • Revision ID: coles.david@gmail.com-20091210011836-6kk2omcmr9hvphj0
Correct documentation's system diagram (console communication goes via Application Slaves)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import errno
25
25
import cPickle
26
 
import md5
 
26
import hashlib
27
27
import os
28
28
import random
29
29
import socket
32
32
 
33
33
import cjson
34
34
 
35
 
import ivle.conf
36
 
from ivle import (chat, util)
37
 
 
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')
 
35
from ivle import chat
44
36
 
45
37
class ConsoleError(Exception):
46
38
    """ The console failed in some way. This is bad. """
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
154
147
 
155
148
        # Create magic
156
149
        # TODO
157
 
        self.magic = md5.new(uuid.uuid4().bytes).digest().encode('hex')
 
150
        self.magic = hashlib.md5(uuid.uuid4().bytes).hexdigest()
158
151
 
159
152
        # Try to find a free port on the server.
160
153
        # Just try some random ports in the range [3000,8000)
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