Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit 7ac95f6

Browse files
#61: Delete files in bucket (#62)
* Added delete method * Added test for delete method * Added small fixes to list_files guides * Added user guide for deletion * Added mock delete method to mock bucketfs * Update doc/user_guide/delete_file_in_bucket.rst Co-authored-by: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> * Updated delete test * Prepared for the release Co-authored-by: Thomas Ubensee <34603111+tomuben@users.noreply.github.com>
1 parent 78cfab1 commit 7ac95f6

File tree

12 files changed

+189
-43
lines changed

12 files changed

+189
-43
lines changed

doc/changes/changes_0.2.0.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# BucketFs Utils Python 0.2.0, released t.b.d
2-
Code name: t.b.d
1+
# BucketFs Utils Python 0.2.0, released 2022-04-29
2+
Code name: Added methods to list files and delete files
33

44
## Summary
5-
t.b.d
5+
This version introduces two new methods that list files in a certain buckets and
6+
delete file in bucket under a specific path. Furthermore, we used a fixed numpy
7+
version build from source against the buffer overflow vulnerability in numpy.
68

79
## Features / Enhancements
810

911
- #55: Added method to list files in bucket
12+
- #61: Added method to delete file in bucket
1013

1114
## Bug Fixes
1215

1316
- #54: Removed PosixPath conversion from alter session string
1417

15-
## Documentation
16-
1718
## Refactoring
1819

1920
- #58: Added Python type hints
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
from exasol_bucketfs_utils_python import upload, delete
3+
from exasol_bucketfs_utils_python.bucket_config import BucketConfig
4+
from exasol_bucketfs_utils_python.bucketfs_config import BucketFSConfig
5+
from exasol_bucketfs_utils_python.bucketfs_connection_config import BucketFSConnectionConfig
6+
7+
connection_config = BucketFSConnectionConfig(
8+
host="localhost", port=6666,
9+
user="w", pwd="write",
10+
is_https=False)
11+
bucketfs_config = BucketFSConfig(
12+
connection_config=connection_config,
13+
bucketfs_name="bfsdefault")
14+
bucket_config = BucketConfig(
15+
bucket_name="default",
16+
bucketfs_config=bucketfs_config)
17+
18+
local_input_file_path = Path("local_input_file.txt")
19+
path_in_bucket = "path/in/bucket/file.txt"
20+
upload.upload_file_to_bucketfs(
21+
bucket_config=bucket_config,
22+
bucket_file_path=path_in_bucket,
23+
local_file_path=local_input_file_path)
24+
25+
delete.delete_file_in_bucketfs(
26+
bucket_config=bucket_config,
27+
bucket_file_path=path_in_bucket)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
#########################
3+
Deleting file in BucketFS
4+
#########################
5+
6+
This library provides a function to delete the file in a bucket under a given
7+
path. As in the example below, the file whose bucketfs path is given is deleted
8+
with the provided delete method.
9+
10+
11+
12+
Example:
13+
14+
.. literalinclude:: delete_file_in_bucket.py
15+
:language: python3

doc/user_guide/list_files_in_bucket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
bucket_file_path=path_in_bucket,
2323
local_file_path=local_input_file_path)
2424

25-
bucket_file_path = Path("path/in/bucket")
25+
bucket_file_path = "path/in/bucket"
2626
files = list_files.list_files_in_bucketfs(
2727
bucket_config=bucket_config,
28-
bucket_file_path=path_in_bucket)
28+
bucket_file_path=bucket_file_path)

doc/user_guide/list_files_in_bucket.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#####################################
3-
Listing files in bucket
3+
Listing files in BucketFS
44
#####################################
55

66
This library provides a function to list the files in the bucket under a given

