'''
Created on 7 lut 2020

@author: fpawlak
'''

from ConfigParser import RawConfigParser


class AviableLibrariesParser:


    def __init__(self, filePath):
        self.filePath = '{}\\Libraries.lst'.format(filePath)
        self.__config = RawConfigParser()
        self.__config.read(self.filePath)
        
    def getLibraries(self):
        return self.__config.sections()
    
    def getLibraryVersions(self, library):
        return self.__config.options(library)
    
    def getLibraryPath(self, library, version):
        return self.__config.get(library, version)
    
    def addLibrary(self, libraryInfo):
        if not self.__config.has_section(libraryInfo.name):
            self.__config.add_section(libraryInfo.name)
        
        if not self.__config.has_option(libraryInfo.name, libraryInfo.getFullName()):
            self.__config.set(libraryInfo.name, libraryInfo.getFullName(), libraryInfo.path)
        
        with open(self.filePath, 'w+') as fp:
            self.__config.write(fp)