LSST Applications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-10-gbfb87ad6+3307648ee3,21.0.0-15-gedb9d5423+47cba9fc36,21.0.0-2-g103fe59+fdf0863a2a,21.0.0-2-g1367e85+d38a93257c,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+d38a93257c,21.0.0-2-g7f82c8f+e682ffb718,21.0.0-2-g8dde007+d179fbfa6a,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+e682ffb718,21.0.0-2-ga63a54e+08647d4b1b,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0445ed2f95,21.0.0-2-gfc62afb+d38a93257c,21.0.0-27-gbbd0d29+ae871e0f33,21.0.0-28-g5fc5e037+feb0e9397b,21.0.0-3-g21c7a62+f4b9c0ff5c,21.0.0-3-g357aad2+57b0bddf0b,21.0.0-3-g4be5c26+d38a93257c,21.0.0-3-g65f322c+3f454acf5d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+9e4ef6332c,21.0.0-3-ge02ed75+4b120a55c4,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-g591bb35+4b120a55c4,21.0.0-4-gc004bbf+4911b9cd27,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-ge8fba5a+2b3a696ff9,21.0.0-5-gb155db7+2c5429117a,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g00874e7+c9fd7f7160,21.0.0-6-g4e60332+4b120a55c4,21.0.0-7-gc8ca178+40eb9cf840,21.0.0-8-gfbe0b4b+9e4ef6332c,21.0.0-9-g2fd488a+d83b7cd606,w.2021.05
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner Class Reference

Public Member Functions

def __init__ (self, Optional[Log] log=None)
 
def add (self, PathElementHandler handler)
 
Iterator[PathElementHandler__iter__ (self)
 
def scan (self, str path, Mapping[DatasetType, Mapping[Optional[str], List[FileDataset]]] datasets, *Callable[[DataCoordinate], bool] predicate)
 

Public Attributes

 log
 

Detailed Description

An object that uses `PathElementHandler` instances to process the files
and subdirectories in a directory tree.

Parameters
----------
log : `Log`, optional
    Log to use to report warnings and debug information.

Definition at line 162 of file scanner.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner.__init__ (   self,
Optional[Log]   log = None 
)

Definition at line 171 of file scanner.py.

171  def __init__(self, log: Optional[Log] = None):
172  self._files = []
173  self._subdirectories = []
174  if log is None:
175  log = Log.getLogger("obs.base.gen2to3.walker")
176  self.log = log
177 

Member Function Documentation

◆ __iter__()

Iterator[PathElementHandler] lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner.__iter__ (   self)
Iterate over all handlers.

Definition at line 194 of file scanner.py.

194  def __iter__(self) -> Iterator[PathElementHandler]:
195  """Iterate over all handlers.
196  """
197  yield from self._files
198  yield from self._subdirectories
199 

◆ add()

def lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner.add (   self,
PathElementHandler  handler 
)
Add a new handler to the scanner.

Parameters
----------
handler : `PathElementHandler`
    The handler to be added.

Definition at line 180 of file scanner.py.

180  def add(self, handler: PathElementHandler):
181  """Add a new handler to the scanner.
182 
183  Parameters
184  ----------
185  handler : `PathElementHandler`
186  The handler to be added.
187  """
188  handler.log = self.log
189  if handler.isForFiles():
190  bisect.insort(self._files, handler)
191  else:
192  bisect.insort(self._subdirectories, handler)
193 

◆ scan()

def lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner.scan (   self,
str  path,
Mapping[DatasetType, Mapping[Optional[str], List[FileDataset]]]  datasets,
*Callable[[DataCoordinate], bool]  predicate 
)
Process a directory.

Parameters
----------
path : `str`
    Full path to the directory to be processed.
datasets : `dict` [`DatasetType`, `list` ]
    Dictionary that found datasets should be added to.  Nested lists
    elements are tuples of `FileDataset` and an optional "CALIBDATE"
    `str` value (for calibration datasets only).
predicate : `~collections.abc.Callable`
    A callable taking a single `DataCoordinate` argument and returning
    `bool`, indicating whether that (Gen3) data ID represents one
    that should be included in the scan.

Definition at line 200 of file scanner.py.

201  predicate: Callable[[DataCoordinate], bool]):
202  """Process a directory.
203 
204  Parameters
205  ----------
206  path : `str`
207  Full path to the directory to be processed.
208  datasets : `dict` [`DatasetType`, `list` ]
209  Dictionary that found datasets should be added to. Nested lists
210  elements are tuples of `FileDataset` and an optional "CALIBDATE"
211  `str` value (for calibration datasets only).
212  predicate : `~collections.abc.Callable`
213  A callable taking a single `DataCoordinate` argument and returning
214  `bool`, indicating whether that (Gen3) data ID represents one
215  that should be included in the scan.
216  """
217  unrecognized = []
218  for entry in os.scandir(path):
219  if entry.is_file():
220  handlers = self._files
221  elif entry.is_dir():
222  handlers = self._subdirectories
223  else:
224  continue
225  for handler in handlers:
226  if handler(entry.path, entry.name, datasets, predicate=predicate):
227  break
228  else:
229  unrecognized.append(entry.name)
230  if unrecognized:
231  self.log.warn("Skipped unrecognized entries in %s: %s", path, unrecognized)

Member Data Documentation

◆ log

lsst.obs.base.gen2to3.repoWalker.scanner.DirectoryScanner.log

Definition at line 176 of file scanner.py.


The documentation for this class was generated from the following file: