# -*- coding: utf-8 -*-
import io
import re
"""
Header pliku swdl
"""
class Header():
    def __init__(self,unit_name,unit_address, position, name, phone_number, email,root,swdl):
        ##Nazwa instytucji
        self.unit_name=unit_name
        ##Adres instytucji
        self.unit_address=unit_address
        ##Stanowisko
        self.position=position
        ##Imie i Nazwisko
        self.name=name
        ##Numer telefonu
        self.phone_number=phone_number
        ##Adres mailowy
        self.email=email
        ##Data
        #self.date=date
        ##Wersja
        self.version=self.swdl_version(root,swdl)

    def swdl_version(self,root,swdl)->str:
        try:
            xsd=root+u'/XSD/{}/XSD/swdl/swdl.xsd'.format(swdl)
            file=io.open(xsd)
            lines=file.readlines()
            idx=[lines.index(e) for e in lines if e.strip()=='<xs:element name="swdlVersion">']
            line=lines[idx[0]+6].strip()
            regex=re.compile('[0-9]*\.[0-9]*')
            nr=regex.findall(line)
            return nr[0]

        except Exception as e:
            raise e

        
        
        