PyS3Uploader 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyS3Uploader
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Python module to upload objects to an S3 bucket.
5
5
  Author-email: Vignesh Rao <svignesh1793@gmail.com>
6
6
  License: MIT License
@@ -63,7 +63,7 @@ Requires-Dist: recommonmark; extra == "dev"
63
63
 
64
64
  **Activity**
65
65
 
66
- [![GitHub Repo created](https://img.shields.io/date/1618966420)][repo]
66
+ [![GitHub Repo created](https://img.shields.io/date/1760313686)][repo]
67
67
  [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/thevickypedia/PyS3Uploader)][repo]
68
68
  [![GitHub last commit](https://img.shields.io/github/last-commit/thevickypedia/PyS3Uploader)][repo]
69
69
 
@@ -0,0 +1,11 @@
1
+ s3/__init__.py,sha256=qSltnC7r3AjwiYWzsD9JUs8SzeBEV16nrHldiWlrxtY,66
2
+ s3/exceptions.py,sha256=hH3jlMOe8yjBatQK9EdndWZz4QESU74KSY_iDhQ37SY,2585
3
+ s3/logger.py,sha256=oH540oq8jY723jA4lDWlgfFPLbNgGXTkDwFpB7TLO_o,1196
4
+ s3/tree.py,sha256=DiQ2ekMMaj2m_P3-iKkEqSuJCJZ_UZxcAwHtAoPVa5c,1824
5
+ s3/uploader.py,sha256=kkv7d2EaMH3OsoIJgTx7yRUd00s0n9PbRbjj6Rm7qdA,9355
6
+ s3/utils.py,sha256=0kcG0aE2olHhC8thaUEwx2J8tOI2-2TGCk6E6U-PiKw,2058
7
+ pys3uploader-0.1.2.dist-info/LICENSE,sha256=8k-hEraOzyum0GvmmK65YxNRTFXK7eIFHJ0OshJXeTk,1068
8
+ pys3uploader-0.1.2.dist-info/METADATA,sha256=GtQq-ZDiZEMpl2CEs4VJw4AQ8tf5rzcfgjDu68oHX6c,7286
9
+ pys3uploader-0.1.2.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
10
+ pys3uploader-0.1.2.dist-info/top_level.txt,sha256=iQp4y1P58Q633gj8M08kHE4mqqT0hixuDWcniDk_RJ4,3
11
+ pys3uploader-0.1.2.dist-info/RECORD,,
s3/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from s3.uploader import Uploader # noqa: F401
2
2
 
3
- version = "0.1.1"
3
+ version = "0.1.2"
s3/uploader.py CHANGED
@@ -11,7 +11,7 @@ from tqdm import tqdm
11
11
 
12
12
  from s3.exceptions import BucketNotFound
13
13
  from s3.logger import default_logger
14
- from s3.utils import UploadResults, getenv, urljoin
14
+ from s3.utils import UploadResults, convert_to_folder_structure, getenv, urljoin
15
15
 
16
16
 
17
17
  class Uploader:
@@ -136,7 +136,9 @@ class Uploader:
136
136
  for file_ in __files:
137
137
  file_path = os.path.join(__path, file_)
138
138
  if self.exclude_path:
139
- file_path = file_path.replace(self.exclude_path, "")
139
+ relative_path = file_path.replace(self.exclude_path, "")
140
+ else:
141
+ relative_path = file_path
140
142
  # Lists in python are ordered, so s3 prefix will get loaded first when provided
141
143
  url_parts = []
142
144
  if self.s3_prefix:
@@ -144,7 +146,7 @@ class Uploader:
144
146
  self.s3_prefix.split(os.sep) if os.sep in self.s3_prefix else self.s3_prefix.split("/")
145
147
  )
146
148
  # Add rest of the file path to parts before normalizing as an S3 object URL
147
- url_parts.extend(file_path.split(os.sep))
149
+ url_parts.extend(relative_path.split(os.sep))
148
150
  # Remove falsy values using filter - "None", "bool", "len" or "lambda item: item"
149
151
  object_path = urljoin(*filter(None, url_parts))
150
152
  files_to_upload[object_path] = file_path
@@ -200,3 +202,18 @@ class Uploader:
200
202
  self.logger.error(f"Upload failed: {error}")
201
203
  self.results.failed += 1
202
204
  self.exit()
205
+
206
+ def get_bucket_structure(self) -> str:
207
+ """Gets all the objects in an S3 bucket and forms it into a hierarchical folder like representation.
208
+
209
+ Returns:
210
+ str:
211
+ Returns a hierarchical folder like representation of the chosen bucket.
212
+ """
213
+ self.init()
214
+ # Using list and set will yield the same results but using set we can isolate directories from files
215
+ return convert_to_folder_structure(set([obj.key for obj in self.bucket.objects.all()]))
216
+
217
+ def print_bucket_structure(self) -> None:
218
+ """Prints all the objects in an S3 bucket with a folder like representation."""
219
+ print(self.get_bucket_structure())
s3/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import os
2
+ from typing import Dict, Set
2
3
 
3
4
 
4
5
  class UploadResults(dict):
@@ -28,3 +29,42 @@ def urljoin(*args) -> str:
28
29
  Joined url.
29
30
  """
30
31
  return "/".join(map(lambda x: str(x).rstrip("/").lstrip("/"), args))
32
+
33
+
34
+ def convert_to_folder_structure(sequence: Set[str]) -> str:
35
+ """Convert objects in a s3 buckets into a folder like representation.
36
+
37
+ Args:
38
+ sequence: Takes either a mutable or immutable sequence as an argument.
39
+
40
+ Returns:
41
+ str:
42
+ String representation of the architecture.
43
+ """
44
+ folder_structure = {}
45
+ for item in sequence:
46
+ parts = item.split("/")
47
+ current_level = folder_structure
48
+ for part in parts:
49
+ current_level = current_level.setdefault(part, {})
50
+
51
+ def generate_folder_structure(structure: Dict[str, dict], indent: str = "") -> str:
52
+ """Generates the folder like structure.
53
+
54
+ Args:
55
+ structure: Structure of folder objects as key-value pairs.
56
+ indent: Required indentation for the ASCII.
57
+ """
58
+ result = ""
59
+ for i, (key, value) in enumerate(structure.items()):
60
+ if i == len(structure) - 1:
61
+ result += indent + "└── " + key + "\n"
62
+ sub_indent = indent + " "
63
+ else:
64
+ result += indent + "├── " + key + "\n"
65
+ sub_indent = indent + "│ "
66
+ if value:
67
+ result += generate_folder_structure(value, sub_indent)
68
+ return result
69
+
70
+ return generate_folder_structure(folder_structure)
@@ -1,11 +0,0 @@
1
- s3/__init__.py,sha256=XgYHKbn7gc5_nzydIKmKVjigeMtOBLqRHKHb8GJi5M4,66
2
- s3/exceptions.py,sha256=hH3jlMOe8yjBatQK9EdndWZz4QESU74KSY_iDhQ37SY,2585
3
- s3/logger.py,sha256=oH540oq8jY723jA4lDWlgfFPLbNgGXTkDwFpB7TLO_o,1196
4
- s3/tree.py,sha256=DiQ2ekMMaj2m_P3-iKkEqSuJCJZ_UZxcAwHtAoPVa5c,1824
5
- s3/uploader.py,sha256=tQaelL7grZSWFydZOekQgVz4Fipm0PHzbt2J17ddYHs,8563
6
- s3/utils.py,sha256=pKVT2GbDGQKpFaHOmVrCfiQhvgr1vuSsITt_0gHguAA,687
7
- pys3uploader-0.1.1.dist-info/LICENSE,sha256=8k-hEraOzyum0GvmmK65YxNRTFXK7eIFHJ0OshJXeTk,1068
8
- pys3uploader-0.1.1.dist-info/METADATA,sha256=sW_fsQxpoZ8f8ivI0Vb4oUXt1RSlFuHJDmpP9h_CXVU,7286
9
- pys3uploader-0.1.1.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
10
- pys3uploader-0.1.1.dist-info/top_level.txt,sha256=iQp4y1P58Q633gj8M08kHE4mqqT0hixuDWcniDk_RJ4,3
11
- pys3uploader-0.1.1.dist-info/RECORD,,