How to use the instawow.models.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 / tests / test_resolvers.py View on Github external
async def test_resolve_curse_simple_pkgs(manager, request, strategy):
    results = await manager.resolve(
        [
            Defn('curse', 'tomcats', strategy),
            Defn('curse', 'mythic-dungeon-tools', strategy),
            Defn('curse', 'classiccastbars', strategy),
            Defn('curse', 'elkbuffbars', strategy),
        ]
    )
    separate, retail_only, classic_only, flavour_explosion = results.values()

    assert isinstance(separate, Pkg)
    if manager.config.is_classic:
        if strategy is Strategies.any_flavour:
            assert 'classic' not in separate.version
            assert isinstance(retail_only, Pkg)
        else:
            assert 'classic' in separate.version
            assert (
                isinstance(retail_only, E.PkgFileUnavailable)
                and retail_only.message
                == f"no files compatible with classic using '{strategy.name}' strategy"
            )
        assert isinstance(classic_only, Pkg)
    else:
        assert 'classic' not in separate.version
        assert isinstance(retail_only, Pkg)
        if strategy is Strategies.any_flavour:
github layday / instawow / tests / test_resolvers.py View on Github external
async def test_resolve_wowi_pkgs(manager):
    results = await manager.resolve(
        [Defn('wowi', '13188-molinari'), Defn('wowi', '13188', Strategies.latest)]
    )
    either, invalid = results.values()

    assert isinstance(either, Pkg)
    assert (
        isinstance(invalid, E.PkgStrategyUnsupported)
        and invalid.message == "'latest' strategy is not valid for source"
    )
github layday / instawow / instawow / resolvers.py View on Github external
try:
            id_, slug = next(p for p in self._addons if defn.name in p)
        except StopIteration:
            raise E.PkgNonexistent

        from .wa_updater import BuilderConfig, WaCompanionBuilder

        sentinel = '__sentinel__'
        builder = WaCompanionBuilder(self.manager, BuilderConfig(account=sentinel))
        if id_ == '1':
            if builder.builder_config.account == sentinel:
                raise E.PkgFileUnavailable('account name not provided')
            await builder.build()

        checksum = await t(builder.checksum)()
        return m.Pkg(
            source=self.source,
            id=id_,
            slug=slug,
            name='WeakAuras Companion',
            description='A WeakAuras Companion clone.',
            url='https://github.com/layday/instawow',
            download_url=builder.addon_file.as_uri(),
            date_published=datetime.now(),
            version=checksum[:7],
            options=m.PkgOptions(strategy=defn.strategy.name),
        )
github layday / instawow / instawow / models.py View on Github external
_id = Column(Integer, primary_key=True)
    id = Column(String, nullable=False)
    pkg_source = Column(String, nullable=False)
    pkg_id = Column(String, nullable=False)


class PkgVersionLog(_BaseTable):
    __tablename__ = 'pkg_version_log'

    version = Column(String, nullable=False, primary_key=True)
    install_time = Column(DateTime, nullable=False, server_default=func.now())
    pkg_source = Column(String, nullable=False, primary_key=True)
    pkg_id = Column(String, nullable=False, primary_key=True)


class _PkgModelAmalgam(Pkg.Coercer):
    folders: List[PkgFolder.Coercer]
    options: PkgOptions.Coercer
    deps: List[PkgDep.Coercer]


class MultiPkgModel(pydantic.BaseModel):
    __root__: List[_PkgModelAmalgam]


def should_migrate(engine: Any, version: str) -> bool:
    """Check if the database version is the same as `version`;
    if not a migration would be required.
    """
    with engine.begin() as conn:
        try:
            current = conn.execute(
github layday / instawow / instawow / api.py View on Github external
async def get() -> list:
            if self.params.uris:
                return [manager.get(*split_uri(manager, u)) for u in self.params.uris]
            else:
                return manager.db.query(Pkg).all()
github layday / instawow / instawow / resolvers.py View on Github external
    async def resolve_one(self, defn: Defn, metadata: Any = None) -> m.Pkg:
        name = ui_name = self.retail_uis.get(defn.name)
        if not name:
            name = ''.join(takewhile('-'.__ne__, defn.name))

        if self.config.is_classic:
            query = 'classic-addon'
        elif ui_name:
            query = 'ui'
        else:
            query = 'addon'

        url = self.api_url.with_query({query: name})
        async with self.web_client.get(url) as response:
            if not response.content_length:
                raise E.PkgNonexistent
            addon = await response.json(content_type=None)  # text/html
github layday / instawow / instawow / resolvers.py View on Github external
)
        except ValueError:
            raise E.PkgFileUnavailable(
                f'no files compatible with {self.config.game_flavour} '
                f'using {defn.strategy.name!r} strategy'
            )

        # 1 = embedded library
        # 2 = optional dependency
        # 3 = required dependency
        # 4 = tool
        # 5 = incompatible
        # 6 = include (wat)
        deps = [m.PkgDep(id=d['addonId']) for d in file['dependencies'] if d['type'] == 3]

        return m.Pkg(
            source=self.source,
            id=metadata['id'],
            slug=metadata['slug'],
            name=metadata['name'],
            description=metadata['summary'],
            url=metadata['websiteUrl'],
            download_url=file['downloadUrl'],
            date_published=file['fileDate'],
            version=file['displayName'],
            options=m.PkgOptions(strategy=defn.strategy.name),
            deps=deps,
        )
github layday / instawow / instawow / manager.py View on Github external
def get_pkg(self, defn: Defn) -> O[Pkg]:
        "Retrieve an installed package from a definition."
        return (
            self.db_session.query(Pkg)
            .filter(Pkg.source == defn.source, (Pkg.id == defn.name) | (Pkg.slug == defn.name))
            .first()
github layday / instawow / instawow / manager.py View on Github external
def get_pkg_from_substr(self, defn: Defn) -> O[Pkg]:
        "Retrieve an installed package from a partial slug."
        return self.get_pkg(defn) or (
            self.db_session.query(Pkg)
            .filter(Pkg.slug.contains(defn.name))
            .order_by(Pkg.name)
            .first()
github layday / instawow / instawow / api.py View on Github external
error: Error

    @classmethod
    def from_api_error(cls, api_error: ApiError) -> ErrorResponse:
        return cls(id=api_error.request_id, error=Error(code=api_error.error_code,
                                                        message=api_error.message,
                                                        data=api_error.data))


class _PkgConverter(PkgCoercer):

    folders: List[PkgFolderCoercer]
    options: PkgOptionsCoercer


_CONVERTERS = [(Pkg, lambda v: _PkgConverter.from_orm(v).dict()),
               (Message, Message.dict),
               (Path, str),
               (datetime, datetime.isoformat),]


class Encoder(JSONEncoder):

    def default(self, value: Any) -> Any:
        try:
            return next(c(value) for t, c in _CONVERTERS if isinstance(value, t))
        except StopIteration:
            return super().default(value)


jsonify = Encoder().encode