• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NaturalHistoryMuseum / data-importer / #34

02 Sep 2025 02:43PM UTC coverage: 77.156%. Remained the same
#34

push

coveralls-python

alycejenni
fix: add parentheses to decorator

0 of 1 new or added line in 1 file covered. (0.0%)

1297 of 1681 relevant lines covered (77.16%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/dataimporter/cli/view.py
1
import click
×
2

3
from dataimporter.cli.utils import console, with_config
×
4
from dataimporter.importer import use_importer
×
5
from dataimporter.lib.config import Config
×
6

7

8
@click.group('view')
×
9
def view_group():
×
10
    pass
×
11

12

13
@view_group.command('list')
×
14
@with_config()
×
15
def list_views(config: Config):
×
16
    """
17
    List the name of all the views in current use.
18
    """
19
    with use_importer(config) as importer:
×
20
        console.log(', '.join(view.name for view in importer.views))
×
21

22

23
@view_group.command('flush')
×
24
@click.argument('view', type=str)
×
25
@with_config()
×
26
def flush(view: str, config: Config):
×
27
    """
28
    Flushes the given view's queue.
29

30
    For non-published views this should always be safe to do (but maybe think about it
31
    first, just to make sure) but for published views you should make sure you know what
32
    you're doing.
33
    """
34
    with use_importer(config) as importer:
×
35
        view = importer.get_view(view)
×
36
        console.log(
×
37
            f'Flushing {view.name} view queue, currently has', view.count(), 'IDs in it'
38
        )
39
        view.flush()
×
40
        console.log(f'{view.name} flushed')
×
41

42

43
@view_group.command('ingest')
×
44
@click.argument('view', type=str)
×
45
@click.option(
×
46
    '--everything',
47
    is_flag=True,
48
    show_default=True,
49
    default=False,
50
    help='Add all records to MongoDB regardless of whether they have changed. This is '
51
    "primarily useful when a change has been made to a view's filters or "
52
    'representation',
53
)
54
@with_config()
×
55
def ingest(view: str, config: Config, everything: bool = False):
×
56
    """
57
    On the given view, updates MongoDB with any queued EMu changes and flushes its
58
    queue.
59
    """
60
    with use_importer(config) as importer:
×
61
        console.log(f'Adding changes from {view} view to mongo')
×
62
        importer.add_to_mongo(view, everything=everything)
×
63
        console.log(f'Added changes from {view} view to mongo')
×
64

65

66
@view_group.command('sync')
×
67
@click.argument('view', type=str)
×
68
@click.option(
×
69
    '--resync',
70
    is_flag=True,
71
    show_default=True,
72
    default=False,
73
    help='Resynchronise all data in Elasticsearch with MongoDB for this view, not just '
74
    'the records that have changed.',
75
)
76
@with_config()
×
77
def sync(view: str, config: Config, resync: bool = False):
×
78
    """
79
    Updates Elasticsearch with the changes in MongoDB for the given view.
80
    """
81
    with use_importer(config) as importer:
×
82
        console.log(f'Syncing changes from {view} view to elasticsearch')
×
83
        importer.sync_to_elasticsearch(view, resync=resync)
×
84
        console.log(f'Finished with {view}')
×
85

86

87
@view_group.command('purge')
×
88
@click.argument('view', type=str)
×
NEW
89
@with_config()
×
90
def purge(view: str, config: Config):
×
91
    """
92
    Purge non-member and non-publishable records from a view.
93

94
    Non-publishable records should be handled by the ingest process, but the occurrence
95
    of records that stop being members of a view should be much rarer so this needs to
96
    be run on a semi-regular basis to account for those.
97
    """
98
    with use_importer(config) as importer:
×
99
        console.log(f'Purging non-member and non-publishable records from {view}')
×
100
        non_member, non_publishable, total_deleted = importer.purge_unsuitable_records(
×
101
            view
102
        )
103
        console.log(f'{non_member} non-member records found')
×
104
        console.log(f'{non_publishable} non-publishable records found')
×
105
        console.log(f'{total_deleted} records deleted')
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc