|
10 | 10 | from sys import platform
|
11 | 11 | from distutils import spawn
|
12 | 12 |
|
13 |
| -from ... import logging |
| 13 | +from ... import logging, LooseVersion |
14 | 14 | from ...utils.filemanip import split_filename, fname_presuffix
|
15 | 15 |
|
16 | 16 | from ..base import (
|
@@ -44,32 +44,25 @@ def version():
|
44 | 44 |
|
45 | 45 | """
|
46 | 46 | try:
|
47 |
| - clout = CommandLine(command='afni_vcheck', |
| 47 | + clout = CommandLine(command='afni --version', |
48 | 48 | terminal_output='allatonce').run()
|
49 |
| - |
50 |
| - # Try to parse the version number |
51 |
| - currv = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip() |
52 | 49 | except IOError:
|
53 | 50 | # If afni_vcheck is not present, return None
|
54 |
| - IFLOGGER.warn('afni_vcheck executable not found.') |
| 51 | + IFLOGGER.warn('afni executable not found.') |
55 | 52 | return None
|
56 |
| - except RuntimeError as e: |
57 |
| - # If AFNI is outdated, afni_vcheck throws error. |
58 |
| - # Show new version, but parse current anyways. |
59 |
| - currv = str(e).split('\n')[4].split('=', 1)[1].strip() |
60 |
| - nextv = str(e).split('\n')[6].split('=', 1)[1].strip() |
61 |
| - IFLOGGER.warn( |
62 |
| - 'AFNI is outdated, detected version %s and %s is available.' % (currv, nextv)) |
63 |
| - |
64 |
| - if currv.startswith('AFNI_'): |
65 |
| - currv = currv[5:] |
66 |
| - |
67 |
| - v = currv.split('.') |
68 |
| - try: |
69 |
| - v = [int(n) for n in v] |
70 |
| - except ValueError: |
71 |
| - return currv |
72 |
| - return tuple(v) |
| 53 | + |
| 54 | + version_stamp = clout.runtime.stdout.split('\n')[0].split('Version ')[1] |
| 55 | + if version_stamp.startswith('AFNI'): |
| 56 | + version_stamp = version_stamp.split('AFNI_')[1] |
| 57 | + elif version_stamp.startswith('Debian'): |
| 58 | + version_stamp = version_stamp.split('Debian-')[1].split('~')[0] |
| 59 | + else: |
| 60 | + return None |
| 61 | + |
| 62 | + version = LooseVersion(version_stamp.replace('_', '.')).version[:3] |
| 63 | + if version[0] < 1000: |
| 64 | + version[0] = version[0] + 2000 |
| 65 | + return tuple(version) |
73 | 66 |
|
74 | 67 | @classmethod
|
75 | 68 | def output_type_to_ext(cls, outputtype):
|
|
0 commit comments