def transFc(fc, dics, idmap): _id = fc['_id'] _cid = _id[:7] #_id = 'TC6H8EU-FC-xuJxcI1416548536490' _cat = 'DC2' _subcat = '0001' _rels = {} _relt1 = get_RLT_id('CONTAINS', _cat, "DC2") # META-RLT-DC2-DC2-1009 _relt2 = get_RLT_id('CONTAINED_BY', _cat, "DC2") # META-RLT-DC2-DC2-0009 for k, v in fc['iddict'].items(): if k == 'rs': _rels[_relt1] = v # fc CONTAINS rs elif k == "owner": _rels[_relt2] = v # fc CONTAINED_BY it dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': b64LSExtract(fc['name']), 'Descr': { 'LSS': ['NAME', 'CONTENT'], 'NAME': flatLSDic(fc['name']), 'ANNO': flatLSDic(fc['anno']), 'TYPE': fc['type'], 'CONTDICT': flatLSDic(fc['contdict']), 'MW_ID': fc['_id'], } }, 'rels': _rels } dics[dic['_id']] = dic idmap[fc["_id"]] = dic['_id']
def transIp(ip, dics, idmap): _id = ip['_id'] _cid = _id[:7] #_id = 'TC6H8EU-IP-hhhhhh1423412341223' _cat = 'DC1' # folder _subcat = '0003' access_level = convertPk(ip.get('pk','M7117')) _rels = {} _rlt1 = get_RLT_id('OWNED_BY', _cat, "PA1") # META-RLT-DC2-PA1-0008 _rlt2 = get_RLT_id('CONTAINS', _cat, 'DC1') # META-RLT-DC1-DC1-1009 _rlt3 = get_RLT_id('CONTAINS', _cat, 'DC2') # META-RLT-DC1-DC2-1009 for k, v in ip['iddict'].items(): if k == 'owner': _rels[_rlt1] = v # owned-by PA1 elif k == 'docs': _rels[_rlt3] = v # containing docs elif k == 'folders': _rels[_rlt2] = v # containing folders dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': b64LSExtract(ip['title']), 'Descr': { 'LSS': ['NAME'], 'NAME': flatLSDic(ip['title']), 'ACCESSLEVEL': access_level, 'MW_ID': ip['_id'], } }, 'rels': _rels } dics[dic['_id']] = dic idmap[ip['_id']] = dic['_id']
def transBa(ba, dics, idmap): _id = ba['_id'] _cid = _id[:7] #_id = 'TC6H8EU' from TC6H8EU-BA-AKmFZi1408857744219 _cat = 'PA2' _subcat = '0000' _rels = {} rlt1 = get_RLT_id("HAS_MALE", _cat, "PA1") #'META-RLT-PA2-PA1-1005' rlt2 = get_RLT_id("HAS_FEMALE", _cat, "PA1") #'META-RLT-PA2-PA1-1006' rlt3 = get_RLT_id("HAS_CHILD", _cat, "PA1") # META-RLT-PA2-PA1-1007' for k, v in ba['iddict'].items(): if k == 'male': _rels[rlt1] = v # RL_HAS_MALE elif k == 'female': _rels[rlt2] = v # RL_HAS_FEMALE elif k == "children": _rels[rlt3] = v # RL_HAS_CHILD dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': '', 'Descr': { 'LSS': [], 'NAME': '', 'MW_ID': ba['_id'] } }, 'rels': _rels } idmap[ba['_id']] = dic['_id'] dics[dic['_id']] = dic
def transPa(pa, dics, idmap): _id = pa['_id'] _cid = _id[:7] #_id = 'TC6H8EU-PA-<6><ts>' _cat = 'PA1' _subcat = 'AUEA' _rels = {} sex = pa['sex'] _rlt1 = get_RLT_id('OWNS', _cat,'DC2') # PA1 owning doc _rlt2 = get_RLT_id('CHILD_OF', _cat, 'PA2') # PA1 child-of PA2 if sex == 'male': _rlt3 = get_RLT_id('MALE_OF','PA1','PA2') # PA1 male of marriage-bond else: _rlt3 = get_RLT_id('FEMALE_OF','PA1','PA2') # PA1 female of PA2 _rlt4 = get_RLT_id('OWNS','PA1','DC1') # PA1 owns folder(DC1) _rlt5 = get_RLT_id('OWNS','PA1','AC1') # PA1 owns account AC1 for k, v in pa.get('iddict',{}).items(): if k == "nutshell": _rels.setdefault(_rlt1, []).append(v) # RL_OWNING nutshell elif k == "parents": _rels[_rlt2] = v # RL_CHILD_OF elif k == "portrait": _rels.setdefault(_rlt1,[]).append(v) # RL_OWNING portrait elif k == "spouses": _rels[_rlt3] = v # RL_HAS_MARR_BOND elif k == "ips": _rels[_rlt4] = v # RL_OWNING info-pane/folder (DC1) else: print('pa has unknown iddict-key: ' + k) dic = { '_id': genID(_cid, _cat, _subcat), 'TS': currentTS, 'cat': _cat, 'subcat': _subcat, 'card': { 'Name': b64LSExtract(pa['tname']), 'Descr': { 'LSS': ['NAME'], 'NAME': flatLSDic(pa['tname']), 'DOB': pa['dob'], 'DOD': pa['dod'], 'POB': flatLSDic(pa.get('pob','')), 'POD': flatLSDic(pa.get('pod','')), 'GENDER': pa.get('sex','male'), 'ROLE': pa.get('role','1'), 'MW_ID': pa['_id'], } }, 'rels': _rels } if _id == "TC6H8EU-PA-AFSmUA1408745022739": print('new id: '+dic['_id']) if 'cfg' in pa: # theme ac1 = makeAC1(_cid, pa) dic['rels'][_rlt5] = [ac1['_id']] dics[ac1['_id']] = ac1 dics[dic['_id']] = dic idmap[pa['_id']] = dic['_id']
def makeAC1(_cid, pa): if 'M7519' in pa['cfg']: theme = pa['cfg']['M7519'] else: theme = 'default' if "M1507" in pa['cfg']: # 'Title' pagetitle = pa['cfg']['M1507'] else: pagetitle = "TXkgRmFtaWx5" if "M1504" in pa['cfg']: loginpwd = pa['cfg']['M1504']['login'][0] else: loginpwd = '******' if "M1508" in pa['cfg']: lang = pa['cfg']['M1508'] else: lang = 'en' if "M1502" in pa['cfg']: email = pa['cfg']['M1502'] else: email = '' if "M7534" in pa['cfg']: trustees = pa['cfg']['M7534'] else: trustees = [] ac1 = { '_id': genID(_cid, "AC1"), # cat: AC1: user-account, no subcat 'TS': currentTS, 'cat': 'AC1', 'subcat': '0000', 'card': { 'Name': 'user account', 'Descr': { 'LSS': ['PAGETITLE','NAME'], 'NAME': 'en:dXNlciBhY2NvdW50', # user account 'PAGETITLE': pagetitle, 'LOGINPWD': loginpwd, 'HASH': "sha256", 'THEME': theme, 'LANG': lang, 'EMAIL': email, 'TRUSTEES': trustees } }, 'rels': { get_RLT_id('OWNED_BY', 'AC1', 'PA1'): [pa['_id']] # RL_OWNED_BY } } return ac1
def transIt(it, dics, idmap): _id = it['_id'] _cid = _id[:7] _name = b64LSExtract(it['name']) if it['type'] == 'F': _cat = 'DC1' # folder _subcat = '0000' # folder else: _cat = 'DC2' # doc _subcat = '0002' # multi-mime doc access_level = convertPk(it.get('pk', 'M7117')) _rels = {} _rlt1 = get_RLT_id('CONTAINS', _cat, 'DC1') # contains folder _rlt2 = get_RLT_id('CONTAINS', _cat, 'DC2') # contains doc _rlt3 = get_RLT_id('CONTAINED_BY', _cat, 'DC1') # contained by DC1(folder) _rlt4 = get_RLT_id('OWNED_BY', _cat, 'PA1') # owned by PA1 for k, v in it['iddict'].items(): if k == 'folders': _rels[_rlt1] = v # 1009: RL_CONTAINING elif k == 'facets': _rels[_rlt2] = v # 1009: RL_CONTAINING DC2/fc elif k == 'owner': _rels[_rlt3] = v # 0008: RL_CONTAINED_BY elif k == 'docs': _rels[_rlt2] = v # 1009: RL_CONTAINING doc elif k == 'ownerpa': _rels[_rlt4] = v # 0008 RL_OWNED_BY PA1 dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': _name, 'Descr': { 'LSS': ['NAME'], 'NAME': flatLSDic(it['name']), 'ACCESSLEVEL': access_level, 'TITLE': flatLSDic(it['title']), 'MW_ID': it['_id'], } }, 'rels': _rels } dics[dic['_id']] = dic idmap[it['_id']] = dic['_id']
def transTd(td, dics, idmap): _id = td['_id'] _cid = _id[:7] #_id = 'TC6H8EU-TD-hNNGaS1408652959879' _cat = 'DC2' _subcat = '0005' # editable text _rels = {} _rlt1 = get_RLT_id('OWNED_BY',_cat, 'PA1') _rlt2 = get_RLT_id('CONTAINED_BY', _cat, 'DC2') for k, v in td['iddict'].items(): if k == "holders": if type(v) == type([]) and len(v) > 0: for i in v: if i[8:10] == 'PA': # owned by PA _rels.setdefault(_rlt1,[]).append(i) else: # contained by DC2 _rels.setdefault(_rlt2,[]).append(i) elif k == "holder": if type(v) == type(''): if v[8:10] == 'PA': _rels.setdefault(_rlt1,[]).append(v) else: _rels.setdefault(_rlt2,[]).append(v) _content = flatLSDic(td['content']) dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': td['name'], 'Descr': { 'LSS': ['NAME','CONTENT'], 'NAME': 'en:' + td['name'], 'CONTENT': _content, 'MW_ID': td['_id'], } }, 'rels': _rels } dics[dic['_id']] = dic idmap[td['_id']] = dic['_id']
def transRs(rs, dics, idmap): _id = rs['_id'] _cid = _id[:7] #_id = 'TC6H8EU-RS-JhXxoG1408651276541' _cat = 'DC2' _subcat = '0004' # media file _rels = {} _rlt1 = get_RLT_id('CONTAINED_BY', _cat, 'DC2') # DC2 contained by DC2 _rlt2 = get_RLT_id('OWNED_BY', _cat, 'PA1') # DC2 owned-by PA1 for k, v in rs['iddict'].items(): if k == 'holders': for i in v: # holder can be PA or FC if i[8:10] == 'PA': # PA owns this rs _rels.setdefault(_rlt2, []).append(i) elif i[8:10] != 'PA': # FC contains this rs _rels.setdefault(_rlt1, []).append(i) dic = { '_id': genID(_cid, _cat, _subcat), 'cat': _cat, 'subcat': _subcat, 'TS': currentTS, 'card': { 'Name': rs['name'], 'Descr': { 'LSS': [], 'NAME': rs['name'], 'SIGNATURE': rs['signature'], 'TITLE': rs['title'], 'SIZE': rs['size'], 'MIME': rs['mime'], 'DATA': rs['data'], 'MW_ID': rs['_id'], } }, 'rels': _rels } dics[dic['_id']] = dic idmap[rs['_id']] = dic['_id']