/usr/share/pyshared/nipype/utils/config.py is in python-nipype 0.9.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
'''
Created on 20 Apr 2010
logging options : INFO, DEBUG
hash_method : content, timestamp
@author: Chris Filo Gorgolewski
'''
import ConfigParser
from json import load, dump
import os
import shutil
from StringIO import StringIO
from warnings import warn
from ..external import portalocker
homedir = os.environ['HOME']
default_cfg = """
[logging]
workflow_level = INFO
filemanip_level = INFO
interface_level = INFO
log_to_file = false
log_directory = %s
log_size = 16384000
log_rotate = 4
[execution]
create_report = true
crashdump_dir = %s
display_variable = :1
hash_method = timestamp
job_finished_timeout = 5
keep_inputs = false
local_hash_check = true
matplotlib_backend = Agg
plugin = Linear
remove_node_directories = false
remove_unnecessary_outputs = true
single_thread_matlab = true
stop_on_first_crash = false
stop_on_first_rerun = false
use_relative_paths = false
stop_on_unknown_version = false
write_provenance = false
parameterize_dirs = true
[check]
interval = 1209600
""" % (homedir, os.getcwd())
class NipypeConfig(object):
"""Base nipype config class
"""
def __init__(self, *args, **kwargs):
self._config = ConfigParser.ConfigParser()
config_dir = os.path.expanduser('~/.nipype')
if not os.path.exists(config_dir):
os.makedirs(config_dir)
old_config_file = os.path.expanduser('~/.nipype.cfg')
new_config_file = os.path.join(config_dir, 'nipype.cfg')
# To be deprecated in two releases
if os.path.exists(old_config_file):
if os.path.exists(new_config_file):
msg=("Detected presence of both old (%s, used by versions "
"< 0.5.2) and new (%s) config files. This version will "
"proceed with the new one. We advise to merge settings "
"and remove old config file if you are not planning to "
"use previous releases of nipype.") % (old_config_file,
new_config_file)
warn(msg)
else:
warn("Moving old config file from: %s to %s" % (old_config_file,
new_config_file))
shutil.move(old_config_file, new_config_file)
self.data_file = os.path.join(config_dir, 'nipype.json')
self._config.readfp(StringIO(default_cfg))
self._config.read([new_config_file, old_config_file, 'nipype.cfg'])
def set_default_config(self):
self._config.readfp(StringIO(default_cfg))
def enable_debug_mode(self):
"""Enables debug configuration
"""
self._config.set('execution', 'stop_on_first_crash', 'true')
self._config.set('execution', 'remove_unnecessary_outputs', 'false')
self._config.set('execution', 'keep_inputs', 'true')
self._config.set('logging', 'workflow_level', 'DEBUG')
self._config.set('logging', 'interface_level', 'DEBUG')
def set_log_dir(self, log_dir):
"""Sets logging directory
This should be the first thing that is done before any nipype class
with logging is imported.
"""
self._config.set('logging', 'log_directory', log_dir)
def get(self, section, option):
return self._config.get(section, option)
def set(self, section, option, value):
return self._config.set(section, option, value)
def getboolean(self, section, option):
return self._config.getboolean(section, option)
def has_option(self, section, option):
return self._config.has_option(section, option)
@property
def _sections(self):
return self._config._sections
def get_data(self, key):
if not os.path.exists(self.data_file):
return None
with open(self.data_file, 'rt') as file:
portalocker.lock(file, portalocker.LOCK_EX)
datadict = load(file)
if key in datadict:
return datadict[key]
return None
def save_data(self, key, value):
datadict = {}
if os.path.exists(self.data_file):
with open(self.data_file, 'rt') as file:
portalocker.lock(file, portalocker.LOCK_EX)
datadict = load(file)
with open(self.data_file, 'wt') as file:
portalocker.lock(file, portalocker.LOCK_EX)
datadict[key] = value
dump(datadict, file)
def update_config(self, config_dict):
for section in ['execution', 'logging', 'check']:
if section in config_dict:
for key, val in config_dict[section].items():
if not key.startswith('__'):
self._config.set(section, key, str(val))
def update_matplotlib(self):
import matplotlib
matplotlib.use(self.get('execution', 'matplotlib_backend'))
def enable_provenance(self):
self._config.set('execution', 'write_provenance', 'true')
self._config.set('execution', 'hash_method', 'content')
|