oh-my-batch 0.4.9__tar.gz → 0.5.1__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.4.9 → oh_my_batch-0.5.1}/PKG-INFO +1 -1
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/batch.py +6 -2
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/combo.py +13 -3
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/pyproject.toml +1 -1
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/LICENSE +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/README.md +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/__init__.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/__main__.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/assets/__init__.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/assets/functions.sh +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/cli.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/job.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/misc.py +0 -0
- {oh_my_batch-0.4.9 → oh_my_batch-0.5.1}/oh_my_batch/util.py +0 -0
@@ -13,13 +13,17 @@ class BatchMaker:
|
|
13
13
|
self._script_bottom = []
|
14
14
|
self._command = []
|
15
15
|
|
16
|
-
def add_work_dirs(self, *dir: str):
|
16
|
+
def add_work_dirs(self, *dir: str, abs=False):
|
17
17
|
"""
|
18
18
|
Add working directories
|
19
19
|
|
20
20
|
:param dir: Directories to work on, can be glob patterns
|
21
|
+
:param abs: Whether to convert to absolute path
|
21
22
|
"""
|
22
|
-
|
23
|
+
paths = expand_globs(dir)
|
24
|
+
if abs:
|
25
|
+
paths = [os.path.abspath(p) for p in paths]
|
26
|
+
self._work_dirs.extend(paths)
|
23
27
|
return self
|
24
28
|
|
25
29
|
def add_header_files(self, *file: str, encoding='utf-8'):
|
@@ -92,7 +92,7 @@ class ComboMaker:
|
|
92
92
|
return self
|
93
93
|
|
94
94
|
def add_file_set(self, key: str, *path: str, format=None,
|
95
|
-
|
95
|
+
sep=' ', abs=False, raise_invalid=False):
|
96
96
|
"""
|
97
97
|
Add a variable with files by glob pattern as one string
|
98
98
|
Unlike add_files, this function joins the files with a delimiter.
|
@@ -163,7 +163,8 @@ class ComboMaker:
|
|
163
163
|
self._broadcast_keys.append(key)
|
164
164
|
return self
|
165
165
|
|
166
|
-
def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8'
|
166
|
+
def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8',
|
167
|
+
extra_vars_from_file=None):
|
167
168
|
"""
|
168
169
|
Make files from template against each combo
|
169
170
|
The template file can include variables with delimiter.
|
@@ -179,6 +180,7 @@ class ComboMaker:
|
|
179
180
|
can be changed to other character, e.g $, $$, ...
|
180
181
|
:param mode: File mode, e.g. 755, 644, ...
|
181
182
|
:param encoding: File encoding
|
183
|
+
:param extra_vars_from_file: Load extra variables from json file, which can be used in template
|
182
184
|
"""
|
183
185
|
_delimiter = delimiter
|
184
186
|
|
@@ -190,9 +192,17 @@ class ComboMaker:
|
|
190
192
|
_template = template.format(i=i, **combo)
|
191
193
|
with open(_template, 'r') as f:
|
192
194
|
template_text = f.read()
|
193
|
-
|
195
|
+
|
196
|
+
if extra_vars_from_file is not None:
|
197
|
+
_vars_file = extra_vars_from_file.format(i=i, **combo)
|
198
|
+
with open(_vars_file, 'r') as f:
|
199
|
+
extra_vars = json.load(f)
|
200
|
+
else:
|
201
|
+
extra_vars = {}
|
202
|
+
text = _Template(template_text).safe_substitute(combo, **extra_vars)
|
194
203
|
_file = file.format(i=i, **combo)
|
195
204
|
ensure_dir(_file)
|
205
|
+
|
196
206
|
with open(_file, 'w', encoding=encoding) as f:
|
197
207
|
f.write(text)
|
198
208
|
if mode is not None:
|
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
|