How to use the bcml.util.BcmlMod function in bcml

To help you get started, we’ve selected a few bcml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NiceneNerd / BCML / bcml / install.py View on Github external
all_mergers = [merger() for merger in mergers.get_mergers()]
    remergers = set()
    partials = {}
    for merger in all_mergers:
        if merger.is_mod_logged(mod):
            remergers.add(merger)
            if merger.can_partial_remerge():
                partials[merger.NAME] = set(merger.get_mod_affected(mod))

    print('Resorting other affected mods...')
    for mod in mods:
        if mod.priority != (mods.index(mod) + 100):
            adjusted_priority = mods.index(mod) + 100
            mods.remove(mod)
            mods.insert(adjusted_priority - 100,
                        BcmlMod(mod.name, adjusted_priority, mod.path))
            if verbose:
                print(
                    f'Changing priority of {mod.name} from'
                    f'{mod.priority} to {adjusted_priority}...'
                )
    for mod in mods:
        if not mod.path.stem.startswith(f'{mod.priority:04}'):
            for merger in all_mergers:
                if merger.is_mod_logged(mod):
                    remergers.add(merger)
                    if merger.can_partial_remerge():
                        if merger.NAME not in partials:
                            partials[merger.NAME] = set()
                        partials[merger.NAME] |= set(merger.get_mod_affected(mod))

            new_mod_id = util.get_mod_id(mod[0], mod[1])
github NiceneNerd / BCML / bcml / install.py View on Github external
def uninstall_mod(mod: Union[Path, BcmlMod, str], wait_merge: bool = False, verbose: bool = False):
    """
    Uninstalls the mod currently installed at the specified path and updates merges as needed

    :param mod: The mod to remove, as a path or a BcmlMod.
    :param wait_merge: Resort mods but don't remerge anything yet, defaults to False.
    :type wait_merge: bool, optional
    :param verbose: Whether to display more detailed output, defaults to False.
    :type verbose: bool, optional
    """
    path = Path(mod) if isinstance(mod, str) else mod.path if isinstance(mod, BcmlMod) else mod
    mod_name, mod_priority, _ = util.get_mod_info(path / 'rules.txt') \
                                if not isinstance(mod, BcmlMod) else mod
    print(f'Uninstalling {mod_name}...')
    remergers = set()
    partials = {}
    for merger in [merger() for merger in mergers.get_mergers()]:
        if merger.is_mod_logged(BcmlMod(mod_name, mod_priority, path)):
            remergers.add(merger)
            if merger.can_partial_remerge():
                partials[merger.NAME] = merger.get_mod_affected(mod)

    shutil.rmtree(str(path))
    next_mod = util.get_mod_by_priority(mod_priority + 1)
    if next_mod:
        print('Adjusting mod priorities...')
        change_mod_priority(next_mod, mod_priority,
                            wait_merge=True, verbose=verbose)
        print()
github NiceneNerd / BCML / bcml / __init__.py View on Github external
def resort_mods(self):
            all_mergers = [merger() for merger in mergers.get_mergers()]
            remergers = set()
            partials = {}
            mods_to_change = []
            for i in range(self.listWidget.count()):
                mod = self.listWidget.item(i).data(QtCore.Qt.UserRole)
                target_priority = i + 100 if util.get_settings_bool(
                    'load_reverse') else 100 + ((self.listWidget.count() - 1) - i)
                if mod.priority != target_priority:
                    mods_to_change.append(BcmlMod(mod.name, target_priority, mod.path))
                    for merger in all_mergers:
                        if merger.is_mod_logged(mod):
                            remergers.add(merger)
                            if merger.can_partial_remerge():
                                if merger.NAME not in partials:
                                    partials[merger.NAME] = set()
                                partials[merger.NAME] |= set(merger.get_mod_affected(mod))
            for mod in sorted(mods_to_change, key=lambda m: m.priority, reverse=True):
                new_path = util.get_modpack_dir() / util.get_mod_id(mod.name, mod.priority)
                shutil.move(str(mod.path), str(new_path))
                rules_name = 'rules.txt'
                if not Path(str(new_path / rules_name)).exists():
                    rules_name = f'{rules_name}.disable'
                rules = util.RulesParser()
                rules.read(str(new_path / rules_name))
                rules['Definition']['fsPriority'] = str(mod.priority)
github NiceneNerd / BCML / bcml / rstable.py View on Github external
def perform_merge_2(self):
        print('Perfoming RSTB merge...')
        log_merged_files_rstb()
        master_diffs = [
            *self.get_all_diffs(),
            self.get_mod_diff(BcmlMod('Master BCML', 9999, util.get_master_modpack_dir()))
        ]
        diffs = self.consolidate_diffs(master_diffs)
        new_rstb = get_stock_rstb()
        counts = {
            'add': 0,
            'update': 0,
            'del': 0
        }
        for file, size in diffs.items():
            if size > 0:
                if new_rstb.is_in_table(file):
                    counts['update'] += 1
                else:
                    counts['add'] += 1
                new_rstb.set_size(file, size)
            else:
