diff --git a/newsfragments/768.feature b/newsfragments/768.feature new file mode 100644 index 000000000..9ac92167c --- /dev/null +++ b/newsfragments/768.feature @@ -0,0 +1,2 @@ +``dials.import``: add a progress bar for the import process, particularly +useful when importing thousands of files diff --git a/src/dxtbx/model/experiment_list.py b/src/dxtbx/model/experiment_list.py index 1386fd231..6f3590c5f 100644 --- a/src/dxtbx/model/experiment_list.py +++ b/src/dxtbx/model/experiment_list.py @@ -14,6 +14,7 @@ from typing import Any, Callable, Generator, Iterable import natsort +from tqdm import tqdm import dxtbx from dxtbx.format.Format import Format @@ -664,6 +665,9 @@ def from_filenames( """Create a list of data blocks from a list of directory or file names.""" experiments = ExperimentList() + # Cast filenames to a list from whatever iterator they are + filenames = list(filenames) + # Process each file given by this path list to_process = _openingpathiterator(filenames) find_format = FormatChecker() @@ -671,7 +675,13 @@ def from_filenames( format_groups = collections.defaultdict(list) if format_kwargs is None: format_kwargs = {} - for filename in to_process: + + if os.isatty and len(filenames) > 1: + filename_iter = tqdm(to_process, total=len(filenames)) + else: + filename_iter = to_process + + for filename in filename_iter: # We now have a file, pre-opened by Format.open_file (therefore # cached). Determine its type, and prepare to put into a group format_class = find_format.find_format(filename)