20462: Refactor "common prefix" function & fix fencepost errors
[arvados.git] / sdk / cwl / arvados_cwl / context.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 from cwltool.context import LoadingContext, RuntimeContext
6 from collections import namedtuple
7
8 class ArvLoadingContext(LoadingContext):
9     def __init__(self, kwargs=None):
10         super(ArvLoadingContext, self).__init__(kwargs)
11
12 class ArvRuntimeContext(RuntimeContext):
13     def __init__(self, kwargs=None):
14         self.work_api = None
15         self.extra_reffiles = []
16         self.priority = 500
17         self.enable_reuse = True
18         self.runnerjob = ""
19         self.submit_request_uuid = None
20         self.project_uuid = None
21         self.trash_intermediate = False
22         self.intermediate_output_ttl = 0
23         self.update_workflow = ""
24         self.create_workflow = False
25         self.submit_runner_ram = 0
26         self.ignore_docker_for_reuse = False
27         self.submit = True
28         self.submit_runner_image = None
29         self.wait = True
30         self.cwl_runner_job = None
31         self.storage_classes = "default"
32         self.intermediate_storage_classes = "default"
33         self.current_container = None
34         self.http_timeout = 300
35         self.submit_runner_cluster = None
36         self.cluster_target_id = 0
37         self.always_submit_runner = False
38         self.collection_cache_size = 256
39         self.match_local_docker = False
40         self.enable_preemptible = None
41         self.copy_deps = None
42         self.defer_downloads = False
43         self.varying_url_params = ""
44         self.prefer_cached_downloads = False
45         self.cached_docker_lookups = {}
46
47         super(ArvRuntimeContext, self).__init__(kwargs)
48
49         if self.submit_request_uuid:
50             self.submit_runner_cluster = self.submit_request_uuid[0:5]
51
52     def get_outdir(self) -> str:
53         """Return self.outdir or create one with self.tmp_outdir_prefix."""
54         return self.outdir
55
56     def get_tmpdir(self) -> str:
57         """Return self.tmpdir or create one with self.tmpdir_prefix."""
58         return self.tmpdir
59
60     def create_tmpdir(self) -> str:
61         """Return self.tmpdir or create one with self.tmpdir_prefix."""
62         return self.tmpdir