Example #1
0
class Extension(object):
    """Facilitates loading the configuration from and updating extensions."""
    def __init__(self, name=None, path=None):
        self.config = {}
        self.configured = False
        self.name = name
        self.bundle = ExtensionBundle(name=self.name, path=path)
        self.path = self.bundle.bundlePath()
        self.configure()

    def configure(self):
        """Set config attribute from info.plist contents."""
        self.configPath = os.path.join(self.path, 'info.plist')
        if(os.path.exists(self.configPath)):
            self.config = plistlib.readPlist(self.configPath)
            if 'repository' in self.config:
                extension_path = self.config['extensionPath'] if hasattr(self.config, 'extensionPath') else None
                self.remote = GithubRepo(self.config['repository'], 
                                         name=self.name,
                                         extension_path=extension_path)
                self.configured = True
            
    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()
        
        new_extension = Extension(path=extension_path)

        self.bundle.deinstall()
        new_extension.bundle.install()
        
    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'])
Example #2
0
class Extension(object):
    """Facilitates loading the configuration from and updating extensions."""

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

    @classmethod
    def install_remote(cls, repository, filename):
        remote = GithubRepository(repository, filename)
        path = remote.download()
        extension = cls(path=path).install()
        shutil.rmtree(path) # TODO: removing the tree should happen after download somehow
        return extension

    def __init__(self, name=None, path=None):
        self.name = name
        self.bundle = ExtensionBundle(name=self.name, path=path)

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

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

        Extension(path=path).install()

    @evented()
    def install(self):
        self.bundle.install()

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

    @lazy_property
    def configuration(self):
        return Configuration(self.configuration_path)

    @lazy_property
    def remote(self):
        return GithubRepository(self.repository, self.filename)

    @property
    def is_current_version(self):
        """Return if extension is at curent version"""
        return self.remote.version <= self.version

    @property
    def is_ignored(self):
        return self.bundle.name in Storage.get('ignore')

    @property
    def is_configured(self):
        return self.repository is not None

    @property
    def is_installed(self):
        return self.bundle.bundleExists()

    @property
    def may_update(self):
        return not self.is_ignored and self.is_configured

    @property
    def should_update(self):
        return self.may_update and not self.is_current_version

    @property
    def configuration_path(self):
        return os.path.join(self.path, 'info.plist')

    @property
    def path(self):
        return self.bundle.bundlePath()

    @property
    def repository(self):
        return self.configuration.namespaced('repository') or \
            self.configuration.deprecated('repository')

    @property
    def version(self):
        return Version(self.configuration['version'])

    @property
    def filename(self):
        return os.path.basename(self.bundle.bundlePath())