Skip to content

load input directory and files #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
6 changes: 3 additions & 3 deletions src/diffpy/labpdfproc/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

params1 = [
(
[],
["--input-file", "."],
[
".",
["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl", "input_dir"],
["good_data.chi", "good_data.xy", "good_data.txt", "unreadable_file.txt", "binary.pkl"],
],
),
(["--input-file", "good_data.chi"], [".", "good_data.chi"]),
(["--input-file", "input_dir/unreadable_file.txt"], ["input_dir", "input_dir/unreadable_file.txt"]),
(["--input-file", "input_dir/unreadable_file.txt"], ["input_dir", "unreadable_file.txt"]),
# ([Path.cwd()], [Path.cwd()]),
]

Expand Down
17 changes: 12 additions & 5 deletions src/diffpy/labpdfproc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def set_input_files(args):
"""
Set input directory and files, default is current working directory and all files in it
Set input directory and files

Parameters
----------
Expand All @@ -20,12 +20,19 @@ def set_input_files(args):
args argparse.Namespace

"""
input_dir = Path.cwd() / Path(args.input_file).parent if args.input_file else Path.cwd()
setattr(args, "input_directory", input_dir)
if not args.input_file:
input_files = glob.glob(str(input_dir) + "/*", recursive=True)
if not args.input_file or not Path(args.input_file).exists():
raise ValueError("Please specify valid input file or directory.")

if not Path(args.input_file).is_dir():
input_dir = Path.cwd() / Path(args.input_file).parent
input_file_name = Path(args.input_file).name
args.input_file = input_file_name
else:
input_dir = Path(args.input_file).resolve()
input_files = [file for file in glob.glob(str(input_dir) + "/*", recursive=True) if os.path.isfile(file)]
input_file_names = [os.path.basename(input_file_path) for input_file_path in input_files]
args.input_file = input_file_names
setattr(args, "input_directory", input_dir)
return args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, I think this looks good.



Expand Down
Loading