'Symlink project subprojects
Link from $WEB_ROOT/projects/<project> ->
$WEB_ROOT/<project>'

def symlink_subprojects(self):

    subprojects = set()
    rels = self.get_subprojects()
    if rels.count():
        if (not os.path.exists(self.subproject_root)):
            safe_makedirs(self.subproject_root)
    for rel in rels:
        from_to = OrderedDict({rel.child.slug: rel.child.slug})
        subprojects.add(rel.child.slug)
        if rel.alias:
            from_to[rel.alias] = rel.child.slug
            subprojects.add(rel.alias)
        for (from_slug, to_slug) in list(from_to.items()):
            self._log(u'Symlinking    subproject:    {0}    ->    {1}'.format(from_slug, to_slug))
            symlink = os.path.join(self.subproject_root, from_slug)
            docs_dir = os.path.join(self.WEB_ROOT, to_slug)
            symlink_dir = os.sep.join(symlink.split(os.path.sep)[:(-1)])
            if (not os.path.lexists(symlink_dir)):
                safe_makedirs(symlink_dir)
            run(('ln    -nsf    %s    %s' % (docs_dir, symlink)))
    if os.path.exists(self.subproject_root):
        for subproj in os.listdir(self.subproject_root):
            if (subproj not in subprojects):
                os.unlink(os.path.join(self.subproject_root, subproj))
