#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import os.path
import sys

def get_files_to_sync(args):
    for path in args:
        for name in os.listdir(path):
            yield os.path.join(path, name), name

def sync(files, destdir):
    for path, name in files:
        dest = os.path.join(destdir, name)
        if os.path.exists(dest):
            if os.path.islink(dest):
                os.remove(dest)
                os.symlink(path, dest)
        else:
            os.symlink(path, dest)

if __name__ == '__main__':
    sync(get_files_to_sync(sys.argv[1:-1]), sys.argv[-1])