import re


def parseAutosarVersionAndSchema(xmlRoot):
   """
   Parses AUTOSAR version from the attributes in the root AUTOSAR tag
   Returns a tuple with major,minor,patch,schemaFile (all integers except schemaFile which is string)
   """
   schemaLocation = None
   for key in xmlRoot.attrib.keys():
      if key.endswith('schemaLocation'):
         value = xmlRoot.attrib[key]
         #Retreive the schema file
         result = re.search(r'(^[ ]+\.xsd)', value)
         tmp = value.partition(' ')
         if len(tmp[2])>0 is not None:
            schemaFile = tmp[2]
         else:
            schemaFile = None
         #Is this AUTOSAR 3?
         result = re.search(r'(\d)\.(\d)\.(\d)', value)
         if result is not None:
            return (int(result.group(1)),int(result.group(2)),int(result.group(3)), schemaFile)
         else:
            #Is this AUTOSAR 4?
            result = re.search(r'(\d)-(\d)-(\d).*\.xsd', value)
            if result is not None:
               return (int(result.group(1)),int(result.group(2)),int(result.group(3)), schemaFile)
            
   return (None, None, None)