Пример #1
0
    def run(self):
        """main loop of the class.  General substep runs:
        * displayable have 'body' and 'menu' attributes.
        * non-displayable as a 'next' target.
        * transitions to Dispatcher steps have 'nextstep' value.
        """

        # Generic substep stream start-up
        # If step doesn't have self.start, then it has to explicitly
        # assign self.substep.  Furthermore, step is not re-startable.
        if not hasattr(self, 'substep') and hasattr(self, 'start'):
            self.substep = self.start

        while True:
            try:
                substep = self.substep
            except Exception, ex:
                log.warn(str(ex))
                substep = self.start
            if substep:
                substep()  # execute the substep
            else:
                log.warn("returning from TextRunner.run()")
                return textengine.DISPATCH_NEXT
            if 'body' in self.substepEnv:
                # This is a user interface (ui) step.
                ui = self.substepEnv
                textengine.render(ui)

                inputType = ui.get("input", "default")
                assert inputType in ['default', 'passwords'], \
                     'unknown inputType: %s' % inputType

                self.substepPrev = self.substep  # save in case push/pop

                # build parameter lists and invoke
                if inputType == 'default':
                    prompt = ui.get('prompt', '> ')
                elif inputType == 'passwords':
                    # plural because we always want two trials of passwords
                    prompts = ui.get('prompts',
                                     ['Password: '******'Confirm password: '******'short', None)
                else:
                    raise ValueError, 'unrecognized type of input'

                try:
                    ui['menu'].setdefault('!', self.cancel)
                    if inputType == 'default':
                        nextstate, self.userinput = \
                            textengine.waitinput(ui['menu'], prompt=prompt)
                        log.debug(
                            'substep %s - input:  %s' %
                            (self.substep.im_func.__name__, self.userinput))
                    elif inputType == 'passwords':
                        nextstate, self.userinput = \
                            textengine.waitpasswords(ui['menu'], prompts, short)
                        log.debug('substep %s - password' % self.substep)
                    else:
                        raise ValueError, 'unrecognized type of input'
                except Exception, ex:
                    msg = str(ex)
                    if msg:
                        log.warn(msg)
                        if msg[-1] != '\n':
                            msg += '\n'
                    if isinstance(ex, textengine.InvalidUserInput):
                        print msg, textengine.BEL
                        nextstate = self.substep  # do not change substep
                    elif isinstance(ex, EOFError):
                        print textengine.BEL
                        nextstate = self.substep  # do not change substep
                    else:
                        log.error('unknown step error')
                        print msg, textengine.BEL
                        assert hasattr(self, 'start'), 'step restart failure'
                        nextstate = self.start

                self.substep = nextstate  # where to go next
Пример #2
0
        s = "<%s:%s>" % (type(a), str(a))
        outstr += s
    outstr += '\n'
    fauxStdout.append(outstr)


textengine._cons_output = newConsOutput
textengine._cons_output_oob = newConsOutputOob

import password_ui

def fauxPswdInput(_prompt):
    textengine._cons_input = newConsInput
    return ("mypass", "mypass")

password_ui._pswd_cons_input = fauxPswdInput

if __name__ == "__main__":
    # simple test
    fauxStdin = ['first', 'second', 'third' ]
    content = { 'title': 'sample page',
        'body': 'Here are a\ncouple of lines of text' }
    textengine.render(content)
    instr = raw_input('a prompt')

    print fauxStdin
    print instr
    print fauxStdout

# vim: set sw=4 tw=80 :
Пример #3
0
 def rescan(self):
     textengine.render({'body': 'Probing for installation media...'})
     self.mediaFound = (cdutil.findCdMedia(showAll=True) +
                        usbmedia.findUSBMedia(showAll=True))
     self.setSubstepEnv( {'next': self.start} )
Пример #4
0
    def run(self):
        """main loop of the class.  General substep runs:
        * displayable have 'body' and 'menu' attributes.
        * non-displayable as a 'next' target.
        * transitions to Dispatcher steps have 'nextstep' value.
        """

        # Generic substep stream start-up
        # If step doesn't have self.start, then it has to explicitly
        # assign self.substep.  Furthermore, step is not re-startable.
        if not hasattr(self,'substep') and  hasattr(self, 'start'):
            self.substep = self.start

        while True:
            try:
                substep = self.substep
            except Exception, ex:
                log.warn(str(ex))
                substep = self.start
            if substep:
                substep()   # execute the substep
            else:
                log.warn("returning from TextRunner.run()")
                return textengine.DISPATCH_NEXT
            if 'body' in self.substepEnv:
                # This is a user interface (ui) step.
                ui = self.substepEnv
                textengine.render(ui)

                inputType = ui.get("input", "default")
                assert inputType in ['default', 'passwords'], \
                     'unknown inputType: %s' % inputType

                self.substepPrev = self.substep  # save in case push/pop

                # build parameter lists and invoke
                if inputType == 'default':
                    prompt = ui.get('prompt', '> ')
                elif inputType == 'passwords':
                    # plural because we always want two trials of passwords
                    prompts = ui.get('prompts',
                        ['Password: '******'Confirm password: '******'short', None)
                else:
                    raise ValueError, 'unrecognized type of input'

                try:
                    ui['menu'].setdefault('!', self.cancel)
                    if inputType == 'default':
                        nextstate, self.userinput = \
                            textengine.waitinput(ui['menu'], prompt=prompt)
                        log.debug('substep %s - input:  %s' %
                            (self.substep.im_func.__name__, self.userinput))
                    elif inputType == 'passwords':
                        nextstate, self.userinput = \
                            textengine.waitpasswords(ui['menu'], prompts, short)
                        log.debug('substep %s - password' % self.substep)
                    else:
                        raise ValueError, 'unrecognized type of input'
                except Exception, ex:
                    msg = str(ex)
                    if msg:
                        log.warn(msg)
                        if msg[-1] != '\n':
                            msg += '\n'
                    if isinstance(ex, textengine.InvalidUserInput):
                        print msg, textengine.BEL
                        nextstate = self.substep   # do not change substep
                    elif isinstance(ex, EOFError):
                        print textengine.BEL
                        nextstate = self.substep   # do not change substep
                    else:
                        log.error('unknown step error')
                        print msg, textengine.BEL
                        assert hasattr(self, 'start'), 'step restart failure'
                        nextstate = self.start

                self.substep = nextstate  # where to go next