oh-my-batch 0.5.0__tar.gz → 0.5.2__tar.gz
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.
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/PKG-INFO +1 -1
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/combo.py +31 -12
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/pyproject.toml +1 -1
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/LICENSE +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/README.md +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/__init__.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/__main__.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/assets/__init__.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/assets/functions.sh +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/batch.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/cli.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/job.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/misc.py +0 -0
- {oh_my_batch-0.5.0 → oh_my_batch-0.5.2}/oh_my_batch/util.py +0 -0
@@ -1,5 +1,6 @@
|
|
1
1
|
from itertools import product
|
2
2
|
from string import Template
|
3
|
+
import traceback
|
3
4
|
import random
|
4
5
|
import json
|
5
6
|
import os
|
@@ -92,7 +93,7 @@ class ComboMaker:
|
|
92
93
|
return self
|
93
94
|
|
94
95
|
def add_file_set(self, key: str, *path: str, format=None,
|
95
|
-
|
96
|
+
sep=' ', abs=False, raise_invalid=False):
|
96
97
|
"""
|
97
98
|
Add a variable with files by glob pattern as one string
|
98
99
|
Unlike add_files, this function joins the files with a delimiter.
|
@@ -163,7 +164,8 @@ class ComboMaker:
|
|
163
164
|
self._broadcast_keys.append(key)
|
164
165
|
return self
|
165
166
|
|
166
|
-
def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8'
|
167
|
+
def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8',
|
168
|
+
extra_vars_from_file=None, ignore_error=False):
|
167
169
|
"""
|
168
170
|
Make files from template against each combo
|
169
171
|
The template file can include variables with delimiter.
|
@@ -179,6 +181,8 @@ class ComboMaker:
|
|
179
181
|
can be changed to other character, e.g $, $$, ...
|
180
182
|
:param mode: File mode, e.g. 755, 644, ...
|
181
183
|
:param encoding: File encoding
|
184
|
+
:param extra_vars_from_file: Load extra variables from json file, which can be used in template
|
185
|
+
:param ignore_error: If True, ignore error when making files
|
182
186
|
"""
|
183
187
|
_delimiter = delimiter
|
184
188
|
|
@@ -187,16 +191,31 @@ class ComboMaker:
|
|
187
191
|
|
188
192
|
combos = self._make_combos()
|
189
193
|
for i, combo in enumerate(combos):
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
try:
|
195
|
+
_template = template.format(i=i, **combo)
|
196
|
+
with open(_template, 'r') as f:
|
197
|
+
template_text = f.read()
|
198
|
+
|
199
|
+
if extra_vars_from_file is not None:
|
200
|
+
_vars_file = extra_vars_from_file.format(i=i, **combo)
|
201
|
+
with open(_vars_file, 'r') as f:
|
202
|
+
extra_vars = json.load(f)
|
203
|
+
else:
|
204
|
+
extra_vars = {}
|
205
|
+
text = _Template(template_text).safe_substitute(combo, **extra_vars)
|
206
|
+
_file = file.format(i=i, **combo)
|
207
|
+
ensure_dir(_file)
|
208
|
+
|
209
|
+
with open(_file, 'w', encoding=encoding) as f:
|
210
|
+
f.write(text)
|
211
|
+
if mode is not None:
|
212
|
+
os.chmod(_file, mode_translate(str(mode)))
|
213
|
+
except Exception as e:
|
214
|
+
if ignore_error:
|
215
|
+
print(f"Error during making file, ignore: {e}")
|
216
|
+
traceback.print_exc()
|
217
|
+
else:
|
218
|
+
raise e
|
200
219
|
return self
|
201
220
|
|
202
221
|
def print(self, *line: str, file: str = '', mode=None, encoding='utf-8'):
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|