def _bs_model_storage(): """ Get django Storage object for BlockStructureModel. """ return get_storage( settings.BLOCK_STRUCTURES_SETTINGS.get('STORAGE_CLASS'), **settings.BLOCK_STRUCTURES_SETTINGS.get('STORAGE_KWARGS', {}) )
def _storage(self): """ Return the configured django storage backend. """ config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"] storage_class = config.get("STORAGE_CLASS", "") storage_kwargs = config.get("STORAGE_KWARGS", {}) return get_storage(storage_class, **storage_kwargs)
def handle(self, *args, **options): storage_class = options['storage'] folder = options['folder'] container = options['container'] path = options['path'] overwrite = options['overwrite'] delete_local = options['delete_local'] if not storage_class or not folder or not container or not path: print 'You must specify the -c, -f, -p, and -s parameters for this command' storage = get_storage(storage_class, container=container) files = [ f for f in listdir(path) if isfile(join(path, f)) and f.endswith('.gz') ] for file in files: print 'Inspecting {} ....'.format(file) local_path = join(path, file) try: with open(local_path, 'r') as f: dest_fn = '{}/{}'.format(folder, file) exists = storage.exists(dest_fn) # does it already exist? Don't overwrite if not exists or overwrite: # even if we overwrite, don't do so if filesize has not # changed if exists and overwrite: remote_size = storage.size(dest_fn) local_size = stat(local_path).st_size print '{} {}'.format(remote_size, local_size) if long(remote_size) == long(local_size): print '{} does not appear to have changed since last transfer. Skipping'.format( file) continue # remote storage often don't support updates, so we need to # delete/save pair storage.delete(dest_fn) print 'Shipping {} to remote storage...'.format(file) storage.save(dest_fn, f) if delete_local: print 'Deleting {} from disk...'.format(file) remove(local_path) else: print 'File {} already exists in remote storage. Skipping...'.format( file) except Exception, ex: print 'Exception: {}'.format(str(ex))
def _storage(self): """ Return the configured django storage backend. """ config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"] # Default to the S3 backend for backward compatibility storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto.S3BotoStorage") storage_kwargs = config.get("STORAGE_KWARGS", {}) # Map old settings to the parameters expected by the storage backend if "AWS_ACCESS_KEY" in config: storage_kwargs["access_key"] = config["AWS_ACCESS_KEY"] if "AWS_SECRET_KEY" in config: storage_kwargs["secret_key"] = config["AWS_SECRET_KEY"] if "S3_BUCKET" in config: storage_kwargs["bucket"] = config["S3_BUCKET"] storage_kwargs["querystring_expire"] = self.IMAGE_LINK_DURATION return get_storage(storage_class, **storage_kwargs)
def __init__(self, storage_class=None, storage_kwargs=None): if storage_kwargs is None: storage_kwargs = {} self.storage = get_storage(storage_class, **storage_kwargs)