source: mauRepo/MolesManager/trunk/src/ascore/utils.py @ 8202

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/ascore/utils.py@8202
Revision 8202, 1.5 KB checked in by mnagni, 8 years ago (diff)

Complete - # 22390: AMEND MOLES2 -> CEDA Moles Author and Co-author migration (plus PI assignment) to CEDA Observation record
 http://team.ceda.ac.uk/trac/ceda/ticket/22390
Incomplete - # 22392: citation migration from MOLES2
 http://team.ceda.ac.uk/trac/ceda/ticket/22392

RevLine 
[8087]1'''
2Created on 6 Feb 2012
3
4@author: mnagni
5'''
[8202]6from sqlalchemy.orm.collections import InstrumentedList
[8087]7def has_value(item):
8    if item is not None:
[8089]9        if (isinstance(item, list) and len(item) > 0) or not isinstance(item, list):           
[8087]10            return True
11        else:
12            return False
[8147]13    return False
14
15def collectionProofHash(tupleToHash):
16    try:
17        return hash(tuple(_convertCollectionToList(tupleToHash)))
18    except Exception as e:
19        print e
20
21def _convertCollectionToList(tupleToHash, processedItems = []): 
22    toHash = []
[8202]23    if tupleToHash is not None and type(tupleToHash) != tuple and type(tupleToHash) != list \
24        and type(tupleToHash) != InstrumentedList and type(tupleToHash) != dict:
25        processedItems.append(tupleToHash)
26        toHash.append(tupleToHash)
27        return toHash
28   
[8147]29    for item in tupleToHash:
30        if item in processedItems:
31            continue
32        processedItems.append(item)
[8202]33        if type(item) == tuple or type(item) == list or type(item) == InstrumentedList:
[8147]34            for innerItem in item:
[8194]35                toHash.extend(_convertCollectionToList(innerItem, processedItems))
[8147]36        elif type(item) == dict:
37            for innerItem in item.keys():
[8194]38                toHash.extend(_convertCollectionToList(innerItem, processedItems))
[8147]39            for innerItem in item.values():
[8194]40                toHash.extend(_convertCollectionToList(innerItem, processedItems))
[8147]41        else:
42            toHash.append(item)
43    return toHash
Note: See TracBrowser for help on using the repository browser.