oh-my-batch 0.6.1__py3-none-any.whl → 0.6.2__py3-none-any.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.
oh_my_batch/batch.py CHANGED
@@ -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)
oh_my_batch/combo.py CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oh-my-batch
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary:
5
5
  License: GPL
6
6
  Author: weihong.xu
@@ -2,14 +2,14 @@ oh_my_batch/__init__.py,sha256=BsRNxZbqDWfaIZJGxzIDqCubRWztMGFDceW08TECuFs,98
2
2
  oh_my_batch/__main__.py,sha256=sWyFZMwWNvhkanwZSJRGfBBDoIevhC028dTSB67i6yI,61
3
3
  oh_my_batch/assets/__init__.py,sha256=Exub46UbQaz2V2eXpQeiVfnThQpXaNeuyjlGY6gBSZc,130
4
4
  oh_my_batch/assets/functions.sh,sha256=LaiavZBu84D7C1r-dWhf91vPTuHXCMV1DQZUIPVQnjE,1001
5
- oh_my_batch/batch.py,sha256=nQUrKULULYUPtkibrU4SJlJQM9D63TsC1VajHcxZulQ,4723
5
+ oh_my_batch/batch.py,sha256=M48sEjUF19Th0H830qvBuKmBVNU4OYLdWaQHGIGk2bY,5009
6
6
  oh_my_batch/cli.py,sha256=Jyz8q2pUYke3mfJS6F_G9S9hApddgXxQw1BsN6Kfkjc,553
7
- oh_my_batch/combo.py,sha256=Twtzbv3hQUCNzwLjtbhmXJ_De5YNlL1mSzK-Zqejh7Y,11423
7
+ oh_my_batch/combo.py,sha256=994SbcTLcUqMowRD1S6p_pInfAyqFdpDoQQyAAIPc0M,12138
8
8
  oh_my_batch/job.py,sha256=fFoyLd0rKilV979ovEf0Y3iXgpyyDmHIfkMSZBaAX4Q,7446
9
9
  oh_my_batch/misc.py,sha256=G_iOovRCrShBJJCc82QLN0CvMqW4adOefEoY1GedEiw,452
10
10
  oh_my_batch/util.py,sha256=5ve2QcviuF0UHFLrsXmjMTj0ogXJ4g05q1y-yWCFuOk,2409
11
- oh_my_batch-0.6.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- oh_my_batch-0.6.1.dist-info/METADATA,sha256=ETV1q0arbSp8Xj-PFTKGj3rO6bbus8nX-XrtKQH1elI,5468
13
- oh_my_batch-0.6.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
- oh_my_batch-0.6.1.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
- oh_my_batch-0.6.1.dist-info/RECORD,,
11
+ oh_my_batch-0.6.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ oh_my_batch-0.6.2.dist-info/METADATA,sha256=N6O8Wb_OeYxxZ03ncr2IdH5cruANsZafWC1j6Y7FEQI,5468
13
+ oh_my_batch-0.6.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
+ oh_my_batch-0.6.2.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
+ oh_my_batch-0.6.2.dist-info/RECORD,,