oh-my-batch 0.5.0__py3-none-any.whl → 0.5.1__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/combo.py CHANGED
@@ -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
- sep=' ', abs=False, raise_invalid=False):
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
- text = _Template(template_text).safe_substitute(combo)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oh-my-batch
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary:
5
5
  License: GPL
6
6
  Author: weihong.xu
@@ -4,12 +4,12 @@ oh_my_batch/assets/__init__.py,sha256=Exub46UbQaz2V2eXpQeiVfnThQpXaNeuyjlGY6gBSZ
4
4
  oh_my_batch/assets/functions.sh,sha256=LaiavZBu84D7C1r-dWhf91vPTuHXCMV1DQZUIPVQnjE,1001
5
5
  oh_my_batch/batch.py,sha256=1aVLP2KAbfNo0Asw7khh5HGCrh1PbYLNXLmiR-sWWcs,3988
6
6
  oh_my_batch/cli.py,sha256=Jyz8q2pUYke3mfJS6F_G9S9hApddgXxQw1BsN6Kfkjc,553
7
- oh_my_batch/combo.py,sha256=A5flYsjugcelj105P6Nq4M3kNGtdqh3c7QaSIL3hUcg,9954
7
+ oh_my_batch/combo.py,sha256=umbm85W_5zefUn6CwU_hf6fBEJTWgGbpKfAjSgpiEHE,10381
8
8
  oh_my_batch/job.py,sha256=8qFYscHGzIQhX-HrAGxCCv7h2T8Ls1Fj0gmNEBdP5Go,7227
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.5.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- oh_my_batch-0.5.0.dist-info/METADATA,sha256=PnmjPUSjhK9CocNBQDYqRGNsy9KITN0Hr93H-V9onTA,5174
13
- oh_my_batch-0.5.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
- oh_my_batch-0.5.0.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
- oh_my_batch-0.5.0.dist-info/RECORD,,
11
+ oh_my_batch-0.5.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ oh_my_batch-0.5.1.dist-info/METADATA,sha256=z8wggFpwrZ1vdM-opqc3jj0bQU3MMdDK4CcT9wRgAso,5174
13
+ oh_my_batch-0.5.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
+ oh_my_batch-0.5.1.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
+ oh_my_batch-0.5.1.dist-info/RECORD,,