diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 4b4942227e..94ade345db 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -185,7 +185,8 @@ def fname_presuffix(fname, prefix='', suffix='', newpath=None, use_ext=True): '/tmp/prefoopost.nii.gz' >>> from nipype.interfaces.base import Undefined - >>> fname_presuffix(fname, 'pre', 'post', Undefined) == fname_presuffix(fname, 'pre', 'post') + >>> fname_presuffix(fname, 'pre', 'post', Undefined) == \ + fname_presuffix(fname, 'pre', 'post') True """ @@ -289,15 +290,25 @@ def _parse_mount_table(exit_code, output): # ^^^^ ^^^^^ # OSX mount example: /dev/disk2 on / (hfs, local, journaled) # ^ ^^^ - pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,]+)(?:, |\)| )') + pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,\)]+)') + + # Keep line and match for error reporting (match == None on failure) + # Ignore empty lines + matches = [(l, pattern.match(l)) + for l in output.strip().splitlines() if l] # (path, fstype) tuples, sorted by path length (longest first) - mount_info = sorted((pattern.match(l).groups() - for l in output.splitlines()), + mount_info = sorted((match.groups() for _, match in matches + if match is not None), key=lambda x: len(x[0]), reverse=True) cifs_paths = [path for path, fstype in mount_info if fstype.lower() == 'cifs'] + # Report failures as warnings + for line, match in matches: + if match is None: + fmlogger.debug("Cannot parse mount line: '%s'", line) + return [ mount for mount in mount_info if any(mount[0].startswith(path) for path in cifs_paths) diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py index e8c0f7da30..033f583049 100644 --- a/nipype/utils/tests/test_filemanip.py +++ b/nipype/utils/tests/test_filemanip.py @@ -451,7 +451,16 @@ def test_related_files(file, length, expected_files): tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,size=65536k,mode=755) tmpfs on /proc/scsi type tmpfs (ro,relatime) tmpfs on /sys/firmware type tmpfs (ro,relatime) -''', 0, [('/data', 'cifs')]) +''', 0, [('/data', 'cifs')]), +# From @yarikoptic - added blank lines to test for resilience +(r'''/proc on /proc type proc (rw,relatime) +sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) +tmpfs on /dev/shm type tmpfs (rw,relatime) +devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666) + +devpts on /dev/ptmx type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666) + +''', 0, []), )