<commit_before>import os
import plistlib
import time

from mojo.extensions import ExtensionBundle
from version import Version

from mechanic.storage import Storage
from mechanic.repositories.github import GithubRepo
from mechanic.event import evented


class Extension(object):
    """Facilitates loading the configuration from and updating extensions."""

    ticks_per_download = 4

    @classmethod
    def all(cls):
        return [cls(name=n) for n in ExtensionBundle.allExtensions()]

    def __init__(self, name=None, path=None):
        self.name = name
        self.bundle = ExtensionBundle(name=self.name, path=path)
        self.config = None
        self.remote = None
        self.config = self.read_config()
        if self.config is not None:
            self.remote = self.initialize_remote()

    @evented()
    def update(self, extension_path=None):
        """Download and install the latest version of the extension."""

        if extension_path is None:
            extension_path = self.remote.download()

        Extension(path=extension_path).install()

    @evented()
    def install(self):
        # TODO: Make this a noop if path isn't present
        self.bundle.install()

    @evented()
    def uninstall(self):
        self.bundle.deinstall()

    def is_current_version(self):
        """Return if extension is at curent version"""
        if not self.remote.version:
            self.remote.get()
        return Version(self.remote.version) <= Version(self.config['version'])

    def has_configuration(self):
        return os.path.exists(self.config_path)

    def read_config(self):
        if self.has_configuration():
            return plistlib.readPlist(self.config_path)

    def read_repository(self):
        return self.read_config_key('com.robofontmechanic.repository') or \
            self.read_config_key('repository')

    def read_config_key(self, key):
        if hasattr(self.config, key):
            return self.config[key]

    def initialize_remote(self):
        extension_path = self.read_config_key('extensionPath')
        repository = self.read_repository()
        if repository:
            return GithubRepo(repository,
                              name=self.name,
                              extension_path=extension_path)

    @property
    def may_update(self):
        ignore = Storage.get('ignore')
        return self.bundle.name not in ignore and self.is_configured
<commit_msg>fix remote read/get error<commit_after>import os
import plistlib
import time

from mojo.extensions import ExtensionBundle
from version import Version

from mechanic.storage import Storage
from mechanic.repositories.github import GithubRepo
from mechanic.event import evented


class Extension(object):
    """Facilitates loading the configuration from and updating extensions."""

    ticks_per_download = 4

    @classmethod
    def all(cls):
        return [cls(name=n) for n in ExtensionBundle.allExtensions()]

    def __init__(self, name=None, path=None):
        self.name = name
        self.bundle = ExtensionBundle(name=self.name, path=path)
        self.config = None
        self.remote = None
        self.config = self.read_config()
        if self.config is not None:
            self.remote = self.initialize_remote()

    @evented()
    def update(self, extension_path=None):
        """Download and install the latest version of the extension."""

        if extension_path is None:
            extension_path = self.remote.download()

        Extension(path=extension_path).install()

    @evented()
    def install(self):
        # TODO: Make this a noop if path isn't present
        self.bundle.install()

    @evented()
    def uninstall(self):
        self.bundle.deinstall()

    def is_current_version(self):
        """Return if extension is at curent version"""
        if not self.remote.version:
            self.remote.read()
        return Version(self.remote.version) <= Version(self.config['version'])

    def has_configuration(self):
        return os.path.exists(self.config_path)

    def read_config(self):
        if self.has_configuration():
            return plistlib.readPlist(self.config_path)

    def read_repository(self):
        return self.read_config_key('com.robofontmechanic.repository') or \
            self.read_config_key('repository')

    def read_config_key(self, key):
        if hasattr(self.config, key):
            return self.config[key]

    def initialize_remote(self):
        extension_path = self.read_config_key('extensionPath')
        repository = self.read_repository()
        if repository:
            return GithubRepo(repository,
                              name=self.name,
                              extension_path=extension_path)

    @property
    def may_update(self):
        ignore = Storage.get('ignore')
        return self.bundle.name not in ignore and self.is_configured

{'fraction_non_alphanumeric': 0.09127871518601342, 'fraction_numerical': 0.0004065867046147591, 'mean_word_length': 2.6309963099630997, 'pattern_counts': {'":': 0, '<': 5, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1849761', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1307, 'n_words': 343}