How to use the instawow.resolvers.Defn.from_pkg function in instawow

To help you get started, we’ve selected a few instawow 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 layday / instawow / instawow / cli.py View on Github external
)
        ).generate_and_exit()

    versions: List[models.PkgVersionLog] = (
        manager.db_session.query(models.PkgVersionLog)
        .filter(
            models.PkgVersionLog.pkg_source == pkg.source, models.PkgVersionLog.pkg_id == pkg.id
        )
        .order_by(models.PkgVersionLog.install_time.desc())
        .limit(limit)
        .all()
    )
    if len(versions) <= 1:
        Report([(addon, E.PkgFileUnavailable('cannot find older versions'))]).generate_and_exit()

    reconstructed_defn = Defn.from_pkg(pkg)
    choices = [
        Choice(
            [('', v.version)],  # type: ignore
            disabled='installed version' if v.version == pkg.version else None,
        )
        for v in versions
    ]
    selection = select(
        f'Select version of {reconstructed_defn} for rollback', choices
    ).unsafe_ask()
    Report(
        chain(
            manager.run(manager.remove([reconstructed_defn])).items(),
            manager.run(
                manager.install([reconstructed_defn.with_version(selection)], replace=False)
            ).items(),
github layday / instawow / instawow / cli.py View on Github external
def construct_choice(pkg: models.Pkg):
            defn = Defn.from_pkg(pkg)
            title = [
                ('', str(defn)),
                ('', '=='),
                ('class:highlight-sub' if highlight_version else '', pkg.version),
            ]
            return PkgChoice(title, defn, pkg=pkg)
github layday / instawow / instawow / cli.py View on Github external
def prompt(groups: Sequence[Tuple[List[AddonFolder], List[Defn]]]) -> Iterable[Defn]:
        uniq_defns = uniq(d for _, b in groups for d in b)
        results = manager.run(manager.resolve(uniq_defns))
        for addons, defns in groups:
            shortlist = list(filter(is_pkg, (results[d] for d in defns)))
            if shortlist:
                if auto:
                    selection = Defn.from_pkg(shortlist[0])
                else:
                    selection = prompt_one(addons, shortlist)
                selection and (yield selection)
github layday / instawow / instawow / cli.py View on Github external
with formatter.section(Defn.from_pkg(pkg)):
                formatter.write_dl(
                    (
                        ('Name', pkg.name),
                        ('Description', get_desc_from_toc(pkg)),
                        ('URL', pkg.url),
                        ('Version', pkg.version),
                        ('Date published', pkg.date_published.isoformat(' ', 'minutes')),
                        ('Folders', ', '.join(f.name for f in pkg.folders)),
                        ('Dependencies', ', '.join(format_deps(pkg))),
                        ('Options', f'{{"strategy": "{pkg.options.strategy}"}}'),
                    )
                )
        click.echo(formatter.getvalue(), nl=False)
    else:
        click.echo(''.join(f'{Defn.from_pkg(p)}\n' for p in pkgs), nl=False)
github layday / instawow / instawow / exceptions.py View on Github external
def __init__(self, conflicts: Sequence[Pkg]) -> None:
        from .resolvers import Defn

        super().__init__()
        self.conflicts = [Defn.from_pkg(c) for c in conflicts]
github layday / instawow / instawow / manager.py View on Github external
async def update(self, defns: Sequence[Defn]) -> Dict[Defn, E.ManagerResult]:
        # Rebuild ``Defn`` with ID and strategy from package for defns
        # of installed packages.  Using the ID has the benefit of resolving
        # installed-but-renamed packages - the slug is transient; the ID isn't
        maybe_pkgs = ((d, self.get_pkg(d)) for d in defns)
        checked_defns = {Defn.from_pkg(p) if p else c: p for c, p in maybe_pkgs}
        # Results can contain errors
        # installables are those results which are packages
        # and updatables are packages with updates
        results = await self.resolve([d for d, p in checked_defns.items() if p])
        installables = {d: r for d, r in results.items() if is_pkg(r)}
        updatables = {
            (d, checked_defns[d], p): download_archive(self, p)
            for d, p in installables.items()
            if p.version != cast(Pkg, checked_defns[d]).version
        }
        archives = await gather(updatables.values())

        coros = dict_chain(
            checked_defns,
            partial(_error_out, E.PkgNotInstalled()),
            ((d, partial(_error_out, r)) for d, r in results.items()),