Skip to content

Commit 0a3af85

Browse files
committed
use source also to delete record sets
1 parent 699f85f commit 0a3af85

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pycsw/core/admin.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,16 @@ def validate_xml(xml, xsd):
354354
raise RuntimeError('ERROR: %s' % str(err)) from err
355355

356356

357-
def delete_records(context, database, table):
357+
def delete_records(context, source, database, table):
358358
"""Deletes all records from repository"""
359359

360360
LOGGER.info('Deleting all records')
361361

362362
repo = repository.Repository(database, context, table=table)
363-
repo.delete(constraint={'where': '', 'values': []})
364-
363+
if source == 'all':
364+
repo.delete(constraint={'where': '', 'values': []})
365+
else:
366+
repo.delete(constraint={'where': f"mdsource == '{source}'", 'values': []})
365367

366368
def cli_option_verbosity(f):
367369
def callback(ctx, param, value):
@@ -385,7 +387,7 @@ def callback(ctx, param, value):
385387

386388
CLI_OPTION_YES_PROMPT = click.option('--yes', '-y', is_flag=True,
387389
default=False,
388-
prompt='This will delete all records! Continue?',
390+
prompt='This will delete all or a set of records! Continue?',
389391
help='Bypass confirmation')
390392

391393

@@ -455,9 +457,11 @@ def cli_load_records(ctx, config, path, recursive, hashidentifier, source, yes,
455457
@cli_callbacks
456458
@click.pass_context
457459
@CLI_OPTION_CONFIG
460+
@click.option('--source', '-s', required=False,
461+
default='all', help='Remove only records from a source')
458462
@CLI_OPTION_YES_PROMPT
459-
def cli_delete_records(ctx, config, yes, verbosity):
460-
"""Delete all records from repository"""
463+
def cli_delete_records(ctx, config, source, yes, verbosity):
464+
"""Delete records from repository"""
461465

462466
with open(config, encoding='utf8') as fh:
463467
cfg = yaml_load(fh)
@@ -466,6 +470,7 @@ def cli_delete_records(ctx, config, yes, verbosity):
466470

467471
delete_records(
468472
context,
473+
source,
469474
cfg['repository']['database'],
470475
cfg['repository']['table']
471476
)

0 commit comments

Comments
 (0)