def do_store(sender, **kwargs): asset = kwargs['asset'] asset_uuid = asset.uuid asset_file = kwargs['asset_file'] asset_file.seek(0) # Might have been read by other handlers with write_lock: destination = open(get_filename(asset_uuid), 'wb') for chunk in asset_file.chunks(): destination.write(chunk) destination.close() return True store_asset.connect(do_store) def do_retrieve(sender, **kwargs): asset_uuid = kwargs['asset_uuid'] source = open(get_filename(asset_uuid), 'rb') return source retrieve_asset.connect(do_retrieve) def do_delete(sender, **kwargs): asset_uuid = kwargs['asset_uuid'] try: os.remove(get_filename(asset_uuid))
# Hash - use Django chunks, so can handle big files decently hasher = hashlib.sha256() for chunk in asset_file.chunks(): hasher.update(chunk) asset.hash_value = 'SHA256|' + hasher.hexdigest() # Save asset.save() return True ## Returns the 'emptymap asset', a basis for new maps @staticmethod def get_emptymap(): owner = UserAccount.get_initial_asset_creator() ret = AssetInfo.objects.filter(location='base/emptymap.tar.gz') ret = filter(lambda r: r.owners.all()[0].uuid == owner.uuid, ret)[0] return ret store_asset.connect(AssetInfo.calculate_metadata, weak=False) classes = [UserAccount, ServerInstance, Activity, AssetInfo] for _class in classes: intensity_uuid_model(_class) # Set home dir, to our parent (ignored if already set) import intensity.conf as intensity_conf intensity_conf.set_home_dir()
for chunk in asset_file.chunks(): hasher.update(chunk) asset.hash_value = 'SHA256|' + hasher.hexdigest() # Save asset.save() return True ## Returns the 'emptymap asset', a basis for new maps @staticmethod def get_emptymap(): owner = UserAccount.get_initial_asset_creator() ret = AssetInfo.objects.filter(location='base/emptymap.tar.gz') ret = filter(lambda r: r.owners.all()[0].uuid == owner.uuid, ret)[0] return ret store_asset.connect(AssetInfo.calculate_metadata, weak=False) classes = [UserAccount, ServerInstance, Activity, AssetInfo] for _class in classes: intensity_uuid_model(_class) # Set home dir, to our parent (ignored if already set) import intensity.conf as intensity_conf intensity_conf.set_home_dir()