oh-my-batch 0.5.7__tar.gz → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oh-my-batch
3
- Version: 0.5.7
3
+ Version: 0.6.1
4
4
  Summary:
5
5
  License: GPL
6
6
  Author: weihong.xu
@@ -1,3 +1,4 @@
1
+ from typing import Optional
1
2
  import shlex
2
3
  import os
3
4
 
@@ -25,6 +26,24 @@ class BatchMaker:
25
26
  self._work_dirs.extend(paths)
26
27
  return self
27
28
 
29
+ def filter(self, expr: str):
30
+ """
31
+ Filter working directories with a Python expression
32
+
33
+ :param expr: Python expression, the variable `{workdir}, {work_dir} or {w}` is the directory path,
34
+ `{index} or {i}` is the index of the directory
35
+
36
+ Example: if expr is 'os.path.exits("{workdir}/input.json")',
37
+ then only the directories containing 'input.json' will be kept.
38
+ """
39
+ filtered = []
40
+ for i, workdir in enumerate(self._work_dirs):
41
+ expr_eval = expr.format(workdir=workdir, work_dir=workdir, w=workdir, index=i, i=i)
42
+ if eval(expr_eval):
43
+ filtered.append(workdir)
44
+ self._work_dirs = filtered
45
+ return self
46
+
28
47
  def add_header_files(self, *file: str, encoding='utf-8'):
29
48
  """
30
49
  Add script header from files
@@ -130,4 +149,4 @@ def load_files(*file, encoding='utf-8', raise_invalid=False):
130
149
  for file in expand_globs(file, raise_invalid=raise_invalid):
131
150
  with open(file, 'r', encoding=encoding) as f:
132
151
  result.append(f.read())
133
- return result
152
+ return result
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "oh-my-batch"
3
- version = "0.5.7"
3
+ version = "0.6.1"
4
4
  description = ""
5
5
  authors = ["weihong.xu <xuweihong.cn@gmail.com>"]
6
6
  license = "GPL"
File without changes
File without changes