Skip to content

Commit

Permalink
Merge af75999 into c46cf2c
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 29, 2019
2 parents c46cf2c + af75999 commit 7435f92
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LICENSE.rst
Expand Up @@ -9,7 +9,7 @@ are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
* Neither the name of the HPSSPy Project nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

Expand Down
7 changes: 7 additions & 0 deletions doc/changes.rst
Expand Up @@ -7,6 +7,13 @@ Release Notes

*Python 2 support will be dropped starting with this release.*

0.4.2 (unreleased)
------------------

* Further fixes for mapping HTAR file names back to directories (PR `#6`_).

.. _`#6`: https://github.com/weaverba137/hpsspy/pull/6

0.4.1 (2019-01-16)
------------------

Expand Down
2 changes: 1 addition & 1 deletion hpsspy/__init__.py
Expand Up @@ -23,4 +23,4 @@ class HpssOSError(HpssError):
pass


__version__ = '0.5.0.dev242'
__version__ = '0.4.2.dev242'
11 changes: 9 additions & 2 deletions hpsspy/scan.py
Expand Up @@ -387,12 +387,19 @@ def extract_directory_name(filename):
:class:`str`
Name of a directory.
"""
prefix = os.path.dirname(filename).replace('/', '_') + '_'
d = os.path.dirname(filename)
basefile = os.path.basename(filename).rsplit('.', 1)[0] # remove .tar
if not d:
return basefile
prefix = d.replace('/', '_') + '_'
try:
i = basefile.index(prefix)
except ValueError:
return basefile
try:
prefix = '_'.join(prefix.split('_')[1:])
i = basefile.index(prefix)
except ValueError:
return basefile
return basefile[(i + len(prefix)):]


Expand Down
5 changes: 5 additions & 0 deletions hpsspy/test/test_scan.py
Expand Up @@ -238,8 +238,13 @@ def test_extract_directory_name(self):
'protodesi_images_fpc_analysis_' +
'stability_dither-33022.tar'))
self.assertEqual(d, 'stability_dither-33022')
d = extract_directory_name(('buzzard/buzzard_v1.6_desicut/8/' +
'buzzard_v1.6_desicut_8_7.tar'))
self.assertEqual(d, '7')
d = extract_directory_name('foo/bar/batch.tar')
self.assertEqual(d, 'batch')
d = extract_directory_name('batch.tar')
self.assertEqual(d, 'batch')


def test_suite():
Expand Down

0 comments on commit 7435f92

Please sign in to comment.