Ejemplo n.º 1
0
class Settings:
    def __init__(self):
        self.thesauri = TEntries()
        self.paths = {}
        self.maxUniqueValues = DEFAULT_MAX_DETAIL
        
    def getPath(self, type):
        xp = "../data/musea/"
        if type in self.paths.keys():
            xp = self.paths[type]
        return getDefaultDirectory(path=xp)
        
    def setPath(self,type,path):
        self.paths[type] = path
        
    def addReferenceThesaurus(self, thesaurusName, thesaurusPath, type):
        '''Add reference thesaurus with specified name, path and type to
        to the settings. If the file does not exist or its type is not
        known it is not added.'''
        thesaurusName = utils.ensureUnicode(thesaurusName)
        'TODO: is it safe to convert filenames to unicode?'
        thesaurusPath = utils.ensureUnicode(thesaurusPath)
        type = utils.ensureUnicode(type)
        if not os.path.exists(thesaurusPath):
            return
        if not type in thesaurus_types:
            return
        self.thesauri[thesaurusName] = {"path": thesaurusPath, "type": type, "order": len(self.thesauri)}
        
    def removeReferenceThesaurus(self, thesaurusName):
        '''Removes the thesaurus with specified name if it exists'''
        thesaurusName = utils.ensureUnicode(thesaurusName)
        if thesaurusName in self.thesauri:
            del self.thesauri[thesaurusName]
        
    def validate(self):
        '''Remove all all thesauri for which the file doesnt exist,
        that dont contain the required field "path" and "type", or
        that have an unknown type from the list.'''
        for entry in self.thesauri.values:
            if not os.path.exists(entry.path) or entry.type not in thesaurus_types:
                self.thesauri.remove(entry)
    
    def getReferenceThesauri(self):
        '''Determine which reference thesauri are configured and their locations.
        The returned result is a dict with thesaurus name as key, and a thesaurus dict
        as value. This thesaurus dict has "type" and "path" values'''
        return self.thesauri
Ejemplo n.º 2
0
 def __init__(self):
     self.thesauri = TEntries()
     self.paths = {}
     self.maxUniqueValues = DEFAULT_MAX_DETAIL