Skip to content

Commit

Permalink
Fix export for merged dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
emi80 committed Apr 25, 2014
1 parent c7f9749 commit 73f5d56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions indexfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"view"
],
"kw_sep": " ",
"rep_sep": ",",
"sep": "=",
"trail": ";"
}
Expand Down
16 changes: 8 additions & 8 deletions indexfile/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ def export(self, types=None, tags=None):
data = dict([(k, v) for k, v in self._metadata.items()
+ {'path': path, 'type': ftype}.items()
+ info.items() if k in tags])
for k, val in data.items():
if type(val) == list:
data[k] = ','.join(v)
out.append(data)
return out

Expand Down Expand Up @@ -477,7 +474,7 @@ def save(self, path=None):
for line in self.export(map=None):
index.write("%s%s" % (line, os.linesep))

def export(self, absolute=False, type='index', tags=None, header=False,
def export(self, absolute=False, export_type='index', tags=None, header=False,
**kwargs):
"""Export the index file information. ``kwargs`` contains the format
information.
Expand Down Expand Up @@ -512,7 +509,7 @@ def export(self, absolute=False, type='index', tags=None, header=False,

out = []

if type == 'tab':
if export_type == 'tab':
log.debug('Create header for %s export format', type)
if not self._alltags:
self._create_lookup()
Expand All @@ -535,17 +532,20 @@ def export(self, absolute=False, type='index', tags=None, header=False,
if k:
line[k] = val
log.debug('Create output for %s format', type)
if type == 'index':
if export_type == 'index':
out.append(colsep.join([line.pop(path, '.'),
to_tags(**dict(line.items() +
kwargs.items()))]))
if type == 'json':
if export_type == 'json':
out.append(json.dumps(line))
if type == 'tab':
if export_type == 'tab':
vals = line.values()
if tags or len(line.values()) != len(headline):
vals = [line.get(l, 'NA') if l != 'id'
else line.get(dsid) for l in headline]
for val in vals:
if type(val) == list:
val = self.format.get('rep_sep', ",").join(val)
out.append(colsep.join(vals))

if type == 'tab':
Expand Down
14 changes: 7 additions & 7 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ def test_export_no_map_tab_tags():
i.export(map=None, type='tab', tags=['id', 'path'])


# def test_export_no_map_tab_all_tags():
# """Test export"""
# i = Index('test/data/index.txt')
# assert i is not None
# i.set_format('test/data/format.json')
# i.open()
# i.export(map=None, type='tab')
def test_export_no_map_tab_all_tags():
"""Test export"""
i = Index('test/data/index.txt')
assert i is not None
i.set_format('test/data/format.json')
i.open()
i.export(map=None, type='tab')


def test_replicates():
Expand Down

0 comments on commit 73f5d56

Please sign in to comment.