示例#1
0
def get_config(extrafiles=None, initdict=None, **kwargs):
    """get_config([extrafiles=], [initdict=], [**kwargs])
Returns a RootContainer instance containing configuration parameters.
An extra dictionary may be merged in with the 'initdict' parameter.
And finally, extra options may be added with keyword parameters when calling
this.  """
    import socketlib
    SOURCES = []
    SOURCES.append(os.path.join(os.environ["HOME"], ".stratatestrc"))

    if type(extrafiles) is str:
        extrafiles = [extrafiles]
    if extrafiles:
        FILES = SOURCES + extrafiles
    else:
        FILES = SOURCES
    try:
        db = get_client()
    except socketlib.SocketError:
        print >>sys.stderr, "Could not connect to server, using local file storage."
        db = get_database()
    cache = AttrDict({"PhysicalQuantity": PhysicalQuantity, "os":os}) # pre-populate with needed objects
    cf = db.get_root(cache)
    # copy default flags to cache so the don't get altered
    cache.flags = cf["flags"].copy()
    # initialize cache items to default values, so they can be altered at runtime.
    cf.update(cf["default"])
    for f in FILES:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    del cache["os"] ; del cache["PhysicalQuantity"]
    return cf
示例#2
0
def get_config(extrafiles=None, initdict=None, **kwargs):
    """get_config([extrafiles=], [initdict=], [**kwargs])
Returns a RootContainer instance containing configuration parameters.
An extra dictionary may be merged in with the 'initdict' parameter.
And finally, extra options may be added with keyword parameters when calling
this.  """
    import socketlib
    SOURCES = []
    SOURCES.append(os.path.join(os.environ["HOME"], ".pynmsrc"))

    if type(extrafiles) is str:
        extrafiles = [extrafiles]
    if extrafiles:
        FILES = SOURCES + extrafiles
    else:
        FILES = SOURCES
    try:
        db = get_client()
    except socketlib.SocketError:
        db = get_database()
    cache = AttrDict()
    cf = db.get_root(cache)
    # copy default flags to cache so the don't get altered
    cache.flags = cf["flags"].copy()
    # initialize cache items to default values, so they can be altered at runtime.
    cf.update(cf["default"])
    for f in FILES:
        if os.path.isfile(f):
            cf.mergefile(f)
    if type(initdict) is dict:
        cf.evalupdate(initdict)
    cf.update(kwargs)
    return cf