[go: up one dir, main page]

File: toollib.py

package info (click to toggle)
dipy 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,828 kB
  • sloc: python: 63,790; makefile: 258; pascal: 167; sh: 131; ansic: 106
file content (46 lines) | stat: -rw-r--r-- 1,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Various utilities common to nibabel release and maintenance tools.
"""
# Library imports
import os
import sys

from distutils.dir_util import remove_tree

# Useful shorthands
pjoin = os.path.join
cd = os.chdir

# Utility functions
def c(cmd):
    """Run system command, raise SystemExit if it returns an error."""
    print ("$",cmd)
    stat = os.system(cmd)
    #stat = 0  # Uncomment this and comment previous to run in debug mode
    if stat:
        raise SystemExit("Command %s failed with code: %s" % (cmd, stat))


def get_dipydir():
    """Get dipy directory from command line, or assume it's the one above."""

    # Initialize arguments and check location
    try:
        dipydir = sys.argv[1]
    except IndexError:
        dipydir = '..'

    dipydir = os.path.abspath(dipydir)

    cd(dipydir)
    if not os.path.isdir('dipy') and os.path.isfile('setup.py'):
        raise SystemExit('Invalid dipy directory: %s' % dipydir)
    return dipydir

# import compileall and then get dir os.path.split
def compile_tree():
    """Compile all Python files below current directory."""
    stat = os.system('python -m compileall .')
    if stat:
        msg = '*** ERROR: Some Python files in tree do NOT compile! ***\n'
        msg += 'See messages above for the actual file that produced it.\n'
        raise SystemExit(msg)