doc/user_guide/user_guide.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ For a detailed explanation of the API, please refer to our :doc:`API Documentati
1111
upload_download_functions
1212
upload_github_release_to_bucket
1313
list_files_in_bucket
14+
delete_file_in_bucket
1415

exasol_bucketfs_utils_python/abstract_bucketfs_location.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,75 @@ class AbstractBucketFSLocation(ABC):
1111
directly, if called from inside a UDF.
1212
"""
1313
@abstractmethod
14-
def download_from_bucketfs_to_string(self,
15-
bucket_file_path: str) -> str:
14+
def download_from_bucketfs_to_string(
15+
self,
16+
bucket_file_path: str) -> str:
1617
pass
1718

1819
@abstractmethod
19-
def download_object_from_bucketfs_via_joblib(self,
20-
bucket_file_path: str) -> Any:
20+
def download_object_from_bucketfs_via_joblib(
21+
self,
22+
bucket_file_path: str) -> Any:
2123
pass
2224

2325
@abstractmethod
24-
def upload_string_to_bucketfs(self,
25-
bucket_file_path: str,
26-
string: str) -> \
27-
Tuple[ParseResult, PurePosixPath]:
26+
def upload_string_to_bucketfs(
27+
self,
28+
bucket_file_path: str,
29+
string: str) -> Tuple[ParseResult, PurePosixPath]:
2830
pass
2931

3032
@abstractmethod
31-
def upload_object_to_bucketfs_via_joblib(self,
32-
object: Any,
33-
bucket_file_path: str,
34-
**kwargs) -> \
35-
Tuple[ParseResult, PurePosixPath]:
33+
def upload_object_to_bucketfs_via_joblib(
34+
self,
35+
object: Any,
36+
bucket_file_path: str,
37+
**kwargs) -> Tuple[ParseResult, PurePosixPath]:
3638
pass
3739

3840
@abstractmethod
39-
def upload_fileobj_to_bucketfs(self,
40-
fileobj: IO,
41-
bucket_file_path: str) -> \
42-
Tuple[ParseResult, PurePosixPath]:
41+
def upload_fileobj_to_bucketfs(
42+
self,
43+
fileobj: IO,
44+
bucket_file_path: str) -> Tuple[ParseResult, PurePosixPath]:
4345
pass
4446

4547
# TODO add missing upload/download functions
4648

4749
@abstractmethod
48-
def read_file_from_bucketfs_to_string(self,
49-
bucket_file_path: str) -> str:
50+
def read_file_from_bucketfs_to_string(
51+
self,
52+
bucket_file_path: str) -> str:
5053
pass
5154

5255
@abstractmethod
53-
def read_file_from_bucketfs_to_file(self,
54-
bucket_file_path: str,
55-
local_file_path: Path) -> None:
56+
def read_file_from_bucketfs_to_file(
57+
self,
58+
bucket_file_path: str,
59+
local_file_path: Path) -> None:
5660
pass
5761

5862
@abstractmethod
59-
def read_file_from_bucketfs_to_fileobj(self,
60-
bucket_file_path: str,
61-
fileobj: IO) -> None:
63+
def read_file_from_bucketfs_to_fileobj(
64+
self,
65+
bucket_file_path: str,
66+
fileobj: IO) -> None:
6267
pass
6368

6469
@abstractmethod
65-
def read_file_from_bucketfs_via_joblib(self,
66-
bucket_file_path: str) -> Any:
70+
def read_file_from_bucketfs_via_joblib(
71+
self,
72+
bucket_file_path: str) -> Any:
6773
pass
6874

6975
@abstractmethod
70-
def list_files_in_bucketfs(self,
71-
bucket_file_path: str) -> Iterable[str]:
76+
def list_files_in_bucketfs(
77+
self,
78+
bucket_file_path: str) -> Iterable[str]:
79+
pass
80+
81+
@abstractmethod
82+
def delete_file_in_bucketfs(
83+
self,
84+
bucket_file_path: str) -> None:
7285
pass

exasol_bucketfs_utils_python/bucketfs_location.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Any, Tuple, IO
1+
from typing import Any, Tuple, IO, Iterable
22
from pathlib import PurePosixPath, Path
33
from urllib.parse import ParseResult
4-
from exasol_bucketfs_utils_python import download, upload, list_files
4+
from exasol_bucketfs_utils_python import download, upload, list_files, \
5+
delete
56
from exasol_bucketfs_utils_python import load_file_from_local_fs as from_BFS
67
from exasol_bucketfs_utils_python.bucket_config import BucketConfig
78

@@ -114,8 +115,16 @@ def read_file_from_bucketfs_via_joblib(
114115

115116
def list_files_in_bucketfs(
116117
self,
117-
bucket_file_path: str) -> list:
118+
bucket_file_path: str) -> Iterable[str]:
118119
return list_files.list_files_in_bucketfs(
119120
self.bucket_config,
120121
self.get_complete_file_path_in_bucket(bucket_file_path)
121122
)
123+
124+
def delete_file_in_bucketfs(
125+
self,
126+
bucket_file_path: str) -> None:
127+
delete.delete_file_in_bucketfs(
128+
self.bucket_config,
129+
self.get_complete_file_path_in_bucket(bucket_file_path)
130+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import requests
2+
from exasol_bucketfs_utils_python import bucketfs_utils
3+
from exasol_bucketfs_utils_python.bucketfs_utils import generate_bucket_http_url
4+
from exasol_bucketfs_utils_python.bucket_config import BucketConfig
5+
6+
7+
def delete_file_in_bucketfs(
8+
bucket_config: BucketConfig,
9+
bucket_file_path: str = "") -> None:
10+
"""
11+
Delete the file in bucket under a given path in BucketFS
12+
13+
:param bucket_config: BucketConfig for the bucket to delete from
14+
:param bucket_file_path: Path in the bucket to delete the file from
15+
"""
16+
if bucket_file_path is None:
17+
raise ValueError("bucket_file_path can't be None")
18+
19+
url = generate_bucket_http_url(bucket_config, bucket_file_path)
20+
auth = bucketfs_utils.create_auth_object(bucket_config)
21+
response = requests.delete(url.geturl(), auth=auth)
22+
response.raise_for_status()

exasol_bucketfs_utils_python/list_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
def list_files_in_bucketfs(bucket_config: BucketConfig,
1010
bucket_file_path: str = "") -> Iterable[str]:
1111
"""
12-
List files at the specified path in the bucket in BucketFs, line by line.
12+
List files at the specified path in the bucket in BucketFS, line by line.
1313
14-
:param bucket_config: BucketConfig for the bucket to download from
15-
:param bucket_file_path: Path in the bucket to download the file from
14+
:param bucket_config: BucketConfig for the bucket to list files in
15+
:param bucket_file_path: Path in the bucket to list the files in
1616
:return: The list of the files in the BucketFS as string.
1717
"""
1818
if bucket_file_path is None:

0 commit comments

Comments
 (0)