-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcm2niix.py
executable file
·67 lines (44 loc) · 1.6 KB
/
dcm2niix.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pnlpipe_software import downloadGithubRepo, getCommitInfo, getSoftDir, checkExists, envFromDict
import psutil
from plumbum import local, FG
from plumbum.cmd import cmake
import logging
from os import getenv
DEFAULT_HASH = 'c0a3731'
def make(commit=DEFAULT_HASH):
softdir = getSoftDir()
if commit != 'master':
if checkExists(get_path(commit)):
return
blddir = softdir / "dcm2niix-build"
with local.cwd(softdir):
repo = downloadGithubRepo('rordenlab/dcm2niix', commit)
sha, date = getCommitInfo(repo)
outbinary = get_path(sha)
if checkExists(outbinary):
return
logging.info("Build code:")
blddir.mkdir()
with local.cwd(blddir):
cmake(repo, "-DUSE_STATIC_RUNTIME:BOOL=OFF")
import plumbum.cmd
plumbum.cmd.make['-j', getenv('PNLPIPE_BUILD_NCPU','4')] & FG
binary = blddir / 'bin/dcm2niix'
outbinary.dirname.mkdir()
binary.move(outbinary)
# chmod('a-w', outbinary)
with open(outbinary.dirname / 'env.sh', 'w') as f:
f.write("export PATH={}:$PATH".format(outbinary.dirname))
symlink = get_path(date).dirname
print("Make symlink: {} -> {}".format(symlink, get_path(sha).dirname))
symlink.unlink()
get_path(sha).dirname.symlink(symlink)
blddir.delete()
logging.info("Made '{}'".format(outbinary))
logging.info("Made '{}'".format(get_path(date)))
def get_path(hash=DEFAULT_HASH):
return getSoftDir() / ('dcm2niix-' + hash) / 'dcm2niix'
def env_dict(hash):
return { 'PATH': get_path(hash).dirname }
def env(bthash):
return envFromDict(env_dict(bthash))