
from pygr import pygrData,pygrSchema
from metabase import ResourceServer, dumps, OneToManyRelation, OneToOneRelation,\
     ManyToManyRelation, PygrDataNotPortableError, PygrDataNotFoundError, \
     PygrDataMismatchError, PygrDataEmptyError, PygrDataReadOnlyError, \
     PygrDataSchemaError, PygrDataNoModuleError, ResourceZone

schema = pygrSchema # ROOT OF OUR SCHEMA NAMESPACE

# PROVIDE TOP-LEVEL NAMES IN OUR RESOURCE HIERARCHY
Bio = pygrData.Bio

getResource = pygrData._mdb # our metabase interface
addResource = pygrData._mdb.add_resource
def addResourceDict(d, layer=None):
    'queue a dict of name:object pairs for saving to specified db layer'
    if layer is not None: # use the named metabase specified by layer
        mdb = pygrData._mdb.zoneDict[layer] # KeyError if layer not found!
    else: # use default MetabaseList
        mdb = pygrData._mdb
    for k,v in d.items(): # queue each resource in the dictionary
        mdb.add_resource(k, v)

addSchema = pygrData._mdb.add_schema
deleteResource = pygrData._mdb.delete_resource
dir = pygrData._mdb.dir
def newServer(*args, **kwargs):
    return ResourceServer(pygrData._mdb, *args, **kwargs)
save = pygrData._mdb.commit
rollback = pygrData._mdb.rollback
list_pending = pygrData._mdb.list_pending
loads = pygrData._mdb.loads
update = pygrData._mdb.update
clear_cache = pygrData._mdb.clear_cache

# TOP-LEVEL NAMES FOR STANDARDIZED LAYERS
here = ResourceZone(getResource, 'here')
my = ResourceZone(getResource, 'my')
system = ResourceZone(getResource, 'system')
subdir = ResourceZone(getResource, 'subdir')
remote = ResourceZone(getResource, 'remote')
MySQL = ResourceZone(getResource, 'MySQL')

__all__ = ('Bio', 'schema', 'getResource', 'addResource', 'addSchema',
           'deleteResource', 'dir', 'newServer', 'save', 'rollback',
           'list_pending', 'loads', 'dumps', 'update', 'clear_cache',
           'OneToManyRelation', 'ManyToManyRelation',
           'OneToOneRelation', 'PygrDataNotPortableError',
           'PygrDataNotFoundError', 'PygrDataMismatchError',
           'PygrDataEmptyError', 'PygrDataReadOnlyError',
           'PygrDataSchemaError', 'PygrDataNoModuleError',
           'here', 'my', 'system', 'subdir', 'remote', 'MySQL')


@@ -15,21 +15,27 @@
 ort 
-pygrData,pygr
+worldbase,worldbase
 Sche
@@ -340,20 +340,25 @@
 chema = 
-pygr
+worldbase
 Schema #
@@ -446,24 +446,25 @@
 Y%0ABio = 
-pygrData
+worldbase
 .Bio%0A%0Age
@@ -471,32 +471,33 @@
 tResource = 
-pygrData
+worldbase
 ._mdb # our 
@@ -525,32 +525,33 @@
 dResource = 
-pygrData
+worldbase
 ._mdb.add_re
@@ -746,32 +746,33 @@
       mdb = 
-pygrData
+worldbase
 ._mdb.zoneDi
@@ -863,24 +863,25 @@
   mdb = 
-pygrData
+worldbase
 ._mdb%0A  
@@ -988,24 +988,25 @@
 chema = 
-pygrData
+worldbase
 ._mdb.ad
@@ -1027,32 +1027,33 @@
 eResource = 
-pygrData
+worldbase
 ._mdb.delete
@@ -1068,24 +1068,25 @@
 e%0Adir = 
-pygrData
+worldbase
 ._mdb.di
@@ -1145,24 +1145,25 @@
 eServer(
-pygrData
+worldbase
 ._mdb, *
@@ -1181,32 +1181,33 @@
 rgs)%0Asave = 
-pygrData
+worldbase
 ._mdb.commit
@@ -1218,24 +1218,25 @@
 lback = 
-pygrData
+worldbase
 ._mdb.ro
@@ -1257,24 +1257,25 @@
 nding = 
-pygrData
+worldbase
 ._mdb.li
@@ -1293,24 +1293,25 @@
 loads = 
-pygrData
+worldbase
 ._mdb.lo
@@ -1319,32 +1319,33 @@
 ds%0Aupdate = 
-pygrData
+worldbase
 ._mdb.update
@@ -1363,16 +1363,17 @@
 e = 
-pygrData
+worldbase
 ._md

make Data.py use new worldbase names