Exemple #1
0
class LocalGC(object):
    """ A version of the global context which can be intialized to
    provide local paths """
    
    def __init__(self, local = '/'):
        self.gc = GC()
        self.local = local
    def __getitem__(self, name):
        return self.getProvider(name)
    def __getattr__(self, attr):
        if attr == 'providers':
            return self.gc.providers
    def registerProvider(self, provider):
        name = provider.getName()
        if name[0] != '/':
            name = self.local + name
        provider.setName(name)
        self.gc.registerProvider(provider)
    def registerThread(self, name, thread):
        self.gc.registerThread(name, thread)
    def getProvider(self, name):
        try:
            if name[0] != '/':
                name = self.local + name
            return self.gc.getProvider(name)
        except:
            print
            print "Provider by name: '" + name + "' not found in global or local context"
            print
            raise
Exemple #2
0
 def __init__(self, local = '/'):
     self.gc = GC()
     self.local = local
Exemple #3
0
def bootstrap(user_boot, ic_console = True, settings_db = None):
    (vmajor, vminor, vmicro, vrl, vserial) = sys.version_info
    print
    print "Welcome to the Cymbeline Framework"
    print "-------------------------------------------"
    print "System Release 1.3.0 on Python " + `vmajor` + "." + `vminor` + "." + `vmicro` + vrl + `vserial` +" " + sys.platform
    print "(c) 2002-2004-2005 Yann Ramin, All Right Reserved."
    print
    print "Beginning bootstrap..."

    print "Current path:"
    print sys.path
    print
    sys.stdout.write("Creating global context... ")
    gc = GC() # create the all mighty global context


    print "OK"


    sys.stdout.write("--- Creating providers...\n")

    sys.stdout.write("Time...     ")
    gc.registerProvider(Time('/system/time'))
    print "OK"

    sys.stdout.write("Log...      ")
    log = Log('/system/log')
    gc.registerProvider(log)
    log.log('system', 'Logging started')
    print "OK"


    sys.stdout.write("Timer...    ") # system event timer
    gc.registerProvider(Timer('/system/timer'))
    print "OK"

    sys.stdout.write("Settings DB... ")
    
    # start up database providers
    # create magic :)

    try:
        filein = settings_db
        gc.registerProvider(MemoryDB( '/system/settings', filein, autoload = 1, dumpinterval = 100))
        sys.stdout.write("(init from " + filein + ") ")
        
       # gc.getProvider('db_settings').loadFromFile()

    except:
        print
        print
        print "No settings database specified, or unable to load."
        print
        raise

    print "OK"

    sys.stdout.write("Interactive console...")
    ic = CymbelineIC( "/system/ic")

    gc.registerProvider(ic)
    print "OK"
    

    print "--- System providers created. "
    print "--- Starting user bootstrap code"

    user_boot(gc)

    print "--- User bootstrap completed"

    if ic_console is True:
        print "--- Switching to interactive console"
        print

        ic.ic_console()
        print "Exiting the main console - So long, and thanks for all the fish"
        return
    else:
        while 1:
            time.sleep(100)