def test_resource_from_json():
    resource = SpigotResource.from_json(json=get_resource(15290))
    assert resource is not None
    assert resource.name == 'Commons'
    assert resource.resource_id == 15290
    assert resource.author_name == "MumbosHut"
    assert resource.external is False
def test_resource_by_name():
    resource = SpigotResource.from_name("Commons")
    assert resource is not None
    assert resource.name == 'Commons'
    assert resource.resource_id == 15290
    assert resource.author_name == "MumbosHut"
    assert resource.external is False
Example #3
0
def test_resource_from_json():
    resource = SpigotResource.from_json(json=get_resource(15290))
    assert resource is not None
    assert resource.name == 'Commons'
    assert resource.resource_id == 15290
    assert resource.author_name == "MumbosHut"
    assert resource.external is False
Example #4
0
def test_resource_by_name():
    resource = SpigotResource.from_name("Commons")
    assert resource is not None
    assert resource.name == 'Commons'
    assert resource.resource_id == 15290
    assert resource.author_name == "MumbosHut"
    assert resource.external is False
    def parse_config_file(self):
        config = yamlbro.load_yaml(self.requirements_file)

        if 'target-folder' in config.keys() and self.output_folder is None:
            print("Info: Files and Configuration will be stored in %s" % self.output_folder)
            self.output_folder = os.path.expanduser(config['target-folder'])

            if not os.path.exists(self.output_folder):
                os.makedirs(self.output_folder)

        if 'Bukkit' in config.keys():
            bukkit_data = config['Bukkit']

            for plugin_name in bukkit_data.keys():
                data = bukkit_data[plugin_name]
                version = data['version']
                configure_after_download = False
                configure_options = {}
                configure_script = None
                template_file = None
                defaults_file = None
                plugin_folder = None
                kwargs = {}

                if 'configure' in data.keys():
                    if 'options' in data['configure']:
                        configure_after_download = True
                        for option, value in data['configure']['options'].items():
                            configure_options[option] = value

                    if 'args' in data['configure'].keys():
                        for key, value in data['configure']['args'].items():
                            kwargs[key] = value

                    if 'script' in data['configure'].keys():
                        configure_script = data['configure']['script']
                        print("Script found: %s" % configure_script)

                    if 'template' in data['configure'].keys():
                        template_file = data['configure']['template']

                    if 'defaults' in data['configure'].keys():
                        defaults_file = data['configure']['defaults']

                    if 'plugin-data-folder' in data['configure'].keys():
                        plugin_folder = data['configure']['plugin-data-folder']

                    if (template_file is not None and defaults_file is None) or (
                                    defaults_file is not None and template_file is None):
                        template_file = None
                        defaults_file = None
                        configure_after_download = False

                        print(textwrap.dedent("""\n
                            +==================================================================+
                                    Configuration Error for {name} ({version})
                            +==================================================================+

                                Generating a plugins configuration file via template & default configuration
                                requires the 'template', 'plugin-data-folder', and 'defaults' node to be present, and valid
                                inside your requirements file ({configuration}).

                                Using one without the others nulls the functionality, as a template has placeholders
                                for your config data, and the defaults file fills in the blanks where you
                                have not specified values. Using either without a plugin data folder doesn't make sense,
                                as you'd want to keep the template and defaults once it's generated.

                                McResolver will continue to download these plugins, though configuration cannot happen
                                unless you provide a template, plugin data folder, and defaults file, or a script that
                                handles the configuration.

                            +==================================================================+
                            """).format(name=plugin_name, version=version, configuration=self.requirements_file))

                if isinstance(plugin_name, int) or plugin_name.isdigit():
                    print("Invalid Bukkit plugin '%s', plugin name or slug (in plugins url) is required")
                    continue

                try:
                    bukkit_resource = BukkitResource.from_name(plugin_name)
                except ValueError:
                    print("Unable to retrieve Bukkit plugin %s (v. %s)" % (plugin_name, version))

                if not bukkit_resource.has_version(version=version):
                    if not self.retrieve_latest_on_version_error:
                        print("Unable to retrieve version %s for %s" % (version, plugin_name))
                        continue
                    else:
                        self.bukkit_resources[plugin_name] = {
                            'version': 'latest',
                            'name': plugin_name,
                            'resource': bukkit_resource,
                            'configure': configure_after_download,
                            'script': configure_script,
                            'configure-options': configure_options,
                            'kwargs': kwargs,
                            'template': template_file,
                            'defaults': defaults_file,
                            'plugin-folder': plugin_folder,
                        }
                else:
                    self.bukkit_resources[plugin_name] = {
                        'version': version,
                        'name': plugin_name,
                        'resource': bukkit_resource,
                        'configure': configure_after_download,
                        'script': configure_script,
                        'configure-options': configure_options,
                        'kwargs': kwargs,
                        'template': template_file,
                        'defaults': defaults_file,
                        'plugin-folder': plugin_folder,

                    }

                print("Bukkit information retrieved on %s (v: %s)" % (
                    plugin_name, self.bukkit_resources[plugin_name]['version']))

        # Go ahead and collect all the Spigot resources in the yml file
        # and their desired versions (or latest)
        if 'Spigot' in config.keys():
            spigot_plugins = config['Spigot']
            for plugin_id in spigot_plugins.keys():
                data = spigot_plugins[plugin_id]
                spigot_resource = None
                version = data['version']
                name = data['name']
                configure_after_download = False
                configure_script = None
                configure_options = {}
                template_file = None
                defaults_file = None
                plugin_folder = None
                kwargs = {}
                if 'configure' in data.keys():
                    if 'options' in data['configure']:
                        configure_after_download = True
                        for option, value in data['configure']['options'].items():
                            configure_options[option] = value

                    if 'args' in data['configure'].keys():
                        for key, value in data['configure']['args'].items():
                            kwargs[key] = value

                    if 'script' in data['configure'].keys():
                        configure_script = data['configure']['script']

                    if 'template' in data['configure'].keys():
                        template_file = data['configure']['template']

                    if 'defaults' in data['configure'].keys():
                        defaults_file = data['configure']['defaults']

                    if 'plugin-data-folder' in data['configure'].keys():
                        plugin_folder = data['configure']['plugin-data-folder']

                    if (template_file is not None and defaults_file is None) or (
                                    defaults_file is not None and template_file is None):
                        template_file = None
                        defaults_file = None
                        configure_after_download = False
                        print(textwrap.dedent("""\n
                            +==================================================================+
                                    Configuration Error for {name} ({version})
                            +==================================================================+

                                Generating a plugins configuration file via template & default configuration
                                requires the 'template', 'plugin-data-folder', and 'defaults' node to be present, and valid
                                inside your requirements file ({configuration}).

                                Using one without the others nulls the functionality, as a template has placeholders
                                for your config data, and the defaults file fills in the blanks where you
                                have not specified values. Using either without a plugin data folder doesn't make sense,
                                as you'd want to keep the template and defaults once it's generated.

                                McResolver will continue to download these plugins, though configuration cannot happen
                                unless you provide a template, plugin data folder, and defaults file, or a script that
                                handles the configuration.

                            +==================================================================+
                            """).format(name=name, version=version, configuration=self.requirements_file))

                if isinstance(plugin_id, int) or plugin_id.isdigit():
                    spigot_resource = SpigotResource.from_id(plugin_id)
                else:
                    print(
                        "Unable to retrieve Spigot plugin (%s) via its name... Potential feature in the future!" % name)
                    continue

                if spigot_resource is None:
                    print("Invalid plugin %s (v: %s)" % (name, version))
                    continue

                if not spigot_resource.has_version(version=version):
                    if not self.retrieve_latest_on_version_error:
                        print("Unable to retrieve version %s for %s" % (version, name))
                        continue

                    self.spigot_resources[plugin_id] = {
                        'version': 'latest',
                        'name': name,
                        'resource': spigot_resource,
                        'configure': configure_after_download,
                        'script': configure_script,
                        'configure-options': configure_options,
                        'kwargs': kwargs,
                        'template': template_file,
                        'defaults': defaults_file,
                        'plugin-folder': plugin_folder,

                    }
                else:
                    self.spigot_resources[plugin_id] = {
                        'version': version,
                        'name': name,
                        'resource': spigot_resource,
                        'configure': configure_after_download,
                        'script': configure_script,
                        'configure-options': configure_options,
                        'kwargs': kwargs,
                        'template': template_file,
                        'defaults': defaults_file,
                        'plugin-folder': plugin_folder,
                    }

                if isinstance(plugin_id, int):
                    print("Spigot information retrieved on %s [id. %s] (v. %s)" % (name, plugin_id,
                                                                                   self.spigot_resources[plugin_id][
                                                                                       'version']))
def test_resource_external():
    resource = SpigotResource.from_id(15441)
    assert resource is not None
    assert resource.name == 'Craft Build Tools - Project Management Suite'
    assert resource.external is True
def test_invalid_resource():
    assert SpigotResource.from_name("_djfkjl4kj24242") is None
Example #8
0
def test_resource_external():
    resource = SpigotResource.from_id(15441)
    assert resource is not None
    assert resource.name == 'Craft Build Tools - Project Management Suite'
    assert resource.external is True
Example #9
0
def test_invalid_resource():
    assert SpigotResource.from_name("_djfkjl4kj24242") is None