<commit_before>from xmodule.modulestore.django import modulestore
from xmodule.modulestore.xml import XMLModuleStore


def import_from_xml(org, course, data_dir):
    """
    Import the specified xml data_dir into the django defined modulestore,
    using org and course as the location org and course.
    """
    module_store = XMLModuleStore(org, course, data_dir, 'xmodule.raw_module.RawDescriptor', eager=True)
    for module in module_store.modules.itervalues():
        modulestore().create_item(module.location)
        if 'data' in module.definition:
            modulestore().update_item(module.location, module.definition['data'])
        if 'children' in module.definition:
            modulestore().update_children(module.location, module.definition['children'])
        modulestore().update_metadata(module.location, dict(module.metadata))

    return module_store.course<commit_msg>Swallow attempts to create a new item where one already exists<commit_after>from xmodule.modulestore.django import modulestore
from xmodule.modulestore.xml import XMLModuleStore
import logging

log = logging.getLogger(__name__)


def import_from_xml(org, course, data_dir):
    """
    Import the specified xml data_dir into the django defined modulestore,
    using org and course as the location org and course.
    """
    module_store = XMLModuleStore(org, course, data_dir, 'xmodule.raw_module.RawDescriptor', eager=True)
    for module in module_store.modules.itervalues():

        # TODO (cpennington): This forces import to overrite the same items.
        # This should in the future create new revisions of the items on import
        try:
            modulestore().create_item(module.location)
        except:
            log.exception('Item already exists at %s' % module.location.url())
            pass
        if 'data' in module.definition:
            modulestore().update_item(module.location, module.definition['data'])
        if 'children' in module.definition:
            modulestore().update_children(module.location, module.definition['children'])
        modulestore().update_metadata(module.location, dict(module.metadata))

    return module_store.course
{'fraction_non_alphanumeric': 0.08944954128440367, 'fraction_numerical': 0.0, 'mean_word_length': 3.741304347826087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068619', 'n_tokens_mistral': 598, 'n_tokens_neox': 586, 'n_words': 163}