How to use the b2sdk.sync.file.File function in b2sdk

To help you get started, we’ve selected a few b2sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Backblaze / b2-sdk-python / test / v1 / test_policy.py View on Github external
def check_one_answer(self, has_source, id_relative_date_action_list, expected_actions):
        source_file = File('a', []) if has_source else None
        dest_file_versions = [
            FileVersion(id_, 'a', self.today + relative_date * self.one_day_millis, action, 100)
            for (id_, relative_date, action) in id_relative_date_action_list
        ]
        dest_file = File('a', dest_file_versions)
        bucket = MagicMock()
        api = MagicMock()
        api.get_bucket_by_name.return_value = bucket
        dest_folder = B2Folder('bucket-1', 'folder', api)
        actual_actions = list(
            make_b2_keep_days_actions(
                source_file, dest_file, dest_folder, dest_folder, self.keep_days, self.today
            )
        )
        actual_action_strs = [str(a) for a in actual_actions]
        self.assertEqual(expected_actions, actual_action_strs)
github Backblaze / b2-sdk-python / test / v1 / test_policy.py View on Github external
def check_one_answer(self, has_source, id_relative_date_action_list, expected_actions):
        source_file = File('a', []) if has_source else None
        dest_file_versions = [
            FileVersion(id_, 'a', self.today + relative_date * self.one_day_millis, action, 100)
            for (id_, relative_date, action) in id_relative_date_action_list
        ]
        dest_file = File('a', dest_file_versions)
        bucket = MagicMock()
        api = MagicMock()
        api.get_bucket_by_name.return_value = bucket
        dest_folder = B2Folder('bucket-1', 'folder', api)
        actual_actions = list(
            make_b2_keep_days_actions(
                source_file, dest_file, dest_folder, dest_folder, self.keep_days, self.today
            )
        )
        actual_action_strs = [str(a) for a in actual_actions]
        self.assertEqual(expected_actions, actual_action_strs)
github Backblaze / b2-sdk-python / b2sdk / sync / folder.py View on Github external
raise UnSyncableFilename(
                    "sync does not support file names that include relative paths", file_name
                )
            # Do not allow absolute paths in file names
            if ABSOLUTE_PATH_MATCHER.search(file_name):
                raise UnSyncableFilename(
                    "sync does not support file names with absolute paths", file_name
                )
            # On Windows, do not allow drive letters in file names
            if platform.system() == "Windows" and DRIVE_MATCHER.search(file_name):
                raise UnSyncableFilename(
                    "sync does not support file names with drive letters", file_name
                )

            if current_name != file_name and current_name is not None and current_versions:
                yield File(current_name, current_versions)
                current_versions = []
            file_info = file_version_info.file_info
            if SRC_LAST_MODIFIED_MILLIS in file_info:
                mod_time_millis = int(file_info[SRC_LAST_MODIFIED_MILLIS])
            else:
                mod_time_millis = file_version_info.upload_timestamp
            assert file_version_info.size is not None

            current_name = file_name
            file_version = FileVersion(
                file_version_info.id_, file_version_info.file_name, mod_time_millis,
                file_version_info.action, file_version_info.size
            )

            if policies_manager.should_exclude_file_version(file_version):
                continue
github Backblaze / b2-sdk-python / b2sdk / sync / folder.py View on Github external
local_path, b2_path, reporter, policies_manager
                ):
                    yield subdir_file
            else:
                # Check that the file still exists and is accessible, since it can take a long time
                # to iterate through large folders
                if is_file_readable(local_path, reporter):
                    file_mod_time = int(os.path.getmtime(local_path) * 1000)

                    file_size = os.path.getsize(local_path)
                    version = FileVersion(local_path, b2_path, file_mod_time, 'upload', file_size)

                    if policies_manager.should_exclude_file_version(version):
                        continue

                    yield File(b2_path, [version])