Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6a9dfb8
Add support for filename, content-type and headers when uploading files
filbranden Sep 6, 2024
9bc5183
Add support for working with Aptly Mirrors API
xaoc7 Nov 23, 2022
b8c2d7f
Add support for making snapshots from mirrors
xaoc7 Nov 23, 2022
921c52a
Adding unit-tests to cover mirrors API functionality:
xaoc7 Nov 24, 2022
5e2e2b0
Fixed code style according flake8:
xaoc7 Dec 2, 2022
26898dd
Apply changes to mitigate mypy reported errors:
xaoc7 Dec 6, 2022
747dc4b
Fixed code style
xaoc7 Jan 10, 2023
54a42c0
fix code formatting
jdelic Aug 13, 2024
d0ec838
More formatting alignment
jdelic Aug 17, 2024
38f170c
typo fixes
jdelic Aug 17, 2024
bf52785
typo fixes
jdelic Aug 17, 2024
8df58ba
Corrected error in mirror.create filter_with_deps
Jul 29, 2024
0456a45
Fixed description argument for create_from_mirror
Jul 30, 2024
ff39a55
keep lines to max 120 chars
jdelic Sep 16, 2024
2ff1052
remove superfluous space
jdelic Sep 16, 2024
6456b9e
Bump pytest from 8.3.2 to 8.3.3
dependabot[bot] Sep 10, 2024
879970e
Bump doc8 from 1.1.1 to 1.1.2
dependabot[bot] Sep 2, 2024
be86305
Bump mypy from 1.11.1 to 1.11.2
dependabot[bot] Sep 16, 2024
de656e5
bump setup-python action version
jdelic Sep 16, 2024
569bb1b
Bump mypy from 1.11.2 to 1.12.0
dependabot[bot] Oct 14, 2024
b80ec43
Bump coverage from 7.6.1 to 7.6.3
dependabot[bot] Oct 14, 2024
85e9208
Bump coverage from 7.6.3 to 7.6.7
dependabot[bot] Nov 15, 2024
4e4e156
Bump pytest-cov from 5.0.0 to 6.0.0
dependabot[bot] Oct 30, 2024
ef6ef14
Bump mypy from 1.12.0 to 1.13.0
dependabot[bot] Oct 23, 2024
d2d9ddc
bump version for release
jdelic Nov 23, 2024
2957c26
Bump flake8 from 7.1.1 to 7.1.2
dependabot[bot] Feb 17, 2025
7fd5b6c
Bump coverage from 7.6.7 to 7.6.12
dependabot[bot] Feb 11, 2025
a1503a4
Bump mypy from 1.13.0 to 1.15.0
dependabot[bot] Feb 5, 2025
8908cde
Bump pygments from 2.18.0 to 2.19.1
dependabot[bot] Jul 29, 2025
0b950f8
Bump pytest from 8.3.3 to 8.3.4
dependabot[bot] Jul 29, 2025
78533ca
add Python 3.13 target and manual dispatching
jdelic Jul 29, 2025
c5e4f2d
Bump flake8 from 7.1.2 to 7.3.0
dependabot[bot] Jul 29, 2025
656bd5c
Bump coverage from 7.6.12 to 7.10.1
dependabot[bot] Jul 29, 2025
aff06a9
Bump pytest-cov from 6.0.0 to 6.2.1
dependabot[bot] Jul 29, 2025
004cbf9
Bump mypy from 1.15.0 to 1.17.0
dependabot[bot] Jul 29, 2025
5d8f822
coveralls still doesn't support Python 3.13
jdelic Jul 29, 2025
edcee22
Add support for filename, content-type and headers when uploading files
filbranden Sep 6, 2024
b5256b5
Merge branch 'feature/pr129' of ssh://github.com/gopythongo/aptly-api…
jdelic Jul 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions aptly_api/parts/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
from typing import Sequence, List, Tuple, BinaryIO, cast, Optional # noqa: F401
from typing import Sequence, List, Tuple, TextIO, BinaryIO, cast, Optional, Union, Dict # noqa: F401

from aptly_api.base import BaseAPIClient, AptlyAPIException

_tuplefiletype = Union[
Tuple[str, Union[TextIO, BinaryIO, str, bytes]],
Tuple[str, Union[TextIO, BinaryIO, str, bytes], str],
Tuple[str, Union[TextIO, BinaryIO, str, bytes], str, Dict[str, str]]
]


class FilesAPISection(BaseAPIClient):
def list(self, directory: Optional[str] = None) -> Sequence[str]:
Expand All @@ -18,13 +24,16 @@ def list(self, directory: Optional[str] = None) -> Sequence[str]:

return cast(List[str], resp.json())

def upload(self, destination: str, *files: str) -> Sequence[str]:
to_upload = [] # type: List[Tuple[str, BinaryIO]]
def upload(self, destination: str, *files: Union[str, _tuplefiletype]) -> Sequence[str]:
to_upload = [] # type: List[Tuple[str, Union[BinaryIO, _tuplefiletype]]]
for f in files:
if not os.path.exists(f) or not os.access(f, os.R_OK):
if isinstance(f, tuple):
to_upload.append((f[0], f),)
elif not os.path.exists(f) or not os.access(f, os.R_OK):
raise AptlyAPIException("File to upload %s can't be opened or read" % f)
fh = open(f, mode="rb")
to_upload.append((f, fh),)
else:
fh = open(f, mode="rb")
to_upload.append((f, fh),)

try:
resp = self.do_post("api/files/%s" % destination,
Expand All @@ -33,7 +42,7 @@ def upload(self, destination: str, *files: str) -> Sequence[str]:
raise
finally:
for fn, to_close in to_upload:
if not to_close.closed:
if not isinstance(to_close, tuple) and not to_close.closed:
to_close.close()

return cast(List[str], resp.json())
Expand Down
8 changes: 8 additions & 0 deletions aptly_api/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_upload_failed(self, *, rmock: requests_mock.Mocker) -> None:
with self.assertRaises(AptlyAPIException):
self.fapi.upload("test", os.path.join(os.path.dirname(__file__), "testpkg.deb"))

def test_upload_with_tuples(self, *, rmock: requests_mock.Mocker) -> None:
rmock.post("http://test/api/files/test", text='["test/otherpkg.deb", "test/binpkg.deb"]')
with open(os.path.join(os.path.dirname(__file__), "testpkg.deb"), "rb") as pkgf:
self.assertSequenceEqual(
self.fapi.upload("test", ("otherpkg.deb", pkgf), ("binpkg.deb", b"dpkg-contents")),
['test/otherpkg.deb', 'test/binpkg.deb'],
)

def test_delete(self, *, rmock: requests_mock.Mocker) -> None:
rmock.delete("http://test/api/files/test",
text='{}')
Expand Down