<commit_before>"""
    minecraftinstall
"""
from __future__ import absolute_import, division, print_function
import hashlib
import re
from PySide import QtGui
import logging
import os
from PySide.QtCore import Qt
from mcedit2.resourceloader import ResourceLoader

from mcedit2.util import settings
from mcedit2.util.load_ui import load_ui
from mceditlib import directories

log = logging.getLogger(__name__)

installationsOption = settings.Settings().getOption("minecraft_installs/installations")
currentInstallOption = settings.Settings().getOption("minecraft_installs/current_install", int)

class MCInstall(object):
    def __init__(self, path, name="Unnamed"):
        self.name = name
        self.path = path

    def checkUsable(self):
        """
        Raises MCInstallError explaining why this install is unusable, or else does nothing
        :return:
        :rtype:
        """
        log.info("Checking install at %s", self.path)
        if not os.path.exists(self.path):
            raise MCInstallError("Minecraft folder does not exist.")
        if not os.path.exists(self.versionsDir):
            raise MCInstallError("Minecraft versions folder does not exist.")
        if not len(self.versions):
            raise MCInstallError("Minecraft folder has no minecraft versions")
        log.info("Found versions:\n%s", self.versions)
        requiredVersions = [v for v in self.versions if v.startswith("1.8")]
        if not len(requiredVersions):
            raise MCInstallError("Minecraft version 1.8 and up is required. Use the Minecraft Launcher to download it.")

    @property
    def versionsDir(self):
        return os.path.join(self.path, "versions")

    @property
    def versions(self):
        versions = os.listdir(self.versionsDir)
        return [v for v in versions
                if os.path.exists(self.getVersionJarPath(v))
                and usableVersion(v)]

    def getVersionJarPath(self, version):
        return os.path.join(self.versionsDir, version, "%s.jar" % version)

    @property
    def resourcePacks(self):
        return os.listdir(os.path.join(self.path, "resourcepacks"))

    def getSaveFileDir(self):
        return os.path.join(self.path, "saves")

    def getResourcePackPath(self, filename):
        return os.path.join(self.path, "resourcepacks", filename)

    def getJsonSettingValue(self):
        return {"name": self.name,
                "path": self.path}

    def getResourceLoader(self, version, resourcePack):
        loader = ResourceLoader()
        if resourcePack:
            loader.addZipFile(self.getResourcePackPath(resourcePack))
        loader.addZipFile(self.getVersionJarPath(version))
        major, minor, rev = splitVersion(version)

        # Need v1.8 for block models
        if (major, minor) < (1, 8):
            v1_8 = self.findVersion1_8()
            loader.addZipFile(self.getVersionJarPath(v1_8))

        def md5hash(filename):
            md5 = hashlib.md5()
            with file(filename, "rb") as f:
                md5.update(f.read())
                return md5.hexdigest()
        info = ["%s (%s)" % (z.filename, md5hash(z.filename)) for z in loader.zipFiles]
        log.info("Created ResourceLoader with search path:\n%s", ",\n".join(info))
        return loader

    def findVersion1_8(self):
        for v in self.versions:
            major, minor, rev = splitVersion(v)
            if (major, minor) >= (1, 8):
                if rev == "":
                    return v
                try:
                    rev = int(rev)  # skip revs like ".2-pre1" and ".1-OptiFine_HD_U_C7", only accept full releases
                    return v
                except ValueError:
                    pass

def splitVersion(version):
    """
    Split a Minecraft version ID into major, minor, and revision. If the version could not be parsed, return (0, 0, "")<commit_msg>Allow findVersion1_8 to accept (1, 8, ".2")<commit_after>"""
    minecraftinstall
"""
from __future__ import absolute_import, division, print_function
import hashlib
import re
from PySide import QtGui
import logging
import os
from PySide.QtCore import Qt
from mcedit2.resourceloader import ResourceLoader

from mcedit2.util import settings
from mcedit2.util.load_ui import load_ui
from mceditlib import directories

log = logging.getLogger(__name__)

installationsOption = settings.Settings().getOption("minecraft_installs/installations")
currentInstallOption = settings.Settings().getOption("minecraft_installs/current_install", int)

class MCInstall(object):
    def __init__(self, path, name="Unnamed"):
        self.name = name
        self.path = path

    def checkUsable(self):
        """
        Raises MCInstallError explaining why this install is unusable, or else does nothing
        :return:
        :rtype:
        """
        log.info("Checking install at %s", self.path)
        if not os.path.exists(self.path):
            raise MCInstallError("Minecraft folder does not exist.")
        if not os.path.exists(self.versionsDir):
            raise MCInstallError("Minecraft versions folder does not exist.")
        if not len(self.versions):
            raise MCInstallError("Minecraft folder has no minecraft versions")
        log.info("Found versions:\n%s", self.versions)
        requiredVersions = [v for v in self.versions if v.startswith("1.8")]
        if not len(requiredVersions):
            raise MCInstallError("Minecraft version 1.8 and up is required. Use the Minecraft Launcher to download it.")

    @property
    def versionsDir(self):
        return os.path.join(self.path, "versions")

    @property
    def versions(self):
        versions = os.listdir(self.versionsDir)
        return [v for v in versions
                if os.path.exists(self.getVersionJarPath(v))
                and usableVersion(v)]

    def getVersionJarPath(self, version):
        return os.path.join(self.versionsDir, version, "%s.jar" % version)

    @property
    def resourcePacks(self):
        return os.listdir(os.path.join(self.path, "resourcepacks"))

    def getSaveFileDir(self):
        return os.path.join(self.path, "saves")

    def getResourcePackPath(self, filename):
        return os.path.join(self.path, "resourcepacks", filename)

    def getJsonSettingValue(self):
        return {"name": self.name,
                "path": self.path}

    def getResourceLoader(self, version, resourcePack):
        loader = ResourceLoader()
        if resourcePack:
            loader.addZipFile(self.getResourcePackPath(resourcePack))
        loader.addZipFile(self.getVersionJarPath(version))
        major, minor, rev = splitVersion(version)

        # Need v1.8 for block models
        if (major, minor) < (1, 8):
            v1_8 = self.findVersion1_8()
            loader.addZipFile(self.getVersionJarPath(v1_8))

        def md5hash(filename):
            md5 = hashlib.md5()
            with file(filename, "rb") as f:
                md5.update(f.read())
                return md5.hexdigest()
        info = ["%s (%s)" % (z.filename, md5hash(z.filename)) for z in loader.zipFiles]
        log.info("Created ResourceLoader with search path:\n%s", ",\n".join(info))
        return loader

    def findVersion1_8(self):
        for v in self.versions:
            major, minor, rev = splitVersion(v)
            if (major, minor) >= (1, 8):
                if rev == "":
                    return v
                try:
                    rev = int(rev[1:])  # skip revs like ".2-pre1" and ".1-OptiFine_HD_U_C7", only accept full releases
                    return v
                except ValueError:
                    pass

def splitVersion(version):
    """
    Split a Minecraft version ID into major, minor, and revision. If the version could not be parsed, return (0, 0, "")
{'fraction_non_alphanumeric': 0.10284688381636317, 'fraction_numerical': 0.00923313670171839, 'mean_word_length': 2.5194043321299637, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6702740', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2202, 'n_words': 616}