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

« back to all changes in this revision

Viewing changes to lib/common/console.py

  • Committer: dcoles
  • Date: 2008-08-21 03:11:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1037
Console: More clean up work to try and prevent coding errors from getting cmdQ 
and lineQ out of sync (that's very bad!). We now use functions to handle each 
request and the top level loop does the queue management. In short, don't mess 
directly with the queues unless you know what you're doing!

Also added in a ExistingConsole class (extends Console) which can be used to 
connect up an existing console process rather than a new one with most of the 
functionality of the Console class. (Basically you can't start a new console)

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        """Starts up a console service for user uid, inside chroot jail 
127
127
        jail_path with work directory of working_dir
128
128
        """
 
129
        super(Console, self).__init__()
 
130
 
129
131
        self.uid = uid
130
132
        self.jail_path = jail_path
131
133
        self.working_dir = working_dir
320
322
        """ Causes the console process to terminate """
321
323
        return self.__chat('terminate', None)
322
324
    
323
 
 
 
325
class ExistingConsole(Console):
 
326
    """ Provides a nice python interface to an existing console.
 
327
    Note: You can't restart an existing console since there is no way to infer 
 
328
    all the starting parameters. Just start a new Console instead.
 
329
    """
 
330
    def __init__(self, host, port, magic):
 
331
        self.host = host
 
332
        self.port = port
 
333
        self.magic = magic
 
334
 
 
335
        # Set up the buffers
 
336
        self.stdin = TruncateStringIO()
 
337
        self.stdout = TruncateStringIO()
 
338
        self.stderr = TruncateStringIO()
 
339
 
 
340
    def restart():
 
341
        raise NotImplementedError('You can not restart an existing console')
 
342