Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Make `B2Api.get_bucket_by_id` return populated bucket objects in v2
* Add proper support of `recommended_part_size` and `absolute_minimum_part_size` in `AccountInfo`
* Refactored `minimum_part_size` to `recommended_part_size` (tha value used stays the same)
* Refactored `sync.file.*File` and `sync.file.*FileVersion` to `sync.path.*SyncPath`
* Encryption settings, types and providers are now part of the public API
* Refactored `FileVersionInfo` to `FileVersion`

### Removed
* Remove `Bucket.copy_file` and `Bucket.start_large_file`
Expand Down
5 changes: 2 additions & 3 deletions b2sdk/_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# data classes

from b2sdk.file_version import FileIdAndName
from b2sdk.file_version import FileVersionInfo
from b2sdk.file_version import FileVersion
from b2sdk.large_file.part import Part
from b2sdk.large_file.unfinished_large_file import UnfinishedLargeFile

Expand Down Expand Up @@ -145,8 +145,7 @@
from b2sdk.sync.exception import EnvironmentEncodingError
from b2sdk.sync.exception import IncompleteSync
from b2sdk.sync.exception import InvalidArgument
from b2sdk.sync.file import File, B2File
from b2sdk.sync.file import FileVersion, B2FileVersion
from b2sdk.sync.path import B2SyncPath, LocalSyncPath
from b2sdk.sync.folder import AbstractFolder
from b2sdk.sync.folder import B2Folder
from b2sdk.sync.folder import LocalFolder
Expand Down
30 changes: 15 additions & 15 deletions b2sdk/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .encryption.setting import EncryptionSetting, EncryptionSettingFactory
from .encryption.types import EncryptionMode
from .exception import FileNotPresent, FileOrBucketNotFound, UnexpectedCloudBehaviour, UnrecognizedBucketType
from .file_version import FileVersionInfo, FileVersionInfoFactory
from .file_version import FileVersion, FileVersionFactory
from .progress import DoNothingProgressListener
from .transfer.emerge.executor import AUTO_CONTENT_TYPE
from .transfer.emerge.write_intent import WriteIntent
Expand Down Expand Up @@ -207,24 +207,24 @@ def download_file_by_name(
encryption=encryption,
)

def get_file_info_by_id(self, file_id: str) -> FileVersionInfo:
def get_file_info_by_id(self, file_id: str) -> FileVersion:
"""
Gets a file version's info by ID.

:param str file_id: the id of the file who's info will be retrieved.
:rtype: generator[b2sdk.v1.FileVersionInfo]
"""
return FileVersionInfoFactory.from_api_response(self.api.get_file_info(file_id))
return FileVersionFactory.from_api_response(self.api.get_file_info(file_id))

def get_file_info_by_name(self, file_name: str) -> FileVersionInfo:
def get_file_info_by_name(self, file_name: str) -> FileVersion:
"""
Gets a file version's info by its name.

:param str file_name: the name of the file who's info will be retrieved.
:rtype: generator[b2sdk.v1.FileVersionInfo]
"""
try:
return FileVersionInfoFactory.from_response_headers(
return FileVersionFactory.from_response_headers(
self.api.session.get_file_info_by_name(self.name, file_name)
)
except FileOrBucketNotFound:
Expand Down Expand Up @@ -273,11 +273,11 @@ def list_file_versions(self, file_name, fetch_count=None):
)

