Commits

mcc committed d4572aa

Don't double-log stuff when loading input

  • Participants
  • Parent commits 83464d7

Comments (0)

Files changed (1)

File server/server.py

 </dc>
 """)
 
+def initLog():
+	lo = history_dom.createElement("init")
+	for gid, g in m.tanks.iteritems():
+		lot = history_dom.createElement("tank")
+		lot.setAttribute("gid", str(gid))
+		lot.setAttribute("gc", str(g.generation_count))
+		for sid,s in g.specs.iteritems():
+			s.archive_xml(history_dom, lot)
+		lo.appendChild(lot)
+	return lo
+
 # After the fact
 
 def main():
 		print("Will save to %s" % (options.database))
 		
 	input = None
+	temp_history = None
 	if options.input:
 		print("Loading from %s" % (options.input))
 		with open(options.input) as f:
 			input_raw = ("<wrap>%s</wrap>" % input_raw)
 			input = xml.dom.minidom.parseString(input_raw)
 			if input:
-				input = input.firstChild # wrap			
+				input = input.firstChild # wrap	
+			temp_history = history_file # suppress history while loading
+			history_file = None
 		
 	global m
 	m = Manager(input)
 	
 	if options.norun:
 		print("BY REQUEST, WON'T RUN")
+		if input:
+			lo = initLog()
+			print(lo.toxml())
 		return
 	
 	if history_file: # initial logging
-		lo = history_dom.createElement("init")
-		for gid, g in m.tanks.iteritems():
-			lot = history_dom.createElement("tank")
-			lot.setAttribute("gid", str(gid))
-			lot.setAttribute("gc", str(g.generation_count))
-			for sid,s in g.specs.iteritems():
-				s.archive_xml(history_dom, lot)
-			lo.appendChild(lot)
-			lot = None # How aggressive is Python's gc...?
+		lo = initLog()
 		history_file.write(lo.toxml())
 		history_file.write("\n")
 		history_file.flush()
 		lo = None
 	
+	if temp_history:
+		history_file = temp_history
+	
 	application = tornado.web.Application([
 		(r"/", MainHandler),
 		(r"/welcome", WelcomeHandler),