Skip to content

Commit f495565

Browse files
added functionality to automatically select files and skipping files
1 parent c8c0071 commit f495565

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def get_args(override_cli_inputs=None):
3030
" the list of files contained in the text-file called "
3131
"file_list.txt that can be found in the folder ./data), "
3232
"'./*.chi', 'data/*.chi' (load all files with extension .chi in the "
33-
"folder ./data).",
33+
"folder ./data). You can also prepend '~' to a file name to "
34+
"specify files that should be excluded.",
3435
)
3536
p.add_argument(
3637
"-a",

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
["good_data*"],
6666
["good_data.chi", "good_data.xy", "good_data.txt"],
6767
),
68+
( # specify files do not want to read
69+
[".", "~unreadable_file.txt", "~binary.pkl"],
70+
["good_data.chi", "good_data.xy", "good_data.txt"],
71+
),
6872
]
6973

7074

src/diffpy/labpdfproc/tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ def set_input_lists(args):
8080
"""
8181

8282
input_paths = []
83+
excluded_paths = []
8384
args = _expand_user_input(args)
8485
for input_name in args.input:
86+
if input_name.startswith("~"):
87+
input_path = Path(input_name[1:]).resolve()
88+
if input_path.exists() and input_path.is_file():
89+
excluded_paths.append(input_path)
90+
continue
8591
input_path = Path(input_name).resolve()
8692
if input_path.exists():
8793
if input_path.is_file():
@@ -100,6 +106,7 @@ def set_input_lists(args):
100106
)
101107
else:
102108
raise FileNotFoundError(f"Cannot find {input_name}.")
109+
input_paths = [input_path for input_path in input_paths if input_path not in excluded_paths]
103110
setattr(args, "input_paths", list(set(input_paths)))
104111
return args
105112

0 commit comments

Comments
 (0)