def generate_plugin_configuration(self): plugins_folder = os.path.join(self.output_folder, "plugins") if not os.path.exists(plugins_folder): os.makedirs(plugins_folder) # Loop through all the available spigot resources and their data # To see if they're desired to be configured! for plugin, data in self.spigot_resources.items(): configure = data['configure'] values = data['configure-options'] kwargs = data['kwargs'] script = data['script'] template = data['template'] defaults = data['defaults'] data_folder = data['plugin-folder'] if not configure: continue if data_folder is not None: kwargs['plugin_folder'] = data_folder if script is not None: print("Script for %s is %s" % (data['name'], script)) if is_url(script): script = save_plugin_config_script(self.scripts_folder, script) else: script = os.path.expanduser(data['script']) resource = data['resource'] if configure_plugin(resource, data['version'], plugins_folder, config_options=values, script=script, script_folder=self.scripts_folder, **kwargs): print("Configuration for %s has been generated!" % data['name']) else: print("Failed to create configuration for %s." % data['name']) for plugin, data in self.bukkit_resources.items(): configure = data['configure'] values = data['configure-options'] script = data['script'] kwargs = data['kwargs'] data_folder = data['plugin-folder'] if data_folder is not None: kwargs['plugin_folder'] = data_folder if not configure: continue if script is not None: if is_url(script): script = save_plugin_config_script(self.scripts_folder, script) else: script = os.path.expanduser(data['script']) print("Script is %s" % script) resource = data['resource'] if configure_plugin(resource, data['version'], plugins_folder, config_options=values, script=script, script_folder=self.scripts_folder, **kwargs): print("Configuration for %s has been created to your likings!" % data['name']) else: print("Failed to create configuration for %s." % data['name'])
def configure_plugin(resource, version, parent_folder, defaults_file=None, template_file=None, config_options=None, script=None, script_folder=None, **kwargs): resource_name = resource.plugin_name if isinstance(resource, BukkitResource) else resource.name # First check if we're supposed to be configuring with a script. if script is not None: # If they've passed a file to use specifically, then we're going to use that to configure the plugins. if os.path.isfile(script) and os.path.exists(script): configuration_script = __load_configuring_script(script, resource, version) else: # Otherwise Scan the scripts directory for the configuration script to handle the specified plugin. configuration_script = __get_configuring_script(script_folder, resource, version) if configuration_script is None: print("Unable to locate script for %s" % resource_name) return False else: print("Found script for %s" % resource_name) configure_method = getattr(configuration_script, 'configure') if configure_method is None: raise AttributeError("Unable to find 'configure' method in configuration script") configure_method(parent_folder, config_options=config_options, **kwargs) return True if defaults_file is None or template_file is None: print("Unable to configure %s without a script, or templates & default folder" % resource_name) return False plugin_folder = os.path.expanduser(os.path.join(parent_folder, kwargs.get('plugin_folder', resource_name))) if not os.path.exists(plugin_folder): os.makedirs(plugin_folder) # Get the default configuration values for Commons, incase some aren't present in the options. try: if is_url(defaults_file): defaults = get_configuration_defaults(url=defaults_file) else: if not os.path.exists(defaults_file): print("Unable to locate default variables file for %s %s" % (resource_name, defaults_file)) return False defaults = get_configuration_defaults(file=defaults_file) except: print("Unable to locate default variables file for %s %s" % (resource_name, defaults_file)) return False # Create a full dictionary of all the options required to render the template, merging # in the missing values from the default config. options = merge_configuration_options(config_options, defaults) # todo implement config file name in options. config_file = os.path.join(plugin_folder, 'config.yml') # Render the configuration of the url, with the options (and defaults included) if is_url(template_file): plugin_config = render_config_from_url(template_file, options) else: if not os.path.exists(template_file): print("Unable to locate template file for %s %s" % (resource_name, defaults_file)) return False plugin_config = render_config_from_string(get_config_from_file(template_file), options) # Lastly write the configuration to the file specified! write_file(config_file, plugin_config) print("Configuration for {plugin} ({version}) has been rendered!".format(resource_name, version)) return True