github NiceneNerd / BCML / bcml / install.py View on Github external
:type path: class:`pathlib.Path`
    :param new_priority: The new priority of the mod.
    :type new_priority: int
    :param wait_merge: Resort priorities but don't remerge anything yet, defaults to False.
    :type wait_merge: bool, optional
    :param verbose: Whether to display more detailed output, defaults to False.
    :type verbose: bool, optional
    """
    mod = util.get_mod_info(path / 'rules.txt')
    print(
        f'Changing priority of {mod.name} from {mod.priority} to {new_priority}...')
    mods = util.get_installed_mods()
    if new_priority > mods[len(mods) - 1][1]:
        new_priority = len(mods) - 1
    mods.remove(mod)
    mods.insert(new_priority - 100, util.BcmlMod(mod.name, new_priority, path))

    all_mergers = [merger() for merger in mergers.get_mergers()]
    remergers = set()
    partials = {}
    for merger in all_mergers:
        if merger.is_mod_logged(mod):
            remergers.add(merger)
            if merger.can_partial_remerge():
                partials[merger.NAME] = set(merger.get_mod_affected(mod))

    print('Resorting other affected mods...')
    for mod in mods:
        if mod.priority != (mods.index(mod) + 100):
            adjusted_priority = mods.index(mod) + 100
            mods.remove(mod)
            mods.insert(adjusted_priority - 100,
github NiceneNerd / BCML / bcml / texts.py View on Github external
def get_modded_languages(mod: Path) -> []:
    """ Gets all languages with modded texts for a given mod """
    if isinstance(mod, BcmlMod):
        mod = mod.path
    text_langs = []
    for text_lang in (mod / 'logs').glob('*text*'):
        lang = util.get_file_language(text_lang)
        if lang not in text_langs:
            text_langs.append(lang)
    return text_langs
github NiceneNerd / BCML / bcml / _api.py View on Github external
def get_mod_info(self, params):
        mod = BcmlMod.from_json(params["mod"])
        util.vprint(mod)
        img = ""
        try:
            img = base64.b64encode(mod.get_preview().read_bytes()).decode("utf8")
        except (KeyError, FileNotFoundError):
            pass
        return {
            "changes": [
                m.NAME.upper() for m in mergers.get_mergers() if m().is_mod_logged(mod)
            ],
            "desc": mod.description,
            "date": mod.date,
            "processed": (mod.path / ".processed").exists(),
            "image": img,
            "url": mod.url,
        }
github NiceneNerd / BCML / bcml / install.py View on Github external
shutil.rmtree(str(tmp_dir))
                    except Exception: # pylint: disable=broad-except
                        pass
                except Exception: # pylint: disable=broad-except
                    raise OSError('BCML could not transfer your mod from the temp directory '
                                       'to the BCML directory.')
        elif mod.is_dir():
            shutil.copytree(str(tmp_dir), str(mod_dir))

        rulepath = os.path.basename(rules['Definition']['path']).replace('"', '')
        rules['Definition']['path'] = f'{{BCML: DON\'T TOUCH}}/{rulepath}'
        rules['Definition']['fsPriority'] = str(priority)
        with Path(mod_dir / 'rules.txt').open('w', encoding='utf-8') as r_file:
            rules.write(r_file)

        output_mod = BcmlMod(mod_name, priority, mod_dir)
        try:
            util.get_mod_link_meta(rules)
            util.get_mod_preview(output_mod, rules)
        except Exception: # pylint: disable=broad-except
            pass

        print(f'Enabling {mod_name} in Cemu...')
        refresh_cemu_mods()
    except Exception: # pylint: disable=broad-except
        clean_error = RuntimeError()
        clean_error.error_text = (f'There was an error installing {mod_name}. '
                                  'It processed successfully, but could not be added to your BCML '
                                  'mods. This may indicate a problem with your BCML installation. '
                                  'Here is the error:\n\n'
                                  f'{traceback.format_exc(limit=-4)}\n\n'
                                  f'{mod_name} is being removed and no changes will be made.')
github NiceneNerd / BCML / bcml / install.py View on Github external
Uninstalls the mod currently installed at the specified path and updates merges as needed

    :param mod: The mod to remove, as a path or a BcmlMod.
    :param wait_merge: Resort mods but don't remerge anything yet, defaults to False.
    :type wait_merge: bool, optional
    :param verbose: Whether to display more detailed output, defaults to False.
    :type verbose: bool, optional
    """
    path = Path(mod) if isinstance(mod, str) else mod.path if isinstance(mod, BcmlMod) else mod
    mod_name, mod_priority, _ = util.get_mod_info(path / 'rules.txt') \
                                if not isinstance(mod, BcmlMod) else mod
    print(f'Uninstalling {mod_name}...')
    remergers = set()
    partials = {}
    for merger in [merger() for merger in mergers.get_mergers()]:
        if merger.is_mod_logged(BcmlMod(mod_name, mod_priority, path)):
            remergers.add(merger)
            if merger.can_partial_remerge():
                partials[merger.NAME] = merger.get_mod_affected(mod)

    shutil.rmtree(str(path))
    next_mod = util.get_mod_by_priority(mod_priority + 1)
    if next_mod:
        print('Adjusting mod priorities...')
        change_mod_priority(next_mod, mod_priority,
                            wait_merge=True, verbose=verbose)
        print()

    if not wait_merge:
        pool = Pool(cpu_count())
        for merger in mergers.sort_mergers(remergers):
            merger.set_pool(pool)