import os
home = os.environ["HOME"]
oldloc = os.path.join(home, "creation", "oldstories")
newloc = os.path.join(home, "creation", "stories")

def adjust(old, new):
	try: stat = os.stat(old)
	except FileNotFoundError:
		print("old not found", old)
		return
	print("old", stat.st_mtime_ns, old)
	print("new", stat.st_mtime_ns, new)
	diff = os.stat(new).st_mtime_ns - stat.st_mtime_ns
	if diff > 1000000:
		print("fix", diff)
		os.utime(new, ns=(stat.st_atime_ns, stat.st_mtime_ns))
	print("")
	
os.chdir(newloc)
for topname in os.listdir(os.curdir) :
	print(topname)
	if os.path.isdir(topname):
		isgit = os.path.isdir(os.path.join(topname, ".git"))
		os.chdir(topname)
		for top, ds, ns in os.walk(os.curdir):
			print(ns, ds)
			for n in tuple(ns)+tuple(ds):
				try:
					adjust(os.path.join(oldloc, topname+"-old", top, n),
								 os.path.join(top, n))
				except FileNotFoundError:
					print("topname was", topname)
					raise
		os.chdir('..')
	adjust(os.path.join(oldloc, topname),
				 os.path.join(newloc, topname))
		
