#!/usr/bin/env python3

from glob import glob
import sys
import os

dir1, dir2 = sys.argv[1:]

files1 = glob(dir1 + '/*')
files2 = glob(dir2 + '/*')

files1 = [f.split('/').pop() for f in files1]
files2 = [f.split('/').pop() for f in files2]

conflicts = [f for f in files1 if f in files2]

for f in files2:
	if f in files1:
		with open(dir1 + '/' + f, 'a') as f1:
			with open(dir2 + '/' + f) as f2:
				f1.write("\n\n")
				f1.write(f2.read())
				print("%s merged" % f)
	else:
		os.rename(dir2 + '/' + f, dir1 + '/' + f)
		print("%s moved" % f)
