Skip to content

Commit 3ff4d4f

Browse files
authored
Remove TEMP_DIR (fixes #276) (#277)
* Remove TEMP_DIR * Store files in root of tmp dir * Fix unit tests * Try to re-trigger workflow * Try to re-trigger workflow
1 parent 4e9fc4f commit 3ff4d4f

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

gramps_webapi/api/resources/exporters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
import mimetypes
2727
import os
28+
import tempfile
2829
import uuid
2930
from pathlib import Path
3031
from typing import Dict
3132

3233
from flask import Response, abort, current_app, send_file
3334
from gramps.gen.const import GRAMPS_LOCALE as glocale
34-
from gramps.gen.const import TEMP_DIR
3535
from gramps.gen.errors import HandleError
3636

3737
_ = glocale.translation.gettext
@@ -137,9 +137,10 @@ def prepare_options(db_handle: DbReadBase, args: Dict):
137137

138138
def run_export(db_handle: DbReadBase, extension: str, options):
139139
"""Generate the export."""
140-
export_path = TEMP_DIR
141140
if current_app.config.get("EXPORT_DIR"):
142141
export_path = current_app.config.get("EXPORT_DIR")
142+
else:
143+
export_path = tempfile.gettempdir()
143144
file_name = os.path.join(export_path, "{}.{}".format(uuid.uuid4(), extension))
144145
_resources = ResourcePath()
145146
os.environ["GRAMPS_RESOURCES"] = str(Path(_resources.data_dir).parent)

gramps_webapi/api/resources/reports.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
import json
2323
import os
24+
import tempfile
2425
import uuid
2526
from pathlib import Path
2627
from typing import Dict
2728

2829
from flask import Response, abort, current_app, send_file
2930
from gramps.cli.plug import CommandLineReport, cl_report
30-
from gramps.gen.const import TEMP_DIR
3131
from gramps.gen.db.base import DbReadBase
3232
from gramps.gen.filters import reload_custom_filters
3333
from gramps.gen.plug import BasePluginManager
@@ -114,9 +114,10 @@ def run_report(
114114
"Can not find {} in MIME_TYPES".format(file_type)
115115
)
116116
abort(500)
117-
report_path = TEMP_DIR
118117
if current_app.config.get("REPORT_DIR"):
119118
report_path = current_app.config.get("REPORT_DIR")
119+
else:
120+
report_path = tempfile.gettempdir()
120121
file_name = os.path.join(
121122
report_path, "{}{}".format(uuid.uuid4(), file_type)
122123
)
@@ -197,7 +198,10 @@ class ReportFileResource(ProtectedResource, GrampsJSONEncoder):
197198
"""Report file resource."""
198199

199200
@use_args(
200-
{"options": fields.Str(validate=validate.Length(min=1)),}, location="query",
201+
{
202+
"options": fields.Str(validate=validate.Length(min=1)),
203+
},
204+
location="query",
201205
)
202206
def get(self, args: Dict, report_id: str) -> Response:
203207
"""Get specific report attributes."""

tests/test_endpoints/test_families.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def test_get_families_parameter_profile_expected_result(self):
451451
"age": "0 days",
452452
"citations": 0,
453453
"confidence": 0,
454-
"date": "164-03-00 (Islamic)",
454+
"date": "164-03 (Islamic)",
455455
"place": "",
456456
"type": "Birth",
457457
"summary": "Birth - , أحمد",
@@ -494,7 +494,7 @@ def test_get_families_parameter_profile_expected_result(self):
494494
"person": [
495495
{
496496
"birth": {
497-
"date": "164-03-00 (Islamic)",
497+
"date": "164-03 (Islamic)",
498498
"place": "",
499499
"type": "Birth",
500500
"summary": "Birth - , أحمد",

tests/test_endpoints/test_people.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def test_get_people_parameter_profile_expected_result(self):
520520
"age": "unknown",
521521
"citations": 0,
522522
"confidence": 0,
523-
"date": "after 1760-02-00",
523+
"date": "after 1760-02",
524524
"place": "Plattsburgh, Clinton, NY, USA",
525525
"summary": "Death - Aguilar, Eleanor",
526526
"type": "Death",
@@ -540,7 +540,7 @@ def test_get_people_parameter_profile_expected_result(self):
540540
"age": "unknown",
541541
"citations": 0,
542542
"confidence": 0,
543-
"date": "after 1760-02-00",
543+
"date": "after 1760-02",
544544
"place": "Plattsburgh, Clinton, NY, USA",
545545
"role": "Primary",
546546
"summary": "Death - Aguilar, Eleanor",
@@ -636,7 +636,7 @@ def test_get_people_parameter_profile_expected_result(self):
636636
"age": "unknown",
637637
"citations": 0,
638638
"confidence": 0,
639-
"date": "after 1760-02-00",
639+
"date": "after 1760-02",
640640
"place": "Plattsburgh, Clinton, NY, USA",
641641
"summary": "Death - Aguilar, Eleanor",
642642
"type": "Death",
@@ -670,7 +670,7 @@ def test_get_people_parameter_profile_expected_result(self):
670670
"age": "unknown",
671671
"citations": 0,
672672
"confidence": 0,
673-
"date": "after 1760-02-00",
673+
"date": "after 1760-02",
674674
"place": "Plattsburgh, Clinton, NY, USA",
675675
"summary": "Death - Aguilar, Eleanor",
676676
"type": "Death",
@@ -697,7 +697,7 @@ def test_get_people_parameter_profile_expected_result(self):
697697
"age": "unknown",
698698
"citations": 0,
699699
"confidence": 0,
700-
"date": "before 1745-02-00",
700+
"date": "before 1745-02",
701701
"place": "Wooster, OH, USA",
702702
"summary": "Death - Aguilar, John",
703703
"type": "Death",
@@ -724,7 +724,7 @@ def test_get_people_parameter_profile_expected_result(self):
724724
"type": "Birth",
725725
},
726726
"death": {
727-
"date": "after 1760-02-00",
727+
"date": "after 1760-02",
728728
"place": "Plattsburgh, Clinton, NY, USA",
729729
"summary": "Death - Aguilar, Eleanor",
730730
"type": "Death",
@@ -745,7 +745,7 @@ def test_get_people_parameter_profile_expected_result(self):
745745
"type": "Birth",
746746
},
747747
"death": {
748-
"date": "before 1745-02-00",
748+
"date": "before 1745-02",
749749
"place": "Wooster, OH, USA",
750750
"summary": "Death - Aguilar, John",
751751
"type": "Death",
@@ -817,7 +817,7 @@ def test_get_people_parameter_profile_expected_result(self):
817817
"type": "Birth",
818818
},
819819
"death": {
820-
"date": "after 1760-02-00",
820+
"date": "after 1760-02",
821821
"place": "Plattsburgh, Clinton, NY, USA",
822822
"summary": "Death - Aguilar, Eleanor",
823823
"type": "Death",

0 commit comments

Comments
 (0)