diff --git a/dgsamples/__init__.py b/dgsamples/__init__.py index 9668d82..49d987d 100644 --- a/dgsamples/__init__.py +++ b/dgsamples/__init__.py @@ -2,6 +2,8 @@ allsamples = _registerdata._runit() +from_root = _registerdata._from_root + for _s in allsamples: exec(_s+'=allsamples[_s]') diff --git a/dgsamples/_registerdata.py b/dgsamples/_registerdata.py index 129e1c0..1edfadd 100644 --- a/dgsamples/_registerdata.py +++ b/dgsamples/_registerdata.py @@ -2,6 +2,7 @@ import tinytools as tt import inspect + def _runit(): # Go into each directory and look for interesting things per pseudo-code: # @@ -16,7 +17,17 @@ def _runit(): # on the OrderedBunch pkg_dir = os.path.dirname(os.path.abspath(inspect.stack()[0][1])) - pkg_dirs = tt.files.search(pkg_dir, '*', ret_files=False, ret_dirs=True) + return _from_root(pkg_dir) + + +def _from_root(test_root): + """ + Return the dgsamples in the given test_root. + :param test_root: Path to a dgsamples-compliant folder + :return: OrderedBunch + """ + + pkg_dirs = tt.files.search(test_root, '*', ret_files=False, ret_dirs=True) # Setup the data structure to be populated pkg_samples = tt.bunch.OrderedBunch() @@ -34,11 +45,12 @@ def _runit(): # Check for notes tmpnote = tt.files.search(d, 'notes.txt', case_sensitive=False) if tmpnote: - with open(tmpnote[0],'r') as f: + with open(tmpnote[0], 'r') as f: pkg_samples[name]['notes'] = f.read() # Look for TIL files tmptil = tt.files.search(d, '*.TIL', case_sensitive=False, depth=3) + # Look for TIF files tmptif = tt.files.search(d, ['*.TIF', '*.TIFF'], case_sensitive=False, depth=3) @@ -48,21 +60,21 @@ def _runit(): if tmptil: pkg_samples[name]['files'] = tmptil - # pkg_samples[name] = _build_dgimg(pkg_samples[name]) elif tmptif: pkg_samples[name]['files'] = tmptif - # pkg_samples[name] = _build_dgimg(pkg_samples[name]) elif tmpvec: pkg_samples[name]['files'] = tmpvec - # pkg_samples[name] = _build_vec(pkg_samples[name]) try: - name_map = tt.pvl.read_from_pvl(os.path.join(d,'filename_map.PVL')) + pvls = tt.files.search(d, 'filename_map.pvl', ret_files=True, ret_dirs=False, case_sensitive=False, + depth=1) + [pvl] = pvls # ensure that there is one and only one filename using python's list unpacking + name_map = tt.pvl.read_from_pvl(pvl) except: name_map = {} - for k,v in name_map.iteritems(): - v = tt.files.search(d,'*'+v,depth=3) + for k, v in name_map.iteritems(): + v = tt.files.search(d, '*' + v, depth=3) if v[0] in pkg_samples[name]['files']: pkg_samples[name][k] = v[0]