for entry in response['files']:
file_version_info = FileVersionInfoFactory.from_api_response(entry)
if file_version_info.file_name != file_name:
file_version = FileVersionFactory.from_api_response(entry)
if file_version.file_name != file_name:
# All versions for the requested file name have been listed.
return
yield file_version_info
yield file_version
start_file_name = response['nextFileName']
start_file_id = response['nextFileId']
if start_file_name is None:
Expand All @@ -302,7 +302,7 @@ def ls(self, folder_to_list='', show_versions=False, recursive=False, fetch_coun
:param bool recursive: if ``True``, list folders recursively
:param int,None fetch_count: how many entries to return or ``None`` to use the default. Acceptable values: 1 - 10000
:rtype: generator[tuple[b2sdk.v1.FileVersionInfo, str]]
:returns: generator of (file_version_info, folder_name) tuples
:returns: generator of (file_version, folder_name) tuples

.. note::
In case of `recursive=True`, folder_name is returned only for first file in the folder.
Expand Down Expand Up @@ -333,15 +333,15 @@ def ls(self, folder_to_list='', show_versions=False, recursive=False, fetch_coun
else:
response = session.list_file_names(self.id_, start_file_name, fetch_count, prefix)
for entry in response['files']:
file_version_info = FileVersionInfoFactory.from_api_response(entry)
if not file_version_info.file_name.startswith(prefix):
file_version = FileVersionFactory.from_api_response(entry)
if not file_version.file_name.startswith(prefix):
# We're past the files we care about
return
after_prefix = file_version_info.file_name[len(prefix):]
after_prefix = file_version.file_name[len(prefix):]
if '/' not in after_prefix or recursive:
# This is not a folder, so we'll print it out and
# continue on.
yield file_version_info, None
yield file_version, None
current_dir = None
else:
# This is a folder. If it's different than the folder
Expand All @@ -351,7 +351,7 @@ def ls(self, folder_to_list='', show_versions=False, recursive=False, fetch_coun
folder_with_slash = after_prefix.split('/')[0] + '/'
if folder_with_slash != current_dir:
folder_name = prefix + folder_with_slash
yield file_version_info, folder_name
yield file_version, folder_name
current_dir = folder_with_slash
if response['nextFileName'] is None:
# The response says there are no more files in the bucket,
Expand Down Expand Up @@ -725,7 +725,7 @@ def hide_file(self, file_name):
:rtype: b2sdk.v1.FileVersionInfo
"""
response = self.api.session.hide_file(self.id_, file_name)
return FileVersionInfoFactory.from_api_response(response)
return FileVersionFactory.from_api_response(response)

def copy(
self,
Expand Down
2 changes: 1 addition & 1 deletion b2sdk/encryption/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class EncryptionSettingFactory:
# if not authorized to read:
# isClientAuthorizedToRead is False and there is no value, so no mode
#
# BUT file_version_info (get_file_info, list_file_versions, upload_file etc)
# BUT file_version (get_file_info, list_file_versions, upload_file etc)
# if the file is encrypted, then
# "serverSideEncryption": {"algorithm": "AES256", "mode": "SSE-B2"},
# or
Expand Down
14 changes: 7 additions & 7 deletions b2sdk/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,21 @@ def should_retry_http(self):


class DestFileNewer(B2Error):
def __init__(self, dest_file, source_file, dest_prefix, source_prefix):
def __init__(self, dest_path, source_path, dest_prefix, source_prefix):
super(DestFileNewer, self).__init__()
self.dest_file = dest_file
self.source_file = source_file
self.dest_path = dest_path
self.source_path = source_path
self.dest_prefix = dest_prefix
self.source_prefix = source_prefix

def __str__(self):
return 'source file is older than destination: %s%s with a time of %s cannot be synced to %s%s with a time of %s, unless a valid newer_file_mode is provided' % (
self.source_prefix,
self.source_file.name,
self.source_file.latest_version().mod_time,
self.source_path.relative_path,
self.source_path.mod_time,
self.dest_prefix,
self.dest_file.name,
self.dest_file.latest_version().mod_time,
self.dest_path.relative_path,
self.dest_path.mod_time,
)

def should_retry_http(self):
Expand Down
10 changes: 5 additions & 5 deletions b2sdk/file_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .encryption.setting import EncryptionSetting, EncryptionSettingFactory


class FileVersionInfo(object):
class FileVersion(object):
"""
A structure which represents a version of a file (in B2 cloud).

Expand Down Expand Up @@ -114,7 +114,7 @@ def __eq__(self, other):
return True


class FileVersionInfoFactory(object):
class FileVersionFactory(object):
"""
Construct :py:class:`b2sdk.v1.FileVersionInfo` objects from various structures.
"""
Expand Down Expand Up @@ -171,7 +171,7 @@ def from_api_response(cls, file_info_dict, force_action=None):
file_info = file_info_dict.get('fileInfo')
server_side_encryption = EncryptionSettingFactory.from_file_version_dict(file_info_dict)

return FileVersionInfo(
return FileVersion(
id_,
file_name,
size,
Expand All @@ -186,7 +186,7 @@ def from_api_response(cls, file_info_dict, force_action=None):

@classmethod
def from_cancel_large_file_response(cls, response):
return FileVersionInfo(
return FileVersion(
response['fileId'],
response['fileName'],
0, # size
Expand All @@ -199,7 +199,7 @@ def from_cancel_large_file_response(cls, response):

@classmethod
def from_response_headers(cls, headers):
return FileVersionInfo(
return FileVersion(
id_=headers.get('x-bz-file-id'),
file_name=headers.get('x-bz-file-name'),
size=headers.get('content-length'),
Expand Down
4 changes: 2 additions & 2 deletions b2sdk/large_file/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Optional

from b2sdk.encryption.setting import EncryptionSetting
from b2sdk.file_version import FileVersionInfoFactory
from b2sdk.file_version import FileVersionFactory
from b2sdk.large_file.part import PartFactory
from b2sdk.large_file.unfinished_large_file import UnfinishedLargeFile

Expand Down Expand Up @@ -112,4 +112,4 @@ def cancel_large_file(self, file_id):
:rtype: None
"""
response = self.services.session.cancel_large_file(file_id)
return FileVersionInfoFactory.from_cancel_large_file_response(response)
return FileVersionFactory.from_cancel_large_file_response(response)
46 changes: 23 additions & 23 deletions b2sdk/sync/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from ..raw_api import SRC_LAST_MODIFIED_MILLIS
from ..transfer.outbound.upload_source import UploadSourceLocalFile
from .file import B2File
from .path import B2SyncPath
from .report import SyncFileReporter

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -210,18 +210,18 @@ def __str__(self):
class B2DownloadAction(AbstractAction):
def __init__(
self,
source_file: B2File,
source_path: B2SyncPath,
b2_file_name: str,
local_full_path: str,
encryption_settings_provider: AbstractSyncEncryptionSettingsProvider,
):
"""
:param b2sdk.v1.B2File source_file: the file to be downloaded
:param b2sdk.v1.B2SyncPath source_path: the file to be downloaded
:param str b2_file_name: b2_file_name
:param str local_full_path: a local file path
:param b2sdk.v1.AbstractSyncEncryptionSettingsProvider encryption_settings_provider: encryption setting provider
"""
self.source_file = source_file
self.source_path = source_path
self.b2_file_name = b2_file_name
self.local_full_path = local_full_path
self.encryption_settings_provider = encryption_settings_provider
Expand All @@ -232,7 +232,7 @@ def get_bytes(self):

:rtype: int
"""
return self.source_file.latest_version().size
return self.source_path.size

def _ensure_directory_existence(self):
parent_dir = os.path.dirname(self.local_full_path)
Expand Down Expand Up @@ -264,11 +264,11 @@ def do_action(self, bucket, reporter):

encryption = self.encryption_settings_provider.get_setting_for_download(
bucket=bucket,
file_version_info=self.source_file.latest_version().file_version_info,
file_version=self.source_path.file_version(),
)

bucket.download_file_by_id(
self.source_file.latest_version().id_,
self.source_path.file_id(),
download_dest,
progress_listener,
encryption=encryption,
Expand All @@ -289,13 +289,13 @@ def do_report(self, bucket, reporter):
:type bucket: b2sdk.bucket.Bucket
:param reporter: a place to report errors
"""
reporter.print_completion('dnload ' + self.source_file.name)
reporter.print_completion('dnload ' + self.source_path.relative_path)

def __str__(self):
return (
'b2_download(%s, %s, %s, %d)' % (
self.b2_file_name, self.source_file.latest_version().id_, self.local_full_path,
self.source_file.latest_version().mod_time
self.b2_file_name, self.source_path.file_id(), self.local_full_path,
self.source_path.mod_time
)
)

Expand All @@ -308,22 +308,22 @@ class B2CopyAction(AbstractAction):
def __init__(
self,
b2_file_name: str,
source_file: B2File,
source_path: B2SyncPath,
dest_b2_file_name,
source_bucket: Bucket,
destination_bucket: Bucket,
encryption_settings_provider: AbstractSyncEncryptionSettingsProvider,
):
"""
:param str b2_file_name: a b2_file_name
:param b2sdk.v1.B2File source_file: the file to be copied
:param b2sdk.v1.B2SyncPath source_path: the file to be copied
:param str dest_b2_file_name: a name of a destination remote file
:param Bucket source_bucket: bucket to copy from
:param Bucket destination_bucket: bucket to copy to
:param b2sdk.v1.AbstractSyncEncryptionSettingsProvider encryption_settings_provider: encryption setting provider
"""
self.b2_file_name = b2_file_name
self.source_file = source_file
self.source_path = source_path
self.dest_b2_file_name = dest_b2_file_name
self.encryption_settings_provider = encryption_settings_provider
self.source_bucket = source_bucket
Expand All @@ -335,7 +335,7 @@ def get_bytes(self):

:rtype: int
"""
return self.source_file.latest_version().size
return self.source_path.size

def do_action(self, bucket, reporter):
"""
Expand All @@ -352,24 +352,24 @@ def do_action(self, bucket, reporter):

source_encryption = self.encryption_settings_provider.get_source_setting_for_copy(
bucket=self.source_bucket,
source_file_version_info=self.source_file.latest_version().file_version_info,
source_file_version=self.source_path.file_version(),
)

destination_encryption = self.encryption_settings_provider.get_destination_setting_for_copy(
bucket=self.destination_bucket,
source_file_version_info=self.source_file.latest_version().file_version_info,
source_file_version=self.source_path.file_version(),
dest_b2_file_name=self.dest_b2_file_name,
)

bucket.copy(
self.source_file.latest_version().id_,
self.source_path.file_id(),
self.dest_b2_file_name,
length=self.source_file.latest_version().size,
length=self.source_path.size,
progress_listener=progress_listener,
destination_encryption=destination_encryption,
source_encryption=source_encryption,
source_file_info=self.source_file.latest_version().file_version_info.file_info,
source_content_type=self.source_file.latest_version().file_version_info.content_type,
source_file_info=self.source_path.file_version().file_info,
source_content_type=self.source_path.file_version().content_type,
)

def do_report(self, bucket, reporter):
Expand All @@ -380,13 +380,13 @@ def do_report(self, bucket, reporter):
:type bucket: b2sdk.bucket.Bucket
:param reporter: a place to report errors
"""
reporter.print_completion('copy ' + self.source_file.name)
reporter.print_completion('copy ' + self.source_path.relative_path)

def __str__(self):
return (
'b2_copy(%s, %s, %s, %d)' % (
self.b2_file_name, self.source_file.latest_version().id_, self.dest_b2_file_name,
self.source_file.latest_version().mod_time
self.b2_file_name, self.source_path.file_id(), self.dest_b2_file_name,
self.source_path.mod_time
)
)

Expand Down
Loading