def upload_files( path, vendor, bucket=None, use_encryption=True, add_checksum=False, progress=False, prefix=None, ignore_prefix=False, ): """Uploads file to the cloud. Args: path (str): path to the file or folder vendor (str): datacenter name: 'aws|softlayer|azure|googlecloud' use_encryption (bool): should the file be server side encrypted add_checksum (bool): should the md5 checksum be uploaded next to the original file progress (bool): should the transfer be monitored Returns: tuple - confirmation(s) from the vendor """ from wanna import setup_vendor vendor = setup_vendor( vendor, bucket=bucket, use_encryption=use_encryption, ignore_prefix=ignore_prefix, ) vendor.upload_files(path, add_checksum=add_checksum, progress=progress)
def download_file(path, vendor, dst=".", bucket=None, use_encryption=True, add_checksum=False, progress=False, ignore_prefix=False, encryption_key=None, humanized=False, **kwargs): """Download file from the cloud. Args: path (str): path to the file vendor (str): datacenter name: 'aws|softlayer|azure|googlecloud' dst (str): destination default . use_encryption (bool): should the file be decrypted add_checksum (bool): should the control sum be checked progress (bool): should the transfer be monitored ignore_prefix (bool): ignore all prefixes Returns: obj - confirmation(s) from the vendor """ vendor = setup_vendor( vendor, bucket=bucket, use_encryption=use_encryption, ignore_prefix=ignore_prefix, humanized=humanized, ) if add_checksum: chck_path = path + vendor.hash_checksum vendor.download_file(chck_path, use_encryption=False) resp = vendor.download_file(path, dst=dst, progress=progress) if add_checksum: with open(chck_path, "rb") as chck_file: control1 = chck_file.read().strip() control2 = vendor.get_checksum(path) if control1 != control2: error = "File corrupted!\n" error += "".join(difflib.unified_diff(control2, control1)) raise IntegrityError(error) else: LOG.info("\nIntegrity check: OK") return resp
def delete_file(vendor, path, **kwargs): vendor = setup_vendor(vendor, **kwargs) return vendor.delete_file(path)
def get_status(vendor, path, **kwargs): vendor = setup_vendor(vendor, **kwargs) return vendor.get_status(path)
def list_files(vendor, **kwargs): vendor = setup_vendor(vendor, **kwargs) return vendor.list_files()
def rename_file(vendor, old, new, **kwargs): vendor = setup_vendor(vendor, **kwargs) return vendor.rename_object(old, new)
def search_files(vendor, term, fuzzy, **kwargs): vendor = setup_vendor(vendor, **kwargs) return vendor.search(term, fuzzy)
def setup_vendor(vendor, **kwargs): from wanna import setup_vendor return setup_vendor(vendor, **kwargs)