<commit_before>import imp
import os

from django.conf import settings
from django.utils.translation import gettext as _


_updates_required = []
_install_fine = False


def check_updates_required():
    """
    Checks if there are manual updates required before Review Board can be
    used on this server.
    """
    global _updates_required
    global _install_fine

    if not _updates_required and not _install_fine:
        # Check if there's a media/uploaded/images directory. If not, this is
        # either a new install or is using the old-style media setup and needs
        # to be manually upgraded.
        uploaded_dir = os.path.join(settings.MEDIA_ROOT, "uploaded")

        if not os.path.isdir(uploaded_dir) or \
           not os.path.isdir(os.path.join(uploaded_dir, "images")):
            _updates_required.append((
                "admin/manual-updates/media-upload-dir.html", {
                    'MEDIA_ROOT': settings.MEDIA_ROOT
                }
            ))

        try:
            from reviewboard.changedescs.models import ChangeDescription
            ChangeDescription.objects.count()
        except:
            # We were unable to load this, so it's likely that the user
            # hasn't run syncdb yet.
            _updates_required.append((
                "admin/manual-updates/run-syncdb.html", {}
            ))
<commit_msg>Fix the media root when the old root is invalid.<commit_after>import imp
import os

from django.conf import settings
from django.utils.translation import gettext as _


_updates_required = []
_install_fine = False


def check_updates_required():
    """
    Checks if there are manual updates required before Review Board can be
    used on this server.
    """
    global _updates_required
    global _install_fine

    if not _updates_required and not _install_fine:
        # Check if the site has moved and the old media directory no longer
        # exists.
        if not os.path.exists(settings.MEDIA_ROOT):
            new_media_root = os.path.join(settings.HTDOCS_ROOT, "media")

            if os.path.exists(new_media_root):
                from djblets.siteconfig.models import SiteConfiguration

                siteconfig = SiteConfiguration.objects.get_current()
                siteconfig.set("site_media_root", new_media_root)
                settings.MEDIA_ROOT = new_media_root


        # Check if there's a media/uploaded/images directory. If not, this is
        # either a new install or is using the old-style media setup and needs
        # to be manually upgraded.
        uploaded_dir = os.path.join(settings.MEDIA_ROOT, "uploaded")

        if not os.path.isdir(uploaded_dir) or \
           not os.path.isdir(os.path.join(uploaded_dir, "images")):
            _updates_required.append((
                "admin/manual-updates/media-upload-dir.html", {
                    'MEDIA_ROOT': settings.MEDIA_ROOT
                }
            ))

        try:
            from reviewboard.changedescs.models import ChangeDescription
            ChangeDescription.objects.count()
        except:
            # We were unable to load this, so it's likely that the user
            # hasn't run syncdb yet.
            _updates_required.append((
                "admin/manual-updates/run-syncdb.html", {}
            ))

{'fraction_non_alphanumeric': 0.07580791301721534, 'fraction_numerical': 0.0, 'mean_word_length': 2.169377990430622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '296555', 'n_tokens_mistral': 936, 'n_tokens_neox': 895, 'n_words': 261}