'update each draft. Create any which don\'t exist in published and attach to their parents.'

def _add_draft_modules_to_course(self, published_course_usage_key, source_course_key, user_id, **kwargs):

    new_draft_course_loc = published_course_usage_key.course_key.for_branch(ModuleStoreEnum.BranchName.draft)
    awaiting_adoption = {}
    for module in self.source_modulestore.get_items(source_course_key, revision=ModuleStoreEnum.RevisionOption.draft_only, **kwargs):
        new_locator = new_draft_course_loc.make_usage_key(module.category, module.location.block_id)
        if self.split_modulestore.has_item(new_locator):
            split_module = self.split_modulestore.get_item(new_locator, **kwargs)
            for (name, field) in split_module.fields.iteritems():
                if (field.is_set_on(split_module) and (not module.fields[name].is_set_on(module))):
                    field.delete_from(split_module)
            for (field, value) in self._get_fields_translate_references(module, new_draft_course_loc, published_course_usage_key.block_id, field_names=False).iteritems():
                field.write_to(split_module, value)
            _new_module = self.split_modulestore.update_item(split_module, user_id, **kwargs)
        else:
            _new_module = self.split_modulestore.create_item(user_id, new_draft_course_loc, new_locator.block_type, block_id=new_locator.block_id, fields=self._get_fields_translate_references(module, new_draft_course_loc, published_course_usage_key.block_id), **kwargs)
            awaiting_adoption[module.location] = new_locator
    for (draft_location, new_locator) in awaiting_adoption.iteritems():
        parent_loc = self.source_modulestore.get_parent_location(draft_location, revision=ModuleStoreEnum.RevisionOption.draft_preferred, **kwargs)
        if (parent_loc is None):
            log.warn(u'No    parent    found    in    source    course    for    %s', draft_location)
            continue
        old_parent = self.source_modulestore.get_item(parent_loc, **kwargs)
        split_parent_loc = new_draft_course_loc.make_usage_key(parent_loc.category, (parent_loc.block_id if (parent_loc.category != 'course') else published_course_usage_key.block_id))
        new_parent = self.split_modulestore.get_item(split_parent_loc, **kwargs)
        if any(((new_locator.block_id == child.block_id) for child in new_parent.children)):
            continue
        new_parent_cursor = 0
        for old_child_loc in old_parent.children:
            if (old_child_loc.block_id == draft_location.block_id):
                break
            for idx in range(new_parent_cursor, len(new_parent.children)):
                if (new_parent.children[idx].block_id == old_child_loc.block_id):
                    new_parent_cursor = (idx + 1)
                    break
        new_parent.children.insert(new_parent_cursor, new_locator)
        new_parent = self.split_modulestore.update_item(new_parent, user_id)
