Skip to content

Commit

Permalink
Use format itself to see if dsetname is OK
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarago committed Aug 12, 2014
1 parent d139d89 commit 8faf2e3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions concert/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,19 @@ def _write_coroutine(self, dsetname=None):

def _dset_exists(self, dsetname):
"""Check if *dsetname* exists on the current level."""
match = re.search(r'(?P<prefix>.*){.*}.*', dsetname)
if not match:
bad = '{' not in dsetname

try:
dsetname.format(0)
except ValueError:
bad = True

if bad:
raise ValueError('dsetname `{}\' has wrong format'.format(dsetname))

filenames = os.listdir(self._current)
for name in filenames:
if name.startswith(match.group('prefix')):
if name.startswith(dsetname.split('{')[0]):
return True

return False
Expand Down

0 comments on commit 8faf2e3

Please sign in to comment.