oh-my-batch 0.5.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oh-my-batch
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary:
5
5
  License: GPL
6
6
  Author: weihong.xu
@@ -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
@@ -164,7 +165,7 @@ class ComboMaker:
164
165
  return self
165
166
 
166
167
  def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8',
167
- extra_vars_from_file=None):
168
+ extra_vars_from_file=None, ignore_error=False):
168
169
  """
169
170
  Make files from template against each combo
170
171
  The template file can include variables with delimiter.
@@ -181,6 +182,7 @@ class ComboMaker:
181
182
  :param mode: File mode, e.g. 755, 644, ...
182
183
  :param encoding: File encoding
183
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
184
186
  """
185
187
  _delimiter = delimiter
186
188
 
@@ -189,24 +191,31 @@ class ComboMaker:
189
191
 
190
192
  combos = self._make_combos()
191
193
  for i, combo in enumerate(combos):
192
- _template = template.format(i=i, **combo)
193
- with open(_template, 'r') as f:
194
- template_text = f.read()
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)
203
- _file = file.format(i=i, **combo)
204
- ensure_dir(_file)
205
-
206
- with open(_file, 'w', encoding=encoding) as f:
207
- f.write(text)
208
- if mode is not None:
209
- os.chmod(_file, mode_translate(str(mode)))
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
210
219
  return self
211
220
 
212
221
  def print(self, *line: str, file: str = '', mode=None, encoding='utf-8'):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "oh-my-batch"
3
- version = "0.5.1"
3
+ version = "0.5.2"
4
4
  description = ""
5
5
  authors = ["weihong.xu <xuweihong.cn@gmail.com>"]
6
6
  license = "GPL"
File without changes
File without changes