riggsd / guano-py

Python reference implementation of the GUANO bat acoustics metadata specification
http://guano-md.org
MIT License
13 stars 5 forks source link

guano_edit.py Templates Don't Support Namespaces #10

Closed riggsd closed 6 years ago

riggsd commented 6 years ago

Using a namespaced field or a field containing a space character within a template substitution causes guano_edit.py to fail with the following exception:

Traceback (most recent call last):
  File "./bin/guano_edit.py", line 95, in <module>
    main()
  File "./bin/guano_edit.py", line 91, in main
    update(gfile, md, dry_run=DRY_RUN)
  File "./bin/guano_edit.py", line 69, in update
    gfile[k] = Template(v).substitute(gfile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 176, in substitute
    return self.pattern.sub(convert, self.template)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 173, in convert
    self._invalid(mo)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 146, in _invalid
    (lineno, colno))
ValueError: Invalid placeholder in string: line 1, col 1

Examples:

$> guano_edit.py 'Species Auto ID: ${SB|AutoID} foo/bar/*.wav

$> guano_edit.py 'Note: Recorded at ${Loc Position} by me.' foo/bar/*.wav

The class attribute string.Template.idpattern is a regular expression responsible for validating template patterns.