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

« back to all changes in this revision

Viewing changes to ivle/console.py

  • Committer: Matt Giuca
  • Date: 2009-02-24 02:02:03 UTC
  • mto: This revision was merged to the branch mainline in revision 1119.
  • Revision ID: matt.giuca@gmail.com-20090224020203-aqdcjnsj6y7wl32o
Added a new look to the IVLE header bar. Mmmm... Web 2.0.
Added top-level directory image-source, containing SVG and script files for
    generating the images.
ivle/webapp/coremedia/images: Added 'chrome' directory containing the rendered
    images.
Modified ivle/webapp/base/ivle-headings.html and
    ivle/webapp/coremedia/ivle.css to support the new images.
    Note that the H1 and H2 at the top of the page are no longer displayed
    (and their custom styles have been removed). There is a heading image
    instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import errno
25
25
import cPickle
26
 
import hashlib
 
26
import md5
27
27
import os
28
28
import random
29
29
import socket
32
32
 
33
33
import cjson
34
34
 
35
 
from ivle import chat
 
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')
36
44
 
37
45
class ConsoleError(Exception):
38
46
    """ The console failed in some way. This is bad. """
114
122
class Console(object):
115
123
    """ Provides a nice python interface to the console
116
124
    """
117
 
    def __init__(self, config, uid, jail_path, working_dir):
 
125
    def __init__(self, uid, jail_path, working_dir):
118
126
        """Starts up a console service for user uid, inside chroot jail 
119
127
        jail_path with work directory of working_dir
120
128
        """
121
129
        super(Console, self).__init__()
122
130
 
123
 
        self.config = config
124
131
        self.uid = uid
125
132
        self.jail_path = jail_path
126
133
        self.working_dir = working_dir
147
154
 
148
155
        # Create magic
149
156
        # TODO
150
 
        self.magic = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
157
        self.magic = md5.new(uuid.uuid4().bytes).digest().encode('hex')
151
158
 
152
159
        # Try to find a free port on the server.
153
160
        # Just try some random ports in the range [3000,8000)
161
168
        while tries < 5:
162
169
            self.port = int(random.uniform(3000, 8000))
163
170
 
164
 
            trampoline_path = os.path.join(self.config['paths']['lib'],
165
 
                                           "trampoline")
166
 
 
167
171
            # Start the console server (port, magic)
168
172
            # trampoline usage: tramp uid jail_dir working_dir script_path args
169
173
            # console usage:    python-console port magic
170
174
            res = os.spawnv(os.P_WAIT, trampoline_path, [
171
175
                trampoline_path,
172
176
                str(self.uid),
173
 
                self.config['paths']['jails']['mounts'],
174
 
                self.config['paths']['jails']['src'],
175
 
                self.config['paths']['jails']['template'],
 
177
                ivle.conf.jail_base,
 
178
                ivle.conf.jail_src_base,
 
179
                ivle.conf.jail_system,
176
180
                self.jail_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'),
 
181
                console_dir,
 
182
                python_path,
 
183
                console_path,
181
184
                str(self.port),
182
185
                str(self.magic),
183
186
                self.working_dir
297
300
              
298
301
        # Unpickle any exceptions
299
302
        if 'exception' in execute:
300
 
            execute['exception'] = cPickle.loads(execute['exception'])
301
 
        return execute
 
303
            return cPickle.loads(execute['exception'])
 
304
        else:
 
305
            return execute
302
306
 
303
307
 
304
308
    def set_vars(self, variables):