import glob


def FindMaxVtuId(project, extensions = [".vtu", ".pvtu"]):
  """
  Find the maximum Fluidity vtu ID for the supplied project name
  """
  
  filenames = []
  for ext in extensions:
    filenames += glob.glob(project + "_?*" + ext)
  
  maxId = None
  for filename in filenames:
    id = filename[len(project) + 1:-len(filename.split(".")[-1]) - 1]
    try:
      id = int(id)
    except ValueError:
      continue
      
    if maxId is None:
      maxId = id
    else:
      maxId = max(maxId, id)
  
  return maxId