def get_resources_dests(resources_root, rules):
def get_rel_path(base, path):<EOL><INDENT>base = base.replace(os.path.sep, '<STR_LIT:/>')<EOL>path = path.replace(os.path.sep, '<STR_LIT:/>')<EOL>assert path.startswith(base)<EOL>return path[len(base):].lstrip('<STR_LIT:/>')<EOL><DEDENT>destinations = {}<EOL>for base, suffix, dest in rules:<EOL><INDENT>prefix = os.path.join(resources_root, base)<EOL>for abs_base in iglob(prefix):<EOL><INDENT>abs_glob = os.path.join(abs_base, suffix)<EOL>for abs_path in iglob(abs_glob):<EOL><INDENT>resource_file = get_rel_path(resources_root, abs_path)<EOL>if dest is None:  <EOL><INDENT>destinations.pop(resource_file, None)<EOL><DEDENT>else:<EOL><INDENT>rel_path = get_rel_path(abs_base, abs_path)<EOL>rel_dest = dest.replace(os.path.sep, '<STR_LIT:/>').rstrip('<STR_LIT:/>')<EOL>destinations[resource_file] = rel_dest + '<STR_LIT:/>' + rel_path<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return destinations<EOL>
Find destinations for resources files