def readHomeSystem(section, fileName, lineNumber):
	blocks = section.split("\n\n")
	for block in blocks:
		lines = block.split("\n")
		for line in lines:
			if line == "":
				continue
			if line == lines[0]:
				#Section header ("Home System")
				assertNotEmpty(line, fileName, lineNumber)
				assertNotSeparator(line, fileName, lineNumber)
			elif line == lines[1]:
				#System name
				assertNotEmpty(line, fileName, lineNumber)
				assertNotSeparator(line, fileName, lineNumber)
				systemName = line.strip().rstrip(":")
				system = System(systemName, "Fixed")
			else:
				#Planet
				assertNotEmpty(line, fileName, lineNumber)
				assertNotSeparator(line, fileName, lineNumber)
				system.addPlanet(line.strip())
			lineNumber+=1
	if block != "":
		lineNumber+=1
	
	return system, lineNumber
def readSystems(fileName, systems):
	with open(fileName, 'r') as systemsFile:
		lineNumber = 1
		sections = systemsFile.read().split("--------------------\n")
		for section in sections:
			if section != "":
				blocks = section.split("\n\n")
				for block in blocks:
					lines = block.split("\n")
					if block == blocks[0]:
						#System type/shape
						assertNumLines(lines, 1, fileName, lineNumber)
						line = lines[0]
						assertNotEmpty(line, fileName, lineNumber)
						assertNotSeparator(line, fileName, lineNumber)
						type = line.split(' ')[0]
						lineNumber += 1
					else:
						#System
						name = ""
						planets = []
						for line in lines:
							line = line.strip()
							if line == "":
								continue
							if line[-1] == ':':
								#System name
								assertNotEmpty(line, fileName, lineNumber)
								assertNotSeparator(line, fileName, lineNumber)
								name = line[:-1]
							elif (line == lines[0] and name == "") or (line == lines[1] and name != ""):
								#Expansion
								expansion = line
								assertValidExpansion(expansion, fileName, lineNumber)
							else:
								#Planet
								assertNotEmpty(line, fileName, lineNumber)
								assertNotSeparator(line, fileName, lineNumber)
								if line != "(None)":
									planets.append(line)
							lineNumber+=1
						system = System(name, type, expansion)
						id = system.getName()
						for planet in planets:
							system.addPlanet(planet)
							id += " " + planet
						id += expansion + type
						systems[id] = system
					if block != "":
						lineNumber+=1
def readHomeSystems(fileName, races):
	with open(fileName, 'r') as homeSystemsFile:
		lineNumber = 1
		sections = homeSystemsFile.read().split("--------------------\n")
		for section in sections:
			if section != "":
				blocks = section.split("\n\n")
				for block in blocks:
					lines = block.split("\n")
					if block == blocks[0]:
						#System type/shape
						assertNumLines(lines, 1, fileName, lineNumber)
						line = lines[0]
						assertSystemType(line.strip()[:-13], fileName, lineNumber)
						assertString(line.strip()[-12:], "Home Systems", fileName, lineNumber)
						type = line.strip()[:-13]
						lineNumber += 1
					else:
						#Race block
						for line in lines:
							if line == "":
								continue
							if line == lines[0]:
								#Race name
								assertNotEmpty(line, fileName, lineNumber)
								assertNotSeparator(line, fileName, lineNumber)
								if (line.strip() == "The Creuss Gate:"):
									raceName = "The Ghosts of Creuss"
									systemName = line.strip().rstrip(":")
								else:
									assertString(line.strip()[-12:], "Home System:", fileName, lineNumber)
									systemName = line.strip().rstrip(":")
									if line.strip()[0:4] != "The ":
										raceName = "The " + line.strip()[:-13]
									else:
										raceName = line.strip()[:-13]
								assertValidRace(line.strip(), races, fileName, lineNumber)
								race = races[raceName]
								system = System(systemName, type)
								race.addHomeSystem(system)
							else:
								#Planet
								assertNotEmpty(line, fileName, lineNumber)
								assertNotSeparator(line, fileName, lineNumber)
								system.addPlanet(line.strip())
							lineNumber+=1
					if block != "":
						lineNumber+=1