def update_modules(self, repository):
        base_dir = path.dirname(path.dirname(path.abspath(__file__)))
        modules_dir = path.join(base_dir, 'modules')

        self._remove_compiled_files(modules_dir)

        installed_modules = self.list_installed_modules_for(repository)
        updated_named_configs = []

        for name, obj in self.walk_modules(modules_dir, repository=repository):
            updated_named_configs += self.update(obj, name, repository)

            if obj.name:
                installed_modules.discard(obj.name)

        # Delete all modules that are no longer in the repository
        for missing_module in installed_modules:
            print "Deleting '{}'".format(missing_module)
            ModuleInfo.get_collection().remove({'name': missing_module})

        # Disable all modules that have incomplete named configs
        for updated_named_config in unique_for_key(updated_named_configs,
                                                   'name'):
            if incomplete_config(updated_named_config['config']):
                for name, obj in self.walk_modules(modules_dir):
                    if obj.name and updated_named_config[
                            'name'] in obj.named_configs:
                        info = ModuleInfo.get(name=obj.name)

                        if info['enabled']:
                            print "Disabling {} for incomplete named config {}".format(
                                obj.name, updated_named_config['name'])
                            info.update_value('enabled', False)
Example #2
0
    def _validate_form(self, groups, module):
        for group in groups:
            if group in current_user['groups']:
                break
        else:
            flash('You have to at least share with one of your groups.', 'danger')
            return False

        if module:
            if not ModuleInfo.get(name=module):
                flash('"{}" is not a valid module'.format(module), 'danger')
                return False

        return True
    def next_preloading_module(self, selected_modules=[], excluded_modules=[]):
        candidate_module = None
        smallest_priority = None

        for module in self.get_preloading_modules():
            if ((not selected_modules
                 or module.info['name'] in selected_modules)
                    and module.info['name'] not in excluded_modules):
                module_info = ModuleInfo.get(name=module.info['name'])

                if smallest_priority is None or module_info[
                        'priority'] < smallest_priority:
                    candidate_module = module_info['name']
                    smallest_priority = module_info['priority']

        if candidate_module:
            return candidate_module
        else:
            raise DispatchingException("No more preloading module available")
Example #4
0
    def _validate_form(self, groups, modules, options):
        for group in groups:
            if group in current_user['groups']:
                break
        else:
            flash('You have to at least share with one of your groups.', 'danger')
            return False

        if modules:
            for module in modules:
                if not ModuleInfo.get(name=module):
                    flash('"{}" is not a valid module'.format(module), 'danger')
                    return False
        else:
            if not options['magic_enabled']:
                flash('You have to select at least one module to execute when magic is disabled', 'danger')
                return False

        return True
    def update(self, module, path, repository):
        named_configs = []

        if module.name:
            module_info = ModuleInfo.get(name=module.name)

            # Ignore duplicates
            if module_info and not module_info['path'].startswith(
                    'fame.modules.{}.'.format(repository['name'])):
                print "Duplicate name '{}', ignoring module.".format(
                    module.name)
                return None

            # Handle named configs
            for named_config in module.named_configs:
                config = Config.get(name=named_config)

                # Creation
                if config is None:
                    config = Config(module.named_config(named_config))
                    config.save()
                # Update
                else:
                    config.update_config(module.named_config(named_config))

                named_configs.append(config)

            # Handle module info
            if module_info is None:
                module_info = module.static_info()
                module_info['enabled'] = False
            else:
                module_info.update_config(module.static_info())

            module_info['class'] = module.__name__
            module_info['path'] = path
            module_info.save()

        return named_configs