Example #1
0
def reload(module):
    ''' Reloads a module.
    
        Usage::
        
            reload module=my_module
    
    '''

    if module.startswith('compmake'):
        try:
            dave = pwd.getpwuid(os.getuid())[0]
        except:
            dave = 'Dave'
        user_error("I'm sorry, %s. I'm afraid I can't do that." % dave)
        return
        
    try:     
        # otherwise import("A.B") returns A instead of A.B
        m = __import__(module, fromlist=['dummy'])
    except Exception as e:
        raise UserError('Cannot find module "%s": %s.' % (module, e))
        
    try: 
        imp.reload(m)
    except Exception as e:
        raise UserError('Obtained this exception while reloading the module:'
                        ' %s' % e)
    
    info('Reloaded module "%s".' % module)
    
Example #2
0
def interactive_console():
    publish('console-starting') 
    exit_requested = False
    while not exit_requested:
        try:
            for line in compmake_console():
                commands = line.strip().split()
                if commands:
                    try:
                        publish('command-starting', command=commands)
                        interpret_commands(commands)
                        publish('command-succeeded', command=commands)
                    except UserError as e:
                        publish('command-failed', command=commands, reason=e)
                        user_error(e)
                    except CompmakeException as e:
                        publish('command-failed', command=commands, reason=e)
                        # Added this for KeyboardInterrupt
                        error(e)
                    except KeyboardInterrupt:
                        publish('command-interrupted',
                                command=commands, reason='keyboard')
                        user_error('Execution of "%s" interrupted' % line)
                    except ShellExitRequested:
                        exit_requested = True
                        break
                    except Exception as e:
                        traceback.print_exc()
                        error('Warning, I got this exception, while it should have'
                              ' been filtered out already. This is a compmake BUG '
                              ' that should be reported:  %s' % e)
                        
        except KeyboardInterrupt:  # CTRL-C
            print "\nPlease use 'exit' to quit."
        except EOFError: # CTRL-D
            # TODO maybe make loop different? we don't want to catch
            # EOFerror in interpret_commands
            print "(end of input detected)"
            exit_requested = True
    
    publish('console-ending')
    return