psr-factory 4.1.0b5__py3-none-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- psr/apps/__init__.py +7 -0
- psr/apps/apps.py +232 -0
- psr/apps/version.py +5 -0
- psr/cloud/__init__.py +7 -0
- psr/cloud/cloud.py +1079 -0
- psr/cloud/data.py +105 -0
- psr/cloud/desktop.py +82 -0
- psr/cloud/log.py +40 -0
- psr/cloud/status.py +81 -0
- psr/cloud/tempfile.py +117 -0
- psr/cloud/version.py +5 -0
- psr/cloud/xml.py +55 -0
- psr/factory/__init__.py +7 -0
- psr/factory/api.py +2339 -0
- psr/factory/factory.pmd +6830 -0
- psr/factory/factory.pmk +18299 -0
- psr/factory/factorylib.py +366 -0
- psr/factory/libfactory.so +0 -0
- psr/factory/py.typed +0 -0
- psr/psrfcommon/__init__.py +6 -0
- psr/psrfcommon/psrfcommon.py +54 -0
- psr/psrfcommon/tempfile.py +118 -0
- psr/runner/__init__.py +7 -0
- psr/runner/runner.py +649 -0
- psr/runner/version.py +5 -0
- psr_factory-4.1.0b5.dist-info/METADATA +86 -0
- psr_factory-4.1.0b5.dist-info/RECORD +30 -0
- psr_factory-4.1.0b5.dist-info/WHEEL +5 -0
- psr_factory-4.1.0b5.dist-info/licenses/LICENSE.txt +21 -0
- psr_factory-4.1.0b5.dist-info/top_level.txt +1 -0
@@ -0,0 +1,366 @@
|
|
1
|
+
# PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
3
|
+
# Proprietary and confidential
|
4
|
+
|
5
|
+
import ctypes
|
6
|
+
import os
|
7
|
+
import sys
|
8
|
+
|
9
|
+
import psr.psrfcommon
|
10
|
+
|
11
|
+
|
12
|
+
lib = None
|
13
|
+
|
14
|
+
if sys.platform == "win32":
|
15
|
+
def get_lib_path() -> str:
|
16
|
+
return os.path.join(os.path.dirname(__file__), "factory.dll")
|
17
|
+
def load_lib():
|
18
|
+
return ctypes.cdll.LoadLibrary(get_lib_path())
|
19
|
+
else:
|
20
|
+
def get_lib_path() -> str:
|
21
|
+
return os.path.join(os.path.dirname(__file__), "libfactory.so")
|
22
|
+
def load_lib():
|
23
|
+
with psr.psrfcommon.change_cwd(os.path.dirname(__file__)):
|
24
|
+
lib_path = "./libfactory.so"
|
25
|
+
return ctypes.cdll.LoadLibrary(lib_path)
|
26
|
+
|
27
|
+
|
28
|
+
def initialize():
|
29
|
+
global lib
|
30
|
+
lib = load_lib()
|
31
|
+
|
32
|
+
lib.psrd_initialize.restype = ctypes.c_int
|
33
|
+
lib.psrd_initialize.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
34
|
+
lib.psrd_unload.restype = ctypes.c_int
|
35
|
+
lib.psrd_unload.argtypes = [ctypes.c_void_p]
|
36
|
+
lib.psrd_set_global_setting.restype = ctypes.c_int
|
37
|
+
lib.psrd_set_global_setting.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
38
|
+
lib.psrd_get_global_setting.restype = ctypes.c_int
|
39
|
+
lib.psrd_get_global_setting.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
40
|
+
lib.psrd_set_binding_property.restype = ctypes.c_int
|
41
|
+
lib.psrd_set_binding_property.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
42
|
+
lib.psrd_version_short.restype = ctypes.c_int
|
43
|
+
lib.psrd_version_short.argtypes = [ctypes.c_char_p, ctypes.c_long]
|
44
|
+
lib.psrd_version_long.restype = ctypes.c_int
|
45
|
+
lib.psrd_version_long.argtypes = [ctypes.c_char_p, ctypes.c_long]
|
46
|
+
lib.psrd_help.restype = ctypes.c_int
|
47
|
+
lib.psrd_help.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
48
|
+
lib.psrd_set_log_level.restype = ctypes.c_int
|
49
|
+
lib.psrd_set_log_level.argtypes = [ctypes.c_long]
|
50
|
+
lib.psrd_get_log_level.restype = ctypes.c_int
|
51
|
+
lib.psrd_get_log_level.argtypes = [ctypes.POINTER(ctypes.c_long)]
|
52
|
+
lib.psrd_set_debug_mode.restype = ctypes.c_int
|
53
|
+
lib.psrd_set_debug_mode.argtypes = [ctypes.c_long]
|
54
|
+
lib.psrd_get_default_context.restype = ctypes.c_void_p
|
55
|
+
lib.psrd_get_default_context.argtypes = [ctypes.c_void_p]
|
56
|
+
lib.psrd_new_error.restype = ctypes.c_void_p
|
57
|
+
lib.psrd_new_error.argtypes = []
|
58
|
+
lib.psrd_error_code.restype = ctypes.c_int
|
59
|
+
lib.psrd_error_code.argtypes = [ctypes.c_void_p]
|
60
|
+
lib.psrd_error_message.restype = ctypes.c_int
|
61
|
+
lib.psrd_error_message.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long]
|
62
|
+
lib.psrd_free_error.restype = ctypes.c_int
|
63
|
+
lib.psrd_free_error.argtypes = [ctypes.c_void_p]
|
64
|
+
lib.psrd_study_load.restype = ctypes.c_void_p
|
65
|
+
lib.psrd_study_load.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
66
|
+
lib.psrd_study_save.restype = ctypes.c_int
|
67
|
+
lib.psrd_study_save.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
68
|
+
lib.psrd_study_load_settings.restype = ctypes.c_void_p
|
69
|
+
lib.psrd_study_load_settings.argtypes = [ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
70
|
+
lib.psrd_study_save_settings.restype = ctypes.c_int
|
71
|
+
lib.psrd_study_save_settings.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
72
|
+
lib.psrd_study_create.restype = ctypes.c_void_p
|
73
|
+
lib.psrd_study_create.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
74
|
+
lib.psrd_study_is_equals_to.restype = ctypes.c_int
|
75
|
+
lib.psrd_study_is_equals_to.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
76
|
+
lib.psrd_study_get_handler.restype = ctypes.c_longlong
|
77
|
+
lib.psrd_study_get_handler.argtypes = [ctypes.c_void_p]
|
78
|
+
lib.psrd_study_clone.restype = ctypes.c_void_p
|
79
|
+
lib.psrd_study_clone.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
80
|
+
lib.psrd_study_context.restype = ctypes.c_void_p
|
81
|
+
lib.psrd_study_context.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
82
|
+
lib.psrd_free_study.restype = ctypes.c_int
|
83
|
+
lib.psrd_free_study.argtypes = [ctypes.c_void_p]
|
84
|
+
lib.psrd_study_property_description_count.restype = ctypes.c_int
|
85
|
+
lib.psrd_study_property_description_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
86
|
+
lib.psrd_study_get_property_description.restype = ctypes.c_void_p
|
87
|
+
lib.psrd_study_get_property_description.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p]
|
88
|
+
lib.psrd_study_set_value.restype = ctypes.c_int
|
89
|
+
lib.psrd_study_set_value.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
90
|
+
lib.psrd_study_set_value_at.restype = ctypes.c_int
|
91
|
+
lib.psrd_study_set_value_at.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
92
|
+
lib.psrd_study_set_from_dict.restype = ctypes.c_int
|
93
|
+
lib.psrd_study_set_from_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
94
|
+
lib.psrd_study_get_value.restype = ctypes.c_int
|
95
|
+
lib.psrd_study_get_value.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p]
|
96
|
+
lib.psrd_study_get_value_at.restype = ctypes.c_int
|
97
|
+
lib.psrd_study_get_value_at.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
98
|
+
lib.psrd_study_get_as_dict.restype = ctypes.c_void_p
|
99
|
+
lib.psrd_study_get_as_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
100
|
+
lib.psrd_study_get_table.restype = ctypes.c_int
|
101
|
+
lib.psrd_study_get_table.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
102
|
+
lib.psrd_study_set_table.restype = ctypes.c_int
|
103
|
+
lib.psrd_study_set_table.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
104
|
+
lib.psrd_study_clear_values.restype = ctypes.c_int
|
105
|
+
lib.psrd_study_clear_values.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
106
|
+
lib.psrd_study_get_objects_values.restype = ctypes.c_int
|
107
|
+
lib.psrd_study_get_objects_values.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p]
|
108
|
+
lib.psrd_study_get_objects_values_at.restype = ctypes.c_int
|
109
|
+
lib.psrd_study_get_objects_values_at.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
110
|
+
lib.psrd_study_get_date_iterator_from_start.restype = ctypes.c_int
|
111
|
+
lib.psrd_study_get_date_iterator_from_start.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
112
|
+
lib.psrd_create.restype = ctypes.c_void_p
|
113
|
+
lib.psrd_create.argtypes = [ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p]
|
114
|
+
lib.psrd_study_add.restype = ctypes.c_int
|
115
|
+
lib.psrd_study_add.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
116
|
+
lib.psrd_study_remove.restype = ctypes.c_int
|
117
|
+
lib.psrd_study_remove.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
118
|
+
lib.psrd_study_get_all_objects.restype = ctypes.c_void_p
|
119
|
+
lib.psrd_study_get_all_objects.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
120
|
+
lib.psrd_study_find.restype = ctypes.c_void_p
|
121
|
+
lib.psrd_study_find.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p]
|
122
|
+
lib.psrd_study_find_by_id.restype = ctypes.c_void_p
|
123
|
+
lib.psrd_study_find_by_id.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p]
|
124
|
+
lib.psrd_study_find_by_code.restype = ctypes.c_void_p
|
125
|
+
lib.psrd_study_find_by_code.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_void_p]
|
126
|
+
lib.psrd_free_object.restype = ctypes.c_int
|
127
|
+
lib.psrd_free_object.argtypes = [ctypes.c_void_p]
|
128
|
+
lib.psrd_object_is_equals_to.restype = ctypes.c_int
|
129
|
+
lib.psrd_object_is_equals_to.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
130
|
+
lib.psrd_object_get_handler.restype = ctypes.c_longlong
|
131
|
+
lib.psrd_object_get_handler.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
132
|
+
lib.psrd_object_clone.restype = ctypes.c_void_p
|
133
|
+
lib.psrd_object_clone.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
134
|
+
lib.psrd_object_context.restype = ctypes.c_void_p
|
135
|
+
lib.psrd_object_context.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
136
|
+
lib.psrd_object_get_parent.restype = ctypes.c_void_p
|
137
|
+
lib.psrd_object_get_parent.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
138
|
+
lib.psrd_object_get_type.restype = ctypes.c_int
|
139
|
+
lib.psrd_object_get_type.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
140
|
+
lib.psrd_object_get_code.restype = ctypes.c_int
|
141
|
+
lib.psrd_object_get_code.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
142
|
+
lib.psrd_object_set_code.restype = ctypes.c_int
|
143
|
+
lib.psrd_object_set_code.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
|
144
|
+
lib.psrd_object_get_name.restype = ctypes.c_int
|
145
|
+
lib.psrd_object_get_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
146
|
+
lib.psrd_object_set_name.restype = ctypes.c_int
|
147
|
+
lib.psrd_object_set_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
148
|
+
lib.psrd_object_get_id.restype = ctypes.c_int
|
149
|
+
lib.psrd_object_get_id.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
150
|
+
lib.psrd_object_set_id.restype = ctypes.c_int
|
151
|
+
lib.psrd_object_set_id.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
152
|
+
lib.psrd_object_property_description_count.restype = ctypes.c_int
|
153
|
+
lib.psrd_object_property_description_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
154
|
+
lib.psrd_object_get_property_description.restype = ctypes.c_void_p
|
155
|
+
lib.psrd_object_get_property_description.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p]
|
156
|
+
lib.psrd_object_set_value.restype = ctypes.c_int
|
157
|
+
lib.psrd_object_set_value.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
158
|
+
lib.psrd_object_set_value_at.restype = ctypes.c_int
|
159
|
+
lib.psrd_object_set_value_at.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
160
|
+
lib.psrd_object_set_from_dict.restype = ctypes.c_int
|
161
|
+
lib.psrd_object_set_from_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
162
|
+
lib.psrd_object_get_value.restype = ctypes.c_int
|
163
|
+
lib.psrd_object_get_value.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p]
|
164
|
+
lib.psrd_object_get_value_at.restype = ctypes.c_int
|
165
|
+
lib.psrd_object_get_value_at.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
166
|
+
lib.psrd_object_get_as_dict.restype = ctypes.c_void_p
|
167
|
+
lib.psrd_object_get_as_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
168
|
+
lib.psrd_object_get_table.restype = ctypes.c_int
|
169
|
+
lib.psrd_object_get_table.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
170
|
+
lib.psrd_object_set_table.restype = ctypes.c_int
|
171
|
+
lib.psrd_object_set_table.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
172
|
+
lib.psrd_object_clear_values.restype = ctypes.c_int
|
173
|
+
lib.psrd_object_clear_values.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
174
|
+
lib.psrd_object_referenced_by.restype = ctypes.c_void_p
|
175
|
+
lib.psrd_object_referenced_by.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
176
|
+
lib.psrd_new_value.restype = ctypes.c_void_p
|
177
|
+
lib.psrd_new_value.argtypes = []
|
178
|
+
lib.psrd_free_value.restype = ctypes.c_int
|
179
|
+
lib.psrd_free_value.argtypes = [ctypes.c_void_p]
|
180
|
+
lib.psrd_value_get_type.restype = ctypes.c_int
|
181
|
+
lib.psrd_value_get_type.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
182
|
+
lib.psrd_value_get_int32.restype = ctypes.c_int
|
183
|
+
lib.psrd_value_get_int32.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
184
|
+
lib.psrd_value_set_int32.restype = ctypes.c_int
|
185
|
+
lib.psrd_value_set_int32.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p]
|
186
|
+
lib.psrd_value_get_int64.restype = ctypes.c_int
|
187
|
+
lib.psrd_value_get_int64.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
188
|
+
lib.psrd_value_set_int64.restype = ctypes.c_int
|
189
|
+
lib.psrd_value_set_int64.argtypes = [ctypes.c_void_p, ctypes.c_longlong, ctypes.c_void_p]
|
190
|
+
lib.psrd_value_get_bool.restype = ctypes.c_int
|
191
|
+
lib.psrd_value_get_bool.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
192
|
+
lib.psrd_value_set_bool.restype = ctypes.c_int
|
193
|
+
lib.psrd_value_set_bool.argtypes = [ctypes.c_void_p, ctypes.c_short, ctypes.c_void_p]
|
194
|
+
lib.psrd_value_get_date.restype = ctypes.c_int
|
195
|
+
lib.psrd_value_get_date.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
196
|
+
lib.psrd_value_set_date.restype = ctypes.c_int
|
197
|
+
lib.psrd_value_set_date.argtypes = [ctypes.c_void_p, ctypes.c_longlong, ctypes.c_void_p]
|
198
|
+
lib.psrd_value_get_float32.restype = ctypes.c_int
|
199
|
+
lib.psrd_value_get_float32.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float), ctypes.c_void_p]
|
200
|
+
lib.psrd_value_set_float32.restype = ctypes.c_int
|
201
|
+
lib.psrd_value_set_float32.argtypes = [ctypes.c_void_p, ctypes.c_float, ctypes.c_void_p]
|
202
|
+
lib.psrd_value_get_float64.restype = ctypes.c_int
|
203
|
+
lib.psrd_value_get_float64.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_double), ctypes.c_void_p]
|
204
|
+
lib.psrd_value_set_float64.restype = ctypes.c_int
|
205
|
+
lib.psrd_value_set_float64.argtypes = [ctypes.c_void_p, ctypes.c_double, ctypes.c_void_p]
|
206
|
+
lib.psrd_value_get_string.restype = ctypes.c_int
|
207
|
+
lib.psrd_value_get_string.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
208
|
+
lib.psrd_value_set_string.restype = ctypes.c_int
|
209
|
+
lib.psrd_value_set_string.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
210
|
+
lib.psrd_value_get_object.restype = ctypes.c_void_p
|
211
|
+
lib.psrd_value_get_object.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
212
|
+
lib.psrd_value_set_object.restype = ctypes.c_int
|
213
|
+
lib.psrd_value_set_object.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
214
|
+
lib.psrd_value_get_list.restype = ctypes.c_void_p
|
215
|
+
lib.psrd_value_get_list.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
216
|
+
lib.psrd_value_set_list.restype = ctypes.c_int
|
217
|
+
lib.psrd_value_set_list.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
218
|
+
lib.psrd_value_get_dict.restype = ctypes.c_void_p
|
219
|
+
lib.psrd_value_get_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
220
|
+
lib.psrd_value_set_dict.restype = ctypes.c_int
|
221
|
+
lib.psrd_value_set_dict.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
222
|
+
lib.psrd_value_set_null.restype = ctypes.c_int
|
223
|
+
lib.psrd_value_set_null.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
224
|
+
lib.psrd_value_is_null.restype = ctypes.c_int
|
225
|
+
lib.psrd_value_is_null.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
226
|
+
lib.psrd_new_list.restype = ctypes.c_void_p
|
227
|
+
lib.psrd_new_list.argtypes = []
|
228
|
+
lib.psrd_free_list.restype = ctypes.c_int
|
229
|
+
lib.psrd_free_list.argtypes = [ctypes.c_void_p]
|
230
|
+
lib.psrd_list_count.restype = ctypes.c_int
|
231
|
+
lib.psrd_list_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
232
|
+
lib.psrd_list_clear.restype = ctypes.c_int
|
233
|
+
lib.psrd_list_clear.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
234
|
+
lib.psrd_list_get.restype = ctypes.c_int
|
235
|
+
lib.psrd_list_get.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
236
|
+
lib.psrd_list_set.restype = ctypes.c_int
|
237
|
+
lib.psrd_list_set.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
238
|
+
lib.psrd_list_append.restype = ctypes.c_int
|
239
|
+
lib.psrd_list_append.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
240
|
+
lib.psrd_new_dict.restype = ctypes.c_void_p
|
241
|
+
lib.psrd_new_dict.argtypes = []
|
242
|
+
lib.psrd_free_dict.restype = ctypes.c_int
|
243
|
+
lib.psrd_free_dict.argtypes = [ctypes.c_void_p]
|
244
|
+
lib.psrd_dict_count.restype = ctypes.c_int
|
245
|
+
lib.psrd_dict_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
246
|
+
lib.psrd_dict_clear.restype = ctypes.c_int
|
247
|
+
lib.psrd_dict_clear.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
248
|
+
lib.psrd_dict_get_by_key.restype = ctypes.c_int
|
249
|
+
lib.psrd_dict_get_by_key.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
250
|
+
lib.psrd_dict_get_by_index.restype = ctypes.c_int
|
251
|
+
lib.psrd_dict_get_by_index.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
252
|
+
lib.psrd_dict_get_key_by_index.restype = ctypes.c_int
|
253
|
+
lib.psrd_dict_get_key_by_index.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
254
|
+
lib.psrd_dict_get_value_by_index.restype = ctypes.c_int
|
255
|
+
lib.psrd_dict_get_value_by_index.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
256
|
+
lib.psrd_dict_set.restype = ctypes.c_int
|
257
|
+
lib.psrd_dict_set.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
258
|
+
lib.psrd_free_property_description.restype = ctypes.c_int
|
259
|
+
lib.psrd_free_property_description.argtypes = [ctypes.c_void_p]
|
260
|
+
lib.psrd_property_description_get_name.restype = ctypes.c_int
|
261
|
+
lib.psrd_property_description_get_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
262
|
+
lib.psrd_property_description_get_alternative_name.restype = ctypes.c_int
|
263
|
+
lib.psrd_property_description_get_alternative_name.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
264
|
+
lib.psrd_property_description_dimensions_count.restype = ctypes.c_int
|
265
|
+
lib.psrd_property_description_dimensions_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
266
|
+
lib.psrd_property_description_get_type.restype = ctypes.c_int
|
267
|
+
lib.psrd_property_description_get_type.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
268
|
+
lib.psrd_property_description_get_dimension_size.restype = ctypes.c_int
|
269
|
+
lib.psrd_property_description_get_dimension_size.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
270
|
+
lib.psrd_property_description_get_dimension_name.restype = ctypes.c_int
|
271
|
+
lib.psrd_property_description_get_dimension_name.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
272
|
+
lib.psrd_property_description_is_dynamic.restype = ctypes.c_int
|
273
|
+
lib.psrd_property_description_is_dynamic.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
274
|
+
lib.psrd_property_description_is_indexed.restype = ctypes.c_int
|
275
|
+
lib.psrd_property_description_is_indexed.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
276
|
+
lib.psrd_property_description_is_grouped.restype = ctypes.c_int
|
277
|
+
lib.psrd_property_description_is_grouped.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
278
|
+
lib.psrd_property_description_grouped_with.restype = ctypes.c_void_p
|
279
|
+
lib.psrd_property_description_grouped_with.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
|
280
|
+
lib.psrd_new_table.restype = ctypes.c_void_p
|
281
|
+
lib.psrd_new_table.argtypes = []
|
282
|
+
lib.psrd_free_table.restype = ctypes.c_int
|
283
|
+
lib.psrd_free_table.argtypes = [ctypes.c_void_p]
|
284
|
+
lib.psrd_table_load.restype = ctypes.c_int
|
285
|
+
lib.psrd_table_load.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
286
|
+
lib.psrd_table_save.restype = ctypes.c_int
|
287
|
+
lib.psrd_table_save.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
288
|
+
lib.psrd_table_is_indexed.restype = ctypes.c_int
|
289
|
+
lib.psrd_table_is_indexed.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
290
|
+
lib.psrd_table_resize.restype = ctypes.c_int
|
291
|
+
lib.psrd_table_resize.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p]
|
292
|
+
lib.psrd_table_configure_index.restype = ctypes.c_int
|
293
|
+
lib.psrd_table_configure_index.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p]
|
294
|
+
lib.psrd_table_configure_column.restype = ctypes.c_int
|
295
|
+
lib.psrd_table_configure_column.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p]
|
296
|
+
lib.psrd_table_columns_count.restype = ctypes.c_int
|
297
|
+
lib.psrd_table_columns_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
298
|
+
lib.psrd_table_column_get_name.restype = ctypes.c_int
|
299
|
+
lib.psrd_table_column_get_name.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
300
|
+
lib.psrd_table_column_set_name.restype = ctypes.c_int
|
301
|
+
lib.psrd_table_column_set_name.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
302
|
+
lib.psrd_table_column_values_count.restype = ctypes.c_int
|
303
|
+
lib.psrd_table_column_values_count.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
304
|
+
lib.psrd_table_column_get_value.restype = ctypes.c_int
|
305
|
+
lib.psrd_table_column_get_value.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
306
|
+
lib.psrd_table_column_set_value.restype = ctypes.c_int
|
307
|
+
lib.psrd_table_column_set_value.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
308
|
+
lib.psrd_table_rows_count.restype = ctypes.c_int
|
309
|
+
lib.psrd_table_rows_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
310
|
+
lib.psrd_table_index_count.restype = ctypes.c_int
|
311
|
+
lib.psrd_table_index_count.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_long), ctypes.c_void_p]
|
312
|
+
lib.psrd_table_index_get_name.restype = ctypes.c_int
|
313
|
+
lib.psrd_table_index_get_name.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
314
|
+
lib.psrd_table_index_set_name.restype = ctypes.c_int
|
315
|
+
lib.psrd_table_index_set_name.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
316
|
+
lib.psrd_table_index_get_value.restype = ctypes.c_int
|
317
|
+
lib.psrd_table_index_get_value.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
318
|
+
lib.psrd_table_index_set_value.restype = ctypes.c_int
|
319
|
+
lib.psrd_table_index_set_value.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_long, ctypes.c_void_p, ctypes.c_void_p]
|
320
|
+
lib.psrd_table_column_set_float32_values.restype = ctypes.c_int
|
321
|
+
lib.psrd_table_column_set_float32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_float), ctypes.c_void_p]
|
322
|
+
lib.psrd_table_column_set_float64_values.restype = ctypes.c_int
|
323
|
+
lib.psrd_table_column_set_float64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_double), ctypes.c_void_p]
|
324
|
+
lib.psrd_table_column_set_int_values.restype = ctypes.c_int
|
325
|
+
lib.psrd_table_column_set_int_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
326
|
+
lib.psrd_table_column_set_date_values.restype = ctypes.c_int
|
327
|
+
lib.psrd_table_column_set_date_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
328
|
+
lib.psrd_table_column_set_null_values.restype = ctypes.c_int
|
329
|
+
lib.psrd_table_column_set_null_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_void_p]
|
330
|
+
lib.psrd_table_index_set_int32_values.restype = ctypes.c_int
|
331
|
+
lib.psrd_table_index_set_int32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
332
|
+
lib.psrd_table_index_set_int64_values.restype = ctypes.c_int
|
333
|
+
lib.psrd_table_index_set_int64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
334
|
+
lib.psrd_table_index_set_float32_values.restype = ctypes.c_int
|
335
|
+
lib.psrd_table_index_set_float32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_float), ctypes.c_void_p]
|
336
|
+
lib.psrd_table_index_set_float64_values.restype = ctypes.c_int
|
337
|
+
lib.psrd_table_index_set_float64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_double), ctypes.c_void_p]
|
338
|
+
lib.psrd_table_index_set_date_values.restype = ctypes.c_int
|
339
|
+
lib.psrd_table_index_set_date_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
340
|
+
lib.psrd_table_column_get_float32_values.restype = ctypes.c_int
|
341
|
+
lib.psrd_table_column_get_float32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_float), ctypes.c_void_p]
|
342
|
+
lib.psrd_table_column_get_float64_values.restype = ctypes.c_int
|
343
|
+
lib.psrd_table_column_get_float64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_double), ctypes.c_void_p]
|
344
|
+
lib.psrd_table_column_get_int32_values.restype = ctypes.c_int
|
345
|
+
lib.psrd_table_column_get_int32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
346
|
+
lib.psrd_table_column_get_int64_values.restype = ctypes.c_int
|
347
|
+
lib.psrd_table_column_get_int64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
348
|
+
lib.psrd_table_column_get_date_values.restype = ctypes.c_int
|
349
|
+
lib.psrd_table_column_get_date_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
350
|
+
lib.psrd_table_index_get_int32_values.restype = ctypes.c_int
|
351
|
+
lib.psrd_table_index_get_int32_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_int), ctypes.c_void_p]
|
352
|
+
lib.psrd_table_index_get_int64_values.restype = ctypes.c_int
|
353
|
+
lib.psrd_table_index_get_int64_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
354
|
+
lib.psrd_table_index_get_date_values.restype = ctypes.c_int
|
355
|
+
lib.psrd_table_index_get_date_values.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.POINTER(ctypes.c_longlong), ctypes.c_void_p]
|
356
|
+
lib.psrd_new_date_iterator.restype = ctypes.c_void_p
|
357
|
+
lib.psrd_new_date_iterator.argtypes = []
|
358
|
+
lib.psrd_free_date_iterator.restype = ctypes.c_int
|
359
|
+
lib.psrd_free_date_iterator.argtypes = [ctypes.c_void_p]
|
360
|
+
lib.psrd_date_iterator_at_start.restype = ctypes.c_int
|
361
|
+
lib.psrd_date_iterator_at_start.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
362
|
+
lib.psrd_date_iterator_at_end.restype = ctypes.c_int
|
363
|
+
lib.psrd_date_iterator_at_end.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_bool), ctypes.c_void_p]
|
364
|
+
lib.psrd_date_iterator_get_value.restype = ctypes.c_int
|
365
|
+
lib.psrd_date_iterator_get_value.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_long, ctypes.c_void_p]
|
366
|
+
|
Binary file
|
psr/factory/py.typed
ADDED
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
3
|
+
# Proprietary and confidential
|
4
|
+
|
5
|
+
import os
|
6
|
+
import pathlib
|
7
|
+
import subprocess
|
8
|
+
import sys
|
9
|
+
from contextlib import contextmanager
|
10
|
+
from typing import Union, List
|
11
|
+
|
12
|
+
|
13
|
+
@contextmanager
|
14
|
+
def change_cwd(new_dir: Union[str, pathlib.Path]):
|
15
|
+
last_dir = os.getcwd()
|
16
|
+
os.chdir(new_dir)
|
17
|
+
try:
|
18
|
+
yield
|
19
|
+
finally:
|
20
|
+
os.chdir(last_dir)
|
21
|
+
|
22
|
+
|
23
|
+
def exec_cmd(cmd: Union[str, List[str]], **kwargs) -> int:
|
24
|
+
dry_run = kwargs.get("dry_run", False)
|
25
|
+
print_progress = kwargs.get("show_progress", False)
|
26
|
+
|
27
|
+
if print_progress or dry_run:
|
28
|
+
sys.stdout.flush()
|
29
|
+
|
30
|
+
if dry_run:
|
31
|
+
if isinstance(cmd, list):
|
32
|
+
print(" ".join(cmd))
|
33
|
+
else:
|
34
|
+
print(cmd)
|
35
|
+
return_code = 0
|
36
|
+
else:
|
37
|
+
try:
|
38
|
+
return_code = subprocess.call(cmd, shell=True)
|
39
|
+
if return_code > 0:
|
40
|
+
raise RuntimeError(f"Execution error, code {return_code}")
|
41
|
+
else:
|
42
|
+
if print_progress:
|
43
|
+
print("Execution success", return_code)
|
44
|
+
except OSError as e:
|
45
|
+
msg = f"Execution failed: {e}"
|
46
|
+
if print_progress:
|
47
|
+
print(msg, file=sys.stderr)
|
48
|
+
raise RuntimeError(msg)
|
49
|
+
|
50
|
+
if print_progress or dry_run:
|
51
|
+
sys.stdout.flush()
|
52
|
+
return return_code
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# PSR Factory. Copyright (C) PSR, Inc - All Rights Reserved
|
2
|
+
# Unauthorized copying of this file, via any medium is strictly prohibited
|
3
|
+
# Proprietary and confidential
|
4
|
+
|
5
|
+
import errno
|
6
|
+
import io
|
7
|
+
import os
|
8
|
+
from random import Random
|
9
|
+
|
10
|
+
|
11
|
+
class _RandomNameSequence:
|
12
|
+
"""An instance of _RandomNameSequence generates an endless
|
13
|
+
sequence of unpredictable strings which can safely be incorporated
|
14
|
+
into file names. Each string is eight characters long. Multiple
|
15
|
+
threads can safely use the same instance at the same time.
|
16
|
+
|
17
|
+
_RandomNameSequence is an iterator."""
|
18
|
+
|
19
|
+
# Method extracted from tempfile Python's module.
|
20
|
+
|
21
|
+
characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
|
22
|
+
|
23
|
+
@property
|
24
|
+
def rng(self):
|
25
|
+
cur_pid = os.getpid()
|
26
|
+
if cur_pid != getattr(self, "_rng_pid", None):
|
27
|
+
self._rng = Random() # nosec
|
28
|
+
self._rng_pid = cur_pid
|
29
|
+
return self._rng
|
30
|
+
|
31
|
+
def __iter__(self):
|
32
|
+
return self
|
33
|
+
|
34
|
+
def __next__(self):
|
35
|
+
c = self.characters
|
36
|
+
choose = self.rng.choice
|
37
|
+
letters = [choose(c) for dummy in range(8)]
|
38
|
+
return "".join(letters)
|
39
|
+
|
40
|
+
|
41
|
+
def _get_tempfile_name(base_path: str, prefix: str):
|
42
|
+
"""Calculate the default directory to use for temporary files.
|
43
|
+
This routine should be called exactly once.
|
44
|
+
|
45
|
+
We determine whether a candidate temp dir is usable by
|
46
|
+
trying to create and write to a file in that directory. If this
|
47
|
+
is successful, the test file is deleted. To prevent denial of
|
48
|
+
service, the name of the test file must be randomized."""
|
49
|
+
# Method extracted from tempfile Python's module.
|
50
|
+
|
51
|
+
_text_openflags = os.O_RDWR | os.O_CREAT | os.O_EXCL
|
52
|
+
if hasattr(os, "O_NOFOLLOW"):
|
53
|
+
_text_openflags |= os.O_NOFOLLOW
|
54
|
+
|
55
|
+
_bin_openflags = _text_openflags
|
56
|
+
if hasattr(os, "O_BINARY"):
|
57
|
+
_bin_openflags |= os.O_BINARY
|
58
|
+
|
59
|
+
namer = _RandomNameSequence()
|
60
|
+
|
61
|
+
if base_path != os.curdir:
|
62
|
+
base_path = os.path.abspath(base_path)
|
63
|
+
# Try only a few names per directory.
|
64
|
+
for seq in range(100):
|
65
|
+
name = next(namer)
|
66
|
+
filename = os.path.join(base_path, prefix + name)
|
67
|
+
try:
|
68
|
+
fd = os.open(filename, _bin_openflags, 0o600)
|
69
|
+
try:
|
70
|
+
try:
|
71
|
+
with io.open(fd, "wb", closefd=False) as fp:
|
72
|
+
fp.write(b"blat")
|
73
|
+
finally:
|
74
|
+
os.close(fd)
|
75
|
+
finally:
|
76
|
+
os.unlink(filename)
|
77
|
+
return filename
|
78
|
+
except FileExistsError:
|
79
|
+
pass
|
80
|
+
except PermissionError:
|
81
|
+
# This exception is thrown when a directory with the chosen name
|
82
|
+
# already exists on windows.
|
83
|
+
if (
|
84
|
+
os.name == "nt"
|
85
|
+
and os.path.isdir(base_path)
|
86
|
+
and os.access(base_path, os.W_OK)
|
87
|
+
):
|
88
|
+
continue
|
89
|
+
break # no point trying more names in this directory
|
90
|
+
except OSError:
|
91
|
+
break # no point trying more names in this directory
|
92
|
+
raise FileNotFoundError(
|
93
|
+
errno.ENOENT, "No usable temporary file found in " % base_path
|
94
|
+
)
|
95
|
+
|
96
|
+
|
97
|
+
class CreateTempFile:
|
98
|
+
def __init__(
|
99
|
+
self,
|
100
|
+
base_path: str,
|
101
|
+
prefix: str,
|
102
|
+
file_content: str,
|
103
|
+
extension: str = ".dat",
|
104
|
+
delete_tempfile: bool = True,
|
105
|
+
):
|
106
|
+
self.delete_tempfile = delete_tempfile
|
107
|
+
# get temp file name
|
108
|
+
self.temp_file_name = _get_tempfile_name(base_path, prefix) + extension
|
109
|
+
self.temp_content = file_content
|
110
|
+
|
111
|
+
def __enter__(self):
|
112
|
+
with open(self.temp_file_name, "w", encoding="utf-8-sig") as tempfile:
|
113
|
+
tempfile.write(self.temp_content)
|
114
|
+
return tempfile
|
115
|
+
|
116
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
117
|
+
if self.delete_tempfile:
|
118
|
+
os.remove(self.temp_file_name)
|