Skip to content

Commit

Permalink
refactor: rename view.sg_nameto view.pulished_name and use "published…
Browse files Browse the repository at this point in the history
…" for views with SG DBs

Published makes a bit more sense.
  • Loading branch information
jrdh committed Aug 15, 2024
1 parent d288200 commit c4b5d31
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dataimporter/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dataimporter.cli.portal import portal_group
from dataimporter.cli.utils import with_config, console
from dataimporter.cli.view import view_group
from dataimporter.importer import DataImporter, ViewDoesNotHaveDatabase
from dataimporter.importer import DataImporter, ViewIsNotPublished
from dataimporter.lib.config import Config


Expand Down Expand Up @@ -41,7 +41,7 @@ def get_status(config: Config):

try:
database = importer.get_database(view)
except ViewDoesNotHaveDatabase:
except ViewIsNotPublished:
console.log(Rule())
continue

Expand Down
6 changes: 4 additions & 2 deletions dataimporter/emu/views/artefact.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class ArtefactView(View):
This view populates the artefacts resource on the Data Portal.
"""

def __init__(self, path: Path, store: Store, image_view: ImageView, sg_name: str):
super().__init__(path, store, sg_name)
def __init__(
self, path: Path, store: Store, image_view: ImageView, published_name: str
):
super().__init__(path, store, published_name)
self.image_link = make_link(self, MEDIA_ID_REF_FIELD, image_view, ID)

def is_member(self, record: SourceRecord) -> FilterResult:
Expand Down
4 changes: 2 additions & 2 deletions dataimporter/emu/views/indexlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def __init__(
store: Store,
image_view: ImageView,
taxonomy_view: TaxonomyView,
sg_name: str,
published_name: str,
):
super().__init__(path, store, sg_name)
super().__init__(path, store, published_name)
self.image_link = make_link(self, MEDIA_ID_REF_FIELD, image_view, ID)
self.taxonomy_link = make_link(self, TAXONOMY_ID_REF_FIELD, taxonomy_view, ID)

Expand Down
6 changes: 4 additions & 2 deletions dataimporter/emu/views/preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class PreparationView(View):
This view populates the preparation resource on the Data Portal.
"""

def __init__(self, path: Path, store: Store, specimen_view: View, sg_name: str):
super().__init__(path, store, sg_name)
def __init__(
self, path: Path, store: Store, specimen_view: View, published_name: str
):
super().__init__(path, store, published_name)
self.specimen_view = specimen_view
self.voucher_spec_link = make_link(
self, SPECIMEN_ID_REF_FIELD, specimen_view, ID
Expand Down
4 changes: 2 additions & 2 deletions dataimporter/emu/views/specimen.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def __init__(
taxonomy_view: TaxonomyView,
gbif_view: GBIFView,
mammal_part_view: MammalPartView,
sg_name: str,
published_name: str,
):
super().__init__(path, store, sg_name)
super().__init__(path, store, published_name)
self.image_link = make_link(self, MEDIA_ID_REF_FIELD, image_view, ID)
self.taxonomy_link = make_link(self, TAXONOMY_ID_REF_FIELD, taxonomy_view, ID)
self.gbif_link = make_link(
Expand Down
8 changes: 4 additions & 4 deletions dataimporter/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, name: str):
self.name = name


class ViewDoesNotHaveDatabase(Exception):
class ViewIsNotPublished(Exception):
def __init__(self, view: View):
super().__init__(f"View {view.name} does not have a Splitgill database")
self.view = view.name
Expand Down Expand Up @@ -173,9 +173,9 @@ def get_database(self, view: Union[str, View]) -> SplitgillDatabase:
"""
if isinstance(view, str):
view = self.get_view(view)
if not view.has_database:
raise ViewDoesNotHaveDatabase(view)
return SplitgillDatabase(view.sg_name, self.client)
if not view.is_published:
raise ViewIsNotPublished(view)
return SplitgillDatabase(view.published_name, self.client)

def queue_changes(self, records: Iterable[SourceRecord], store_name: str):
"""
Expand Down
13 changes: 7 additions & 6 deletions dataimporter/lib/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,29 @@ class View:
- links from this view to other views
"""

def __init__(self, path: Path, store: Store, sg_name: Optional[str] = None):
def __init__(self, path: Path, store: Store, published_name: Optional[str] = None):
"""
:param path: the root path that all view related data should be stored under
:param store: the Store object that backs this view
:param sg_name: the name of the SplitgillDatabase this view populates
:param published_name: the name of the SplitgillDatabase this view populates
"""
self.path = path
self.store = store
self.sg_name = sg_name
self.published_name = published_name
self.name = path.name
self.changes = ChangeQueue(self.path / "changes")
# a list of links which need to be updated when records in this view change
self.dependants: List[Link] = []

@property
def has_database(self) -> bool:
def is_published(self) -> bool:
"""
Returns whether this view directly feeds a Splitgill database.
Returns whether this view directly feeds a Splitgill database, i.e. is
"published" to the Portal.
:return: True if a Splitgill database should exist for this view, False if not
"""
return self.sg_name is not None
return self.published_name is not None

def add_dependant(self, link: "Link"):
"""
Expand Down

0 comments on commit c4b5d31

Please sign in to comment.