Skip to content

Instantly share code, notes, and snippets.

@akelch
Last active December 10, 2021 10:51
Show Gist options
  • Save akelch/30eb281eadfd8328b8286785c5407021 to your computer and use it in GitHub Desktop.
Save akelch/30eb281eadfd8328b8286785c5407021 to your computer and use it in GitHub Desktop.
BoneGen
class xxRel(RelSkel):
name =stringBone(descr="FFFFFFFFFF", required = True)
nameMult = stringBone(descr="gggg", multiple = True, required = True)
spac = spatialBone(descr="GPS POINT",indexed=False, boundsLat=(30.0, 70.0), boundsLng=(-20.0, 50.0), gridDimensions=(1000.0, 1000.0))
class exampleSkel(Skeleton):
def __new__(cls, *args, **kwargs):
bones = [ baseBone, booleanBone, colorBone, credentialBone,numericBone,
dateBone, emailBone, fileBone, passwordBone,
recordBone, relationalBone, selectBone, selectCountryBone,
stringBone, textBone, userBone,spatialBone,treeNodeBone,treeLeafBone ] #, treeLeafBone, treeNodeBone,keyBone randomSliceBone, captchaBone,
#bones = [ numericBone ]
def fillBoneMapRecursive(inCls):
boneMap = {}
for baseCls in inCls.__bases__:
if "__viurBaseSkeletonMarker__" in dir(baseCls):
fillBoneMapRecursive(baseCls)
for key in inCls.__dict__:
prop = getattr(inCls, key)
if isinstance(prop, baseBone):
if "." in key:
raise AttributeError("Invalid bone '%s': Bone keys may not contain a dot (.)" % key)
if key in inCls.__class__._MetaBaseSkel__reservedKeywords_:
raise AttributeError("Invalid bone '%s': Bone cannot have any of the following names: %s" %
(key, str(inCls.__class__._MetaBaseSkel__reservedKeywords_)))
boneMap[key] = prop
return boneMap
for abone in bones:
sets = [{},{"readOnly":True},{"multiple":True},{"multiple":True, "languages":["de","en","fr"]},{"multiple":True, "languages":["de","en","fr"],"readOnly":True}]
sets = [{}] #[{}]#,
for attrset in sets:
setname = "_".join(attrset.keys())
#skip core invalids
if abone.__name__ =="credentialBone" and ("multiple" in attrset or "languages" in attrset):
continue
cname = abone.__name__+setname
boneparams = {"descr":cname, "params":{"category":setname if setname else "example"}}
boneparams.update(attrset)
if abone.type == "select":
boneparams.update( { "values": { "test1":"Test1","test2":"Test2","test3":"Test3" }, "defaultValue":"test1" } )
elif abone.type == "record":
boneparams.update({"using":xxRel, "format":"$(dest.name)"})
elif abone.type =="spatial":
boneparams.update( { "indexed":False, "boundsLat": (30.0, 70.0), "boundsLng": (-20.0, 50.0), "gridDimensions":(1000.0, 1000.0) } )
elif abone.__name__ == "userBone":
pass #boneparams.update( { "kind": "example" } )
elif abone.type == "relational":
boneparams.update( { "kind": "example" } )
elif abone.type in ['relational.tree.leaf','relational.tree.node']:
boneparams.update( { "kind": "file" } )
boneInst = abone(**boneparams)
setattr(cls, "bone_%s"%cname, boneInst) #add bones
cls.__boneMap__.update(fillBoneMapRecursive(cls)) #update map
return super().__new__(cls,*args,**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment