oh-my-batch 0.6.1__tar.gz → 0.6.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.6.1 → oh_my_batch-0.6.2}/PKG-INFO +1 -1
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/batch.py +9 -3
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/combo.py +18 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/pyproject.toml +1 -1
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/LICENSE +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/README.md +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/__init__.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/__main__.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/assets/__init__.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/assets/functions.sh +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/cli.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/job.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/misc.py +0 -0
- {oh_my_batch-0.6.1 → oh_my_batch-0.6.2}/oh_my_batch/util.py +0 -0
@@ -1,5 +1,5 @@
|
|
1
|
-
from typing import Optional
|
2
1
|
import shlex
|
2
|
+
import glob
|
3
3
|
import os
|
4
4
|
|
5
5
|
from .util import split_list, ensure_dir, expand_globs, mode_translate
|
@@ -101,22 +101,28 @@ class BatchMaker:
|
|
101
101
|
self._command.extend(cmd)
|
102
102
|
return self
|
103
103
|
|
104
|
-
def make(self, path: str, concurrency=0, encoding='utf-8', mode='755'):
|
104
|
+
def make(self, path: str, concurrency=0, encoding='utf-8', mode='755', purge=False):
|
105
105
|
"""
|
106
106
|
Make batch script files from the previous setup
|
107
107
|
|
108
108
|
:param path: Path to save batch script files, use {i} to represent index
|
109
109
|
:param concurrency: Number of scripts to to make, default is 0, which means make one script for each working directory
|
110
|
+
:param purge: Whether to purge existing files of the same pattern before making new ones
|
110
111
|
:param encoding: File encoding
|
111
112
|
:param mode: File mode, default is 755
|
112
113
|
"""
|
113
|
-
|
114
114
|
header = '\n'.join(self._script_header)
|
115
115
|
bottom = '\n'.join(self._script_bottom)
|
116
116
|
|
117
117
|
if concurrency < 1:
|
118
118
|
concurrency = len(self._work_dirs)
|
119
119
|
|
120
|
+
if purge:
|
121
|
+
legacy_files = glob.glob(path.format(i='*'))
|
122
|
+
for f in legacy_files:
|
123
|
+
print(f'Removing existing file {f}')
|
124
|
+
os.remove(f)
|
125
|
+
|
120
126
|
for i, work_dirs in enumerate(split_list(self._work_dirs, concurrency)):
|
121
127
|
body = []
|
122
128
|
work_dirs_arr = "\n".join(shlex.quote(w) for w in work_dirs)
|
@@ -231,6 +231,24 @@ class ComboMaker:
|
|
231
231
|
raise e
|
232
232
|
return self
|
233
233
|
|
234
|
+
def dump_combos(self, file: str, encoding='utf-8', indent=2):
|
235
|
+
"""
|
236
|
+
dump each combo to a json file
|
237
|
+
|
238
|
+
This is useful for debugging or use with `--extra-vars-from-file` in `make_files`
|
239
|
+
|
240
|
+
:param file: path pattern to json file, can include format style variables, e.g. {i}, {i:03d}, {TEMP}
|
241
|
+
:param encoding: File encoding
|
242
|
+
:param indent: Indentation for json file
|
243
|
+
"""
|
244
|
+
combos = self._make_combos()
|
245
|
+
for i, combo in enumerate(combos):
|
246
|
+
out_path = file.format(i=i, **combo)
|
247
|
+
ensure_dir(out_path)
|
248
|
+
with open(out_path, 'w', encoding=encoding) as f:
|
249
|
+
json.dump(combo, f, indent=indent)
|
250
|
+
return self
|
251
|
+
|
234
252
|
def print(self, *line: str, file: str = '', mode=None, encoding='utf-8'):
|
235
253
|
"""
|
236
254
|
Print lines to a file against each combo
|
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
|