def setup(self, application_key_id: str, application_key: str, bucket_name: str): info = b2sdk.InMemoryAccountInfo() self.api = b2sdk.B2Api(info) self.api.authorize_account("production", application_key_id, application_key) self.bucket = self.api.get_bucket_by_name(bucket_name)
def _get_api(self) -> b2.B2Api: if self.b2_api is None: self.b2_api = b2.B2Api( b2.InMemoryAccountInfo(), max_upload_workers=2) self.b2_api.authorize_account( 'production', self.application_key_id, self.application_key) return self.b2_api
def __init__(self, factory: Factory, credentials: B2Credentials, bucket_name: str, b2_raw_api: Any = None): self.credentials = credentials self.bucket_name = bucket_name # TODO(fyhuang): maybe a circular dependency later if we want to include sync in factory self.factory = factory # TODO(fyhuang): cache auth token between runs? self.info = b2.InMemoryAccountInfo() self.api = b2.B2Api(self.info, raw_api=b2_raw_api)
def client(self): if not hasattr(self, '_client'): self._account_info = b2.InMemoryAccountInfo() self._client = api.B2Api(self._account_info) self.client.authorize_account('production', self.kwargs['application_key_id'], self.kwargs['application_key']) retry = Retry(total=6) timeout = (self.connect_timeout, self.read_timeout) adapter = base.HTTPAdapter(max_retries=retry, timeout=timeout) self._client.raw_api.b2_http.session.mount('http://', adapter) self._client.raw_api.b2_http.session.mount('https://', adapter) self._client.raw_api.b2_http.TIMEOUT = timeout return self._client
import b2sdk.v1 as b2 import cfg import os import shutil import sys import time print("Backing up scriptdir:", cfg.SCRIPT_DIR) info = b2.InMemoryAccountInfo() b2_api = b2.B2Api(info) try: application_key_id = cfg.CONFIG['b2_key_id'] application_key = cfg.CONFIG['b2_key'] destination = cfg.CONFIG['b2_destination'] except KeyError: print("Missing b2 config key(s).") sys.exit() b2_api.authorize_account("production", application_key_id, application_key) source = cfg.SCRIPT_DIR source_tmp = os.path.join(cfg.SCRIPT_DIR, '.tmp_BU') if os.path.exists(source_tmp): shutil.rmtree(source_tmp) shutil.copytree(source, source_tmp, symlinks=False,