Exemple #1
0
def delete_package_version(
        platform: str,
        filename: str,
        channel_name: str,
        package_name: str,
        dao: Dao = Depends(get_dao),
        db=Depends(get_db),
        auth: authorization.Rules = Depends(get_rules),
):

    version = dao.get_package_version_by_filename(channel_name, package_name,
                                                  filename, platform)

    auth.assert_package_delete(version.package)

    if not version:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"package version {platform}/{filename} not found",
        )

    db.delete(version)
    db.commit()

    path = os.path.join(platform, filename)
    pkgstore.delete_file(channel_name, path)

    dao.update_channel_size(channel_name)
Exemple #2
0
def get_package_version(
        platform: str,
        filename: str,
        package_name: str,
        channel_name: str,
        package: db_models.Package = Depends(get_package_or_fail),
        dao: Dao = Depends(get_dao),
):
    version = dao.get_package_version_by_filename(channel_name, package_name,
                                                  filename, platform)

    if not version:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"package version {platform}/{filename} not found",
        )

    return version
Exemple #3
0
def get_package_version_metrics(
        platform: str,
        filename: str,
        package_name: str,
        channel_name: str,
        fill_zeros: bool = False,
        period: IntervalType = IntervalType.day,
        metric_name: str = "download",
        start: Optional[datetime] = None,
        end: Optional[datetime] = None,
        package: db_models.Package = Depends(get_package_or_fail),
        dao: Dao = Depends(get_dao),
):
    version = dao.get_package_version_by_filename(channel_name, package_name,
                                                  filename, platform)

    if not version:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"package version {platform}/{filename} not found",
        )

    series = dao.get_package_version_metrics(version.id,
                                             period,
                                             metric_name,
                                             start=start,
                                             end=end,
                                             fill_zeros=fill_zeros)

    total = sum(s.count for s in series)

    return {
        "server_timestamp": datetime.utcnow(),
        "period": period,
        "metric_name": metric_name,
        "total": total,
        "series": series,
    }