def dir_details(path, pre_walk=None): logger.debug('dir_details path: {}, pre_walked: {}'.format( path, pre_walk is not None)) root, dirs, files = util.path_content( path) if pre_walk is None else pre_walk # Sizes name = os.path.basename(path) size = util.dir_size(path) # File type counts num_files = len(files) num_vid = len([f for f in files if util.fext(f) in EXT_VIDEO]) num_img = len([f for f in files if util.fext(f) in EXT_IMAGE]) num_snd = len([f for f in files if util.fext(f) in EXT_SOUND]) num_doc = len([f for f in files if util.fext(f) in EXT_DOC]) data_fmt = contains_data(path, pre_walk=(root, dirs, files)) return dict(fname=name, size=size, num_files=num_files, num_vid=num_vid, num_img=num_img, num_snd=num_snd, num_doc=num_doc, data_fmt=data_fmt)
def format_version(base_path, pre_walk=None): root, dirs, files = path_content( base_path) if pre_walk is None else pre_walk if "settings.xml" in files: xml_root = ETree.parse(os.path.join(base_path, 'settings.xml')) version = xml_root.findall("INFO/VERSION")[0].text if len(version): return "{}_v{}".format(FMT_NAME, version if version else '???')
def find_settings_xml(base_dir): """Search for the settings.xml file in the base directory. Args: base_dir: Base directory of data set Returns: Path to settings.xml relative to base_dir """ _, dirs, files = util.path_content(base_dir) if "settings.xml" in files: return os.path.join(base_dir, 'settings.xml') else: return None
def detect(base_path, pre_walk=None): """Checks for existence of a kwik formatted data set in the root directory. Args: base_path: Directory to search in. pre_walk: Tuple from previous path_content call (root, dirs, files) Returns: None if no data set found, else a dict of configuration data from settings.xml """ root, dirs, files = path_content( base_path) if pre_walk is None else pre_walk for f in files: if fext(f) in ['.kwx', '.kwd', '.kwik']: # return format_version(base_path, pre_walk) return True
def gather(path): """Gather details on the path and its subdirectories. Args: path: Relative or absolute path to a directory. Returns: List of dictionaries. Each element in the list corresponds to the details of a single directory (including the given as [path]) in a dictionary. """ root, dirs, files = util.path_content(path) details = [dir_details(root)] for d in dirs: details.append(dir_details(os.path.join(root, d))) return details
def detect(base_path, pre_walk=None): """Checks for existence of an open ephys formatted data set in the root directory. Args: base_path: Path to search at. For OE data sets, typically a directory containing .continuous, .events and a settings.xml file. pre_walk: Tuple from previous path_content call Returns: None if no data set found, else a dict of configuration data from settings.xml """ logger.debug('Looking for .continuous data set in {}'.format(base_path)) root, dirs, files = util.path_content( base_path) if pre_walk is None else pre_walk for f in files: if util.fext(f) in ['.continuous']: # fv = metadata_from_xml(base_path)['INFO']['VERSION'] # return "{}_v{}".format(FMT_NAME, fv if fv else '???') return True
def detect(base_path, pre_walk=None): """Checks for existence of a/multiple .dat file(s) at the target path. Args: base_path: Directory to search in. pre_walk: Tuple from previous path_content call (root, dirs, files) Returns: None if no data set found, else string """ root, dirs, files = util.path_content( base_path) if pre_walk is None else pre_walk logger.debug('Looking for .dat files'.format(dirs, files)) dat_files = [f for f in files if util.fext(f) == '.dat'] logger.debug('{} .dat files found: {}'.format(len(dat_files), dat_files)) if not len(dat_files): return None elif len(dat_files) == 1: return '{}-File'.format(FMT_NAME) else: return '{}x {}'.format(len(dat_files), FMT_NAME)