Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dgsamples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

allsamples = _registerdata._runit()

from_root = _registerdata._from_root

for _s in allsamples:
exec(_s+'=allsamples[_s]')

Expand Down
28 changes: 20 additions & 8 deletions dgsamples/_registerdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tinytools as tt
import inspect


def _runit():
# Go into each directory and look for interesting things per pseudo-code:
#
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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]

Expand Down