'Replace all identical files with symlinks to save disk space/upload bandwidth'

def replace_with_symlinks(self, lang_dir):

    from calibre import walk
    base = self.a(lang_dir)
    for f in walk(base):
        r = os.path.relpath(f, base)
        orig = self.j(self.d(base), r)
        try:
            sz = os.stat(orig).st_size
        except EnvironmentError:
            continue
        if ((sz == os.stat(f).st_size) and filecmp._do_cmp(f, orig)):
            os.remove(f)
            os.symlink(os.path.relpath(orig, self.d(f)), f)
