Returns a string with the final filename for an export. :param export: :return:
(export, session)
| 13 | logger = get_shared_logger() |
| 14 | |
| 15 | def generate_file_name_from_export(export, session): |
| 16 | """ |
| 17 | Returns a string with the final filename for an export. |
| 18 | :param export: |
| 19 | :return: |
| 20 | """ |
| 21 | |
| 22 | # TODO (low priority) switch to starting to array with "".join() it |
| 23 | # it's a bit faster and more importantly easier to read / check. |
| 24 | |
| 25 | filename = f"_diffgram_annotations__source_{str(export.source)}_" |
| 26 | |
| 27 | if export.source == "task": |
| 28 | filename += str(export.task.id) |
| 29 | |
| 30 | if export.source == "job": |
| 31 | job = Job.get_by_id( |
| 32 | session=session, |
| 33 | job_id=export.job_id) |
| 34 | if job: |
| 35 | filename += str(job.name) |
| 36 | |
| 37 | if export.source == "directory": |
| 38 | filename += str(export.working_dir.nickname) |
| 39 | |
| 40 | # Always add timestamps to avoid duplicate names. |
| 41 | filename += f"_datetime_{datetime.datetime.utcnow().isoformat()}" |
| 42 | filename = filename.replace(":", "-") |
| 43 | |
| 44 | return filename |
| 45 | |
| 46 | |
| 47 | def has_project_permissions_for_export(export, project_string_id, session): |
no test coverage detected