Skip to content

Commit

Permalink
Print export path if success
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJiahao committed Dec 11, 2023
1 parent c28315b commit 6ebf1a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/infrastructure/bibtex_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
class BibtexExporter:
"""Luokka, joka vastaa viitteiden muuntamisesta BibTeX-muotoon."""

def export(self, path: str, cites: list[Cite]) -> None:
def export(self, path: str, cites: list[Cite]) -> str:
"""
Kirjoittaa viitteet BiBTeX-muodossa tiedostoon.
Args:
path (str): Polku kirjoitettavaan tiedostoon.
cites (list[Cite]): Kirjoitettavat viitteet.
Returns:
str: Polku, johon viitteet tallennettiin.
"""

file_basename, file_extension = os.path.splitext(path)
Expand All @@ -25,6 +28,8 @@ def export(self, path: str, cites: list[Cite]) -> None:
with open(path, mode="w", encoding="utf-8") as file:
file.write(data)

return path

def __dump(self, cites: list[Cite]) -> str:
"""Palauttaa viitteet BibTeX-muodossa, aakkosjärjestyksessä id:n perusteella.
Expand Down
9 changes: 7 additions & 2 deletions src/services/export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, exporters: dict | None = None) -> None:

self.__exporters: dict = exporters or {"bibtex": BibtexExporter()}

def export(self, path: str, format: str, cites: list[Cite]) -> None:
def export(self, path: str, format: str, cites: list[Cite]) -> str:
"""
Kirjoittaa viitteet annettuun tiedostoon.
Expand All @@ -27,12 +27,17 @@ def export(self, path: str, format: str, cites: list[Cite]) -> None:
format (str): Tiedostomuoto. Tuetut muodot: bibtex
cites (list[Cite]): Kirjoitettavat viitteet.
Returns:
str: Polku, johon viitteet tallennettiin.
Raises:
ValueError: Tiedostomuoto ei ole tuettu.
"""

try:
self.__exporters[format].export(path, cites)
path = self.__exporters[format].export(path, cites)

return path

except KeyError as exception:
raise ValueError(
Expand Down
14 changes: 12 additions & 2 deletions src/services/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,18 @@ def remove_all_cites(self) -> None:

self.repository.remove_all_cites()

def export(self, path: str, format: str, cites: list[Cite]) -> None:
"""Kirjoittaa viitteet tiedostoon"""
def export(self, path: str, format: str, cites: list[Cite]) -> str:
"""
Tallentaa viitteet annettuun tiedostoon.
Args:
path (str): Polku, johon tallennetaan.
format (str): Tiedostomuoto.
cites (list[Cite]): Tallennettavat viitteet.
Returns:
str: Polku, johon tallennettiin.
"""

service = ExportService()
return service.export(path, format, cites)
4 changes: 3 additions & 1 deletion src/ui/export_cite_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ def start(self) -> None:
else:
path = os.path.join(DATA_DIRECTORY, name)

self._logic.export(path, "bibtex", self._logic.get_all_cites())
path = self._logic.export(path, "bibtex", self._logic.get_all_cites())

self._io.write(f"Viitteet tallennettu polkuun {os.path.abspath(path)}")

0 comments on commit 6ebf1a6

Please sign in to comment.