def test_synchronize_remove(self): self.test_synchronize_add() # add a dataset with a non-existing location and assert that it is # removed dataset = models.RectifiedDataset( identifier="rectified-1", footprint=GEOSGeometry( "MULTIPOLYGON (((-111.6210939999999994 26.8588260000000005, -113.0273439999999994 -4.0786740000000004, -80.6835939999999994 -9.7036739999999995, -68.0273439999999994 15.6088260000000005, -111.6210939999999994 26.8588260000000005)))" ), begin_time=parse_datetime("2013-06-11T14:55:23Z"), end_time=parse_datetime("2013-06-11T14:55:23Z"), min_x=10, min_y=10, max_x=20, max_y=20, srid=4326, size_x=100, size_y=100, range_type=models.RangeType.objects.get(name="RGB")) dataset.full_clean() dataset.save() backends.DataItem.objects.create(dataset=dataset, semantic="bands", location="doesnotexist.tif") backends.DataItem.objects.create(dataset=dataset, semantic="metadata", location="doesnotexist.xml") self.collection.insert(dataset) synchronize(self.collection) with self.assertRaises(models.Coverage.DoesNotExist): models.Coverage.objects.get(identifier="rectified-1")
def test_synchronize_remove(self): self.test_synchronize_add() # add a dataset with a non-existing location and assert that it is # removed dataset = models.RectifiedDataset( identifier="rectified-1", footprint=GEOSGeometry("MULTIPOLYGON (((-111.6210939999999994 26.8588260000000005, -113.0273439999999994 -4.0786740000000004, -80.6835939999999994 -9.7036739999999995, -68.0273439999999994 15.6088260000000005, -111.6210939999999994 26.8588260000000005)))"), begin_time=parse_datetime("2013-06-11T14:55:23Z"), end_time=parse_datetime("2013-06-11T14:55:23Z"), min_x=10, min_y=10, max_x=20, max_y=20, srid=4326, size_x=100, size_y=100, range_type=models.RangeType.objects.get(name="RGB") ) dataset.full_clean() dataset.save() backends.DataItem.objects.create( dataset=dataset, semantic="bands", location="doesnotexist.tif" ) backends.DataItem.objects.create( dataset=dataset, semantic="metadata", location="doesnotexist.xml" ) self.collection.insert(dataset) synchronize(self.collection) with self.assertRaises(models.Coverage.DoesNotExist): models.Coverage.objects.get( identifier="rectified-1" )
def test_synchronize_add(self): synchronize(self.collection) coverages = models.Coverage.objects.filter(identifier__in=[ "mosaic_MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_RGB_reduced", "mosaic_MER_FRS_1PNPDE20060822_092058_000001972050_00308_23408_0077_RGB_reduced", "mosaic_MER_FRS_1PNPDE20060830_100949_000001972050_00423_23523_0079_RGB_reduced" ]) if not len(coverages) == 3: self.fail("Expected coverages don't exist.") for coverage in coverages: self.assertIn(coverage, self.collection)
def test_synchronize_add(self): synchronize(self.collection) coverages = models.Coverage.objects.filter( identifier__in=[ "mosaic_MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_RGB_reduced", "mosaic_MER_FRS_1PNPDE20060822_092058_000001972050_00308_23408_0077_RGB_reduced", "mosaic_MER_FRS_1PNPDE20060830_100949_000001972050_00423_23523_0079_RGB_reduced" ] ) if not len(coverages) == 3: self.fail("Expected coverages don't exist.") for coverage in coverages: self.assertIn(coverage, self.collection)
def handle(self, collection_ids, all_collections, *args, **kwargs): if not collection_ids and not all_collections: raise CommandError( "Missing the mandatory collection identifier(s)!" ) if all_collections: collection_ids = ( c.identifier for c in models.Collection.objects.all() ) for collection_id in collection_ids: try: collection = models.Collection.objects.get( identifier=collection_id ) except models.Collection.DoesNotExist: raise CommandError( "Collection '%s' does not exist." % collection_id ) self.print_msg("Synchronizing collection '%s'." % collection_id) registered, deleted = synchronize(collection.cast()) self.print_msg( "Finished synchronizing collection '%s'. Registered %d new " "datasets, deleted %d stale datasets." % ( collection_id, registered, deleted ) )
def handle(self, *args, **kwargs): synchronize() # check the required inputs collection_ids = kwargs.get('collection_ids', None) remove_ids = kwargs.get('remove_ids', None) if not collection_ids: raise CommandError( "Missing the mandatory collection identifier(s)!" ) if not remove_ids: raise CommandError( "Missing the mandatory identifier(s) for to be removed " "objects." ) # extract the collections ignore_missing_collection = kwargs['ignore_missing_collection'] collections = [] for collection_id in collection_ids: try: collections.append( models.Collection.objects.get(identifier=collection_id) ) except models.Collection.DoesNotExist: msg = ( "There is no Collection matching the given " "identifier: '%s'" % collection_id ) if ignore_missing_collection: self.print_wrn(msg) else: raise CommandError(msg) # extract the children ignore_missing_object = kwargs['ignore_missing_object'] objects = [] for remove_id in remove_ids: try: objects.append( models.EOObject.objects.get(identifier=remove_id) ) except models.EOObject.DoesNotExist: msg = ( "There is no EOObject matching the given identifier: '%s'" % remove_id ) if ignore_missing_object: self.print_wrn(msg) else: raise CommandError(msg) try: for collection, eo_object in product(collections, objects): # check whether the link does not exist if eo_object in collection: self.print_msg( "Unlinking: %s <-x- %s" % (collection, eo_object) ) collection.remove(eo_object) else: self.print_wrn( "Collection %s does not contain %s" % (collection, eo_object) ) except Exception as e: self.print_traceback(e, kwargs) raise CommandError("Unlinking failed: %s" % (e))