Exemplo n.º 1
0
def create_version_from_metadata(
    channel_name: str,
    user_id: bytes,
    package_file_name: str,
    package_data: dict,
    dao: Dao,
):
    package_name = package_data["name"]
    package = dao.get_package(channel_name, package_name)
    if not package:
        package_info = rest_models.Package(
            name=package_name,
            summary=package_data.get("summary", ""),
            description=package_data.get("description", ""),
        )
        dao.create_package(channel_name, package_info, user_id, "owner")

    pkg_format = "tarbz2" if package_file_name.endswith(
        ".tar.bz2") else ".conda"
    version = dao.create_version(
        channel_name,
        package_name,
        pkg_format,
        get_subdir_compat(package_data),
        package_data["version"],
        int(package_data["build_number"]),
        package_data["build"],
        package_file_name,
        json.dumps(package_data),
        user_id,
        package_data["size"],
    )

    return version
Exemplo n.º 2
0
def post_package(new_package: rest_models.Package,
                 channel: db_models.Channel = Depends(get_channel_or_fail),
                 auth: authorization.Rules = Depends(get_rules),
                 dao: Dao = Depends(get_dao)):

    user_id = auth.assert_user()
    package = dao.get_package(channel.name, new_package.name)
    if package:
        raise HTTPException(
            status_code=status.HTTP_409_CONFLICT,
            detail=f'Package {channel.name}/{new_package.name} exists')

    dao.create_package(channel.name, new_package, user_id, authorization.OWNER)
Exemplo n.º 3
0
def create_packages_from_channeldata(channel_name: str, user_id: bytes,
                                     channeldata: dict, dao: Dao):
    packages = channeldata.get("packages", {})

    for package_name, metadata in packages.items():
        description = metadata.get("description", "")
        summary = metadata.get("summary", "")
        package_data = rest_models.Package(
            name=package_name,
            summary=summary,
            description=description,
        )

        try:
            package = dao.create_package(channel_name,
                                         package_data,
                                         user_id,
                                         role=authorization.OWNER)
        except DBError:
            # package already exists so skip it so we retrieve and update it
            package = dao.get_package(channel_name, package_name)
            package.description = description
            package.summary = summary
        package.url = metadata.get("home", "")
        package.platforms = ":".join(metadata.get("subdirs", []))
        package.channeldata = json.dumps(metadata)
        dao.db.commit()
Exemplo n.º 4
0
def package_version(db, user, channel_name, package_name, dao: Dao):
    channel_data = Channel(name=channel_name, private=False)
    package_data = Package(name=package_name)

    channel = dao.create_channel(channel_data, user.id, "owner")
    package = dao.create_package(channel_name, package_data, user.id, "owner")
    package_format = "tarbz2"
    package_info = "{}"
    version = dao.create_version(
        channel_name,
        package_name,
        package_format,
        "linux-64",
        "0.1",
        0,
        "",
        "",
        package_info,
        user.id,
    )

    yield version

    db.delete(version)
    db.delete(package)
    db.delete(channel)
    db.commit()
Exemplo n.º 5
0
def post_package(
        new_package: rest_models.Package,
        channel: db_models.Channel = Depends(
            ChannelChecker(allow_proxy=False, allow_mirror=False), ),
        auth: authorization.Rules = Depends(get_rules),
        dao: Dao = Depends(get_dao),
):

    user_id = auth.assert_user()
    auth.assert_create_package(channel.name)
    package = dao.get_package(channel.name, new_package.name)
    if package:
        raise HTTPException(
            status_code=status.HTTP_409_CONFLICT,
            detail=f"Package {channel.name}/{new_package.name} exists",
        )

    dao.create_package(channel.name, new_package, user_id, authorization.OWNER)
Exemplo n.º 6
0
def test_rollback_on_collision(dao: Dao, db, dao_extra, user_with_channel):
    """testing rollback on concurrent writes."""

    new_package = rest_models.Package(name=f"new-package-{uuid.uuid4()}")

    user_id = user_with_channel
    channel_name = "new-test-channel"

    dao.create_package(channel_name, new_package, user_id, "owner")
    with pytest.raises(errors.DBError,
                       match="(IntegrityError)|(UniqueViolation)"):
        dao_extra.create_package(channel_name, new_package, user_id, "owner")

    requested = db.query(Package).filter(
        Package.name == new_package.name).one_or_none()

    assert requested

    # need to clean up because we didn't run the test in a transaction

    db.delete(requested)
    db.commit()
Exemplo n.º 7
0
def test_package_version(db, dao: Dao, user, channel_name, package_name):
    channel_data = Channel(name=channel_name, private=False)
    package_data = Package(name=package_name)

    dao.create_channel(channel_data, user.id, "owner")
    package = dao.create_package(channel_name, package_data, user.id, "owner")
    package_format = "tarbz2"
    package_info = "{}"

    versions = [
        ("0.1.0", 0),
        ("1.0.0", 0),
        ("0.0.1", 0),
        ("0.0.2", 0),
        ("0.0.3", 0),
        ("1.0.0", 1),
        ("1.0.0", 2),
        ("0.1.0", 5),
        ("0.1.0", 2),
    ]
    for ver, build_str in versions:
        dao.create_version(
            channel_name,
            package_name,
            package_format,
            "linux-64",
            ver,
            build_str,
            "",
            f"{package_name}-{ver}-{build_str}.tar.bz2",
            package_info,
            user.id,
            size=0,
        )
    res = dao.get_package_versions(package)
    res_versions = [(VersionOrder(x[0].version), x[0].build_number)
                    for x in res]

    assert sorted(res_versions, reverse=True) == res_versions