Пример #1
0
 def upload_file(self, bucket_name, file_information):
     bucket = self._s3_client.get_bucket(bucket_name)
     if bucket is None:
         return False
     object_name = to_posix(file_information.rel_path)
     key = bucket.get_key(object_name)
     key = bucket.new_key(key_name=object_name) if key is None else key
     try:
         key.set_contents_from_filename(file_information.abs_path)
     except Exception as exception:
         self._logger.error(exception)
         raise
     file_length = self._file_system_helper.file_size(
         file_information.abs_path)
     self._logger.debug(
         f'File "{object_name}" uploaded, {file_length} bytes transferred')
     return file_length
Пример #2
0
 def delete_file(self, bucket_name, file_rel_path):
     object_name = to_posix(file_rel_path)
     bucket = self._s3_client.get_bucket(bucket_name)
     if bucket is None:
         self._logger.warning(
             f'Tried to delete object "{object_name}" from non-existent bucket "{bucket_name}"'
         )
         return False
     key = bucket.get_key(object_name)
     if key is None:
         self._logger.warning(
             f'Tried to delete non-existent object "{object_name}" from bucket "{bucket_name}"'
         )
         return False
     key.delete()
     self._logger.debug(
         f'Deleted object "{object_name}" from bucket "{bucket_name}"')
     return True
Пример #3
0
 def test_windows_path_converted_to_posix(self):
     path = r'c\test\subdir\file.txt'
     assert to_posix(path) == r"c/test/subdir/file.txt"
Пример #4
0
 def test_empty_string_returns_dot(self):
     path = r""
     assert to_posix(path) == r"."
Пример #5
0
 def test_blank_string_remains_empty(self):
     path = r" "
     assert to_posix(path) == r" "
Пример #6
0
 def test_posix_directory_remain_posix_final_slash_removed(self):
     path = r"C:/test/subdir/"
     assert to_posix(path) == r"C:/test/subdir"
Пример #7
0
 def test_windows_directory_converts_to_posix_final_slash_removed(self):
     path = r"C:\\test\\subdir\\"
     assert to_posix(path) == r"C:/test/subdir"
Пример #8
0
 def test_posix_path_remain_posix(self):
     path = r"c/test/subdir/file.txt"
     assert to_posix(path) == r"c/test/subdir/file.txt"
Пример #9
0
 def test_mixed_path_converted_to_posix(self):
     path = r"c/test\subdir/file.txt"
     assert to_posix(path) == r"c/test/subdir/file.txt"