def __init__(self): self.manager = stored.SettingsManager(self.TVB_CONFIG_FILE) # Actual storage of all TVB related files self.KEYCLOAK_CONFIG = self.manager.get_attribute( stored.KEY_KC_CONFIGURATION, '') self.KEYCLOAK_LOGIN_ENABLED = self.manager.get_attribute( stored.KEY_ENABLE_KC_LOGIN, False, eval) self.KEYCLOAK_WEB_CONFIG = self.manager.get_attribute( stored.KEY_KC_WEB_CONFIGURATION, '') self.TVB_STORAGE = self.manager.get_attribute(stored.KEY_STORAGE, self.FIRST_RUN_STORAGE, str) self.UPLOAD_KEY_PATH = self.manager.get_attribute( stored.KEY_UPLOAD_PRIVATE_KEY_PATH, None, str) self.TRACE_USER_ACTIONS = self.manager.get_attribute( stored.KEY_TRACE_USER_ACTIONS, False, eval) self.TVB_LOG_FOLDER = os.path.join(self.TVB_STORAGE, "logs") self.TVB_TEMP_FOLDER = os.path.join(self.TVB_STORAGE, "TEMP") self.env = Environment() self.cluster = ClusterSettings(self.manager) self.hpc = HPCSettings(self.manager) self.web = WebSettings(self.manager) self.db = DBSettings(self.manager, self.DEFAULT_STORAGE, self.TVB_STORAGE) self.version = VersionSettings(self.manager, self.BIN_FOLDER) self.file_storage = self.manager.get_attribute(stored.KEY_FILE_STORAGE, 'h5', str) self.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.BIN_FOLDER) if not self.env.is_distribution(): self.EXTERNALS_FOLDER_PARENT = os.path.dirname( self.EXTERNALS_FOLDER_PARENT) # The path to the matlab executable (if existent). Otherwise just return an empty string. value = self.manager.get_attribute(stored.KEY_MATLAB_EXECUTABLE, '', str) or '' if value == 'None': value = '' self.MATLAB_EXECUTABLE = value # Maximum number of vertices acceptable o be part of a surface at import time. self.MAX_SURFACE_VERTICES_NUMBER = self.manager.get_attribute( stored.KEY_MAX_NR_SURFACE_VERTEX, 300000, int) # Max number of ops that can be scheduled from UI in a PSE. To be correlated with the oarsub limitations self.MAX_RANGE_NUMBER = self.manager.get_attribute( stored.KEY_MAX_RANGE_NR, 2000, int) # Max number of threads in the pool of ops running in parallel. TO be correlated with CPU cores self.MAX_THREADS_NUMBER = self.manager.get_attribute( stored.KEY_MAX_THREAD_NR, 4, int) self.OPERATIONS_BACKGROUND_JOB_INTERVAL = self.manager.get_attribute( stored.KEY_OP_BACKGROUND_INTERVAL, 60, int) # The maximum disk space that can be used by one single user, in KB. self.MAX_DISK_SPACE = self.manager.get_attribute( stored.KEY_MAX_DISK_SPACE_USR, 5 * 1024 * 1024, int)
def __init__(self, web_enabled=True): self.manager = stored.SettingsManager(self.TVB_CONFIG_FILE) ## Actual storage of all TVB related files self.TVB_STORAGE = self.manager.get_attribute(stored.KEY_STORAGE, self.FIRST_RUN_STORAGE, unicode) self.TVB_LOG_FOLDER = os.path.join(self.TVB_STORAGE, "logs") self.TVB_TEMP_FOLDER = os.path.join(self.TVB_STORAGE, "TEMP") self.TVB_PATH = self.manager.get_attribute(stored.KEY_TVB_PATH, '') self.env = Environment() self.cluster = ClusterSettings(self.manager) self.web = WebSettings(self.manager, web_enabled) self.db = DBSettings(self.manager, self.DEFAULT_STORAGE, self.TVB_STORAGE) self.version = VersionSettings(self.manager, self.BIN_FOLDER) self.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.BIN_FOLDER) if not self.env.is_distribution(): self.EXTERNALS_FOLDER_PARENT = os.path.dirname( self.EXTERNALS_FOLDER_PARENT) # The path to the matlab executable (if existent). Otherwise just return an empty string. value = self.manager.get_attribute(stored.KEY_MATLAB_EXECUTABLE, '', str) or '' if value == 'None': value = '' self.MATLAB_EXECUTABLE = value # Maximum number of vertices acceptable o be part of a surface at import time. self.MAX_SURFACE_VERTICES_NUMBER = self.manager.get_attribute( stored.KEY_MAX_NR_SURFACE_VERTEX, 300000, int) # Max number of ops that can be scheduled from UI in a PSE. To be correlated with the oarsub limitations self.MAX_RANGE_NUMBER = self.manager.get_attribute( stored.KEY_MAX_RANGE_NR, 2000, int) # Max number of threads in the pool of ops running in parallel. TO be correlated with CPU cores self.MAX_THREADS_NUMBER = self.manager.get_attribute( stored.KEY_MAX_THREAD_NR, 4, int) # The maximum disk space that can be used by one single user, in KB. self.MAX_DISK_SPACE = self.manager.get_attribute( stored.KEY_MAX_DISK_SPACE_USR, 5 * 1024 * 1024, int) ## Configure Traits self.TRAITS_CONFIGURATION = EnhancedDictionary() self.TRAITS_CONFIGURATION.interface_method_name = 'interface' self.TRAITS_CONFIGURATION.use_storage = True
def new_function(*args, **kwargs): """ Wrapper function for Linux TVB altered environment variables. Apply this only on Linux, as that is the only env in which TVB start scripts alter LD_*_PATH env vars. :return: Result of the wrapped function """ if not Environment().is_linux_deployment(): # Do nothing return func(*args, **kwargs) original_ld_library_path = _remove_from_path('LD_LIBRARY_PATH', 2, 'tvb_data') original_ld_run_path = _remove_from_path('LD_RUN_PATH', 2, 'tvb_data') result = func(*args, **kwargs) ## Restore environment settings after function executed. if original_ld_library_path: os.environ['LD_LIBRARY_PATH'] = original_ld_library_path if original_ld_run_path: os.environ['LD_RUN_PATH'] = original_ld_run_path return result
class TvbProfile(): """ ENUM-like class with current TVB profile and accepted values. """ LIBRARY_PROFILE = "LIBRARY_PROFILE" COMMAND_PROFILE = "COMMAND_PROFILE" WEB_PROFILE = "WEB_PROFILE" DESKTOP_PROFILE = "DESKTOP_PROFILE" TEST_LIBRARY_PROFILE = "TEST_LIBRARY_PROFILE" TEST_POSTGRES_PROFILE = "TEST_POSTGRES_PROFILE" TEST_SQLITE_PROFILE = "TEST_SQLITE_PROFILE" ALL = [ LIBRARY_PROFILE, COMMAND_PROFILE, WEB_PROFILE, DESKTOP_PROFILE, TEST_POSTGRES_PROFILE, TEST_SQLITE_PROFILE, TEST_LIBRARY_PROFILE ] REGISTERED_PROFILES = {} CURRENT_PROFILE_NAME = None current = BaseSettingsProfile(False) env = Environment() _meta_path_copier = MetaPathCopier() _meta_path_copier.deepcopy() @classmethod def set_profile(cls, selected_profile, in_operation=False, run_init=True): """ Sets TVB profile and do related initializations. """ ### Ensure Python is using UTF-8 encoding (otherwise default encoding is ASCII) ### We should make sure UTF-8 gets set before reading from any TVB files ### e.g. TVB_STORAGE will differ if the .tvb.configuration file contains non-ascii bytes ### most of the comments in the simulator are having pieces outside of ascii coverage if cls.env.is_development( ) and sys.getdefaultencoding().lower() != 'utf-8': reload(sys) sys.setdefaultencoding('utf-8') if selected_profile is not None: ## Restore sys.meta_path, as some profiles (Library) are adding something cls._meta_path_copier.restore() cls._load_framework_profiles(selected_profile) cls._build_profile_class(selected_profile, in_operation, run_init) @classmethod def _build_profile_class(cls, selected_profile, in_operation=False, run_init=True): """ :param selected_profile: Profile name to be loaded. """ if selected_profile in cls.REGISTERED_PROFILES: current_class = cls.REGISTERED_PROFILES[selected_profile] cls.current = current_class() cls.CURRENT_PROFILE_NAME = selected_profile if in_operation: # set flags IN_OPERATION, before initialize** calls, to avoid LoggingBuilder being created there cls.current.prepare_for_operation_mode() if not cls.env.is_development(): # initialize deployment first, because in case of a contributor setup this tried to reload # and initialize_profile loads already too many tvb modules, # making the reload difficult and prone to more failures cls.current.initialize_for_deployment() if run_init: cls.current.initialize_profile() else: msg = "Invalid profile name %r, expected one of %r" msg %= (selected_profile, cls.ALL) raise Exception(msg) @classmethod def _load_framework_profiles(cls, new_profile): from tvb.basic.config.profile_settings import LibrarySettingsProfile, TestLibraryProfile cls.REGISTERED_PROFILES[ TvbProfile.LIBRARY_PROFILE] = LibrarySettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_LIBRARY_PROFILE] = TestLibraryProfile if not cls.is_library_mode(new_profile): try: from tvb.config.profile_settings import CommandSettingsProfile, WebSettingsProfile from tvb.config.profile_settings import TestPostgresProfile, TestSQLiteProfile cls.REGISTERED_PROFILES[ TvbProfile.COMMAND_PROFILE] = CommandSettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.WEB_PROFILE] = WebSettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_POSTGRES_PROFILE] = TestPostgresProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_SQLITE_PROFILE] = TestSQLiteProfile except ImportError: pass @staticmethod def is_library_mode(new_profile=None): lib_profiles = [ TvbProfile.LIBRARY_PROFILE, TvbProfile.TEST_LIBRARY_PROFILE ] result = (new_profile in lib_profiles or (new_profile is None and TvbProfile.CURRENT_PROFILE_NAME in lib_profiles) or not TvbProfile.env.is_framework_present()) # Make sure default settings are not failing because we are not finding some modules if (new_profile is None and TvbProfile.CURRENT_PROFILE_NAME is None and not TvbProfile.env.is_framework_present()): TvbProfile.set_profile(TvbProfile.LIBRARY_PROFILE) return result @staticmethod def is_first_run(): return TvbProfile.current.manager.is_first_run()
class TvbProfile(object): """ ENUM-like class with current TVB profile and accepted values. """ LIBRARY_PROFILE = "LIBRARY_PROFILE" COMMAND_PROFILE = "COMMAND_PROFILE" WEB_PROFILE = "WEB_PROFILE" MATLAB_PROFILE = "MATLAB_PROFILE" TEST_LIBRARY_PROFILE = "TEST_LIBRARY_PROFILE" TEST_POSTGRES_PROFILE = "TEST_POSTGRES_PROFILE" TEST_SQLITE_PROFILE = "TEST_SQLITE_PROFILE" ALL = [ LIBRARY_PROFILE, COMMAND_PROFILE, WEB_PROFILE, MATLAB_PROFILE, TEST_POSTGRES_PROFILE, TEST_SQLITE_PROFILE, TEST_LIBRARY_PROFILE ] REGISTERED_PROFILES = {} CURRENT_PROFILE_NAME = None current = BaseSettingsProfile(False) env = Environment() @classmethod def set_profile(cls, selected_profile, in_operation=False, run_init=True): """ Sets TVB profile and do related initializations. """ if selected_profile is not None: cls._load_framework_profiles(selected_profile) cls._build_profile_class(selected_profile, in_operation, run_init) @classmethod def _build_profile_class(cls, selected_profile, in_operation=False, run_init=True): """ :param selected_profile: Profile name to be loaded. """ if selected_profile in cls.REGISTERED_PROFILES: current_class = cls.REGISTERED_PROFILES[selected_profile] cls.current = current_class() cls.CURRENT_PROFILE_NAME = selected_profile if in_operation: # set flags IN_OPERATION, before initialize** calls, to avoid LoggingBuilder being created there cls.current.prepare_for_operation_mode() if cls.env.is_distribution(): # initialize deployment first, because in case of a contributor setup this tried to reload # and initialize_profile loads already too many tvb modules, # making the reload difficult and prone to more failures cls.current.initialize_for_deployment() if run_init: cls.current.initialize_profile() else: msg = "Invalid profile name %r, expected one of %r" msg %= (selected_profile, cls.ALL) raise Exception(msg) @classmethod def _load_framework_profiles(cls, new_profile): from tvb.basic.config.profile_settings import LibrarySettingsProfile, TestLibraryProfile, MATLABLibraryProfile cls.REGISTERED_PROFILES[ TvbProfile.LIBRARY_PROFILE] = LibrarySettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_LIBRARY_PROFILE] = TestLibraryProfile cls.REGISTERED_PROFILES[ TvbProfile.MATLAB_PROFILE] = MATLABLibraryProfile if not cls.is_library_mode(new_profile): try: from tvb.config.profile_settings import CommandSettingsProfile, WebSettingsProfile from tvb.config.profile_settings import TestPostgresProfile, TestSQLiteProfile cls.REGISTERED_PROFILES[ TvbProfile.COMMAND_PROFILE] = CommandSettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.WEB_PROFILE] = WebSettingsProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_POSTGRES_PROFILE] = TestPostgresProfile cls.REGISTERED_PROFILES[ TvbProfile.TEST_SQLITE_PROFILE] = TestSQLiteProfile except ImportError: pass @staticmethod def is_library_mode(new_profile=None): lib_profiles = [ TvbProfile.LIBRARY_PROFILE, TvbProfile.TEST_LIBRARY_PROFILE ] result = (new_profile in lib_profiles or (new_profile is None and TvbProfile.CURRENT_PROFILE_NAME in lib_profiles) or not TvbProfile.env.is_framework_present()) # Make sure default settings are not failing because we are not finding some modules if (new_profile is None and TvbProfile.CURRENT_PROFILE_NAME is None and not TvbProfile.env.is_framework_present()): TvbProfile.set_profile(TvbProfile.LIBRARY_PROFILE) return result @staticmethod def is_first_run(): return TvbProfile.current.manager.is_first_run()
for target_file, content in config.commands_map.items(): config.command_factory(join(config.target_root, target_file), content) _log(1, "Introspecting 3rd party licenses...") zip_name = generate_artefact( config.target_site_packages, extra_licenses_check=config.to_read_licenses_from) zipfile.ZipFile(zip_name).extractall(config.target_3rd_licences_folder) os.remove(zip_name) _log(1, "Packing final ZIP...") if os.path.exists(config.target_before_zip): shutil.rmtree(config.target_before_zip, True) os.mkdir(config.target_before_zip) shutil.move(config.target_root, config.target_before_zip) _compress(config.target_before_zip, config.artifact_pth) shutil.rmtree(config.target_before_zip, True) _log(1, "Done TVB package " + config.artifact_pth) if __name__ == "__main__": if Environment.is_mac(): prepare_anaconda_dist(Config.mac64()) elif Environment.is_windows(): prepare_anaconda_dist(Config.win64()) else: prepare_anaconda_dist(Config.linux64())
class BaseSettingsProfile(object): TVB_CONFIG_FILE = os.path.expanduser(os.path.join("~", '.tvb.configuration')) DEFAULT_STORAGE = os.path.expanduser(os.path.join('~', 'TVB' + os.sep)) FIRST_RUN_STORAGE = os.path.expanduser(os.path.join('~', '.tvb-temp')) LOGGER_CONFIG_FILE_NAME = "logger_config.conf" # Access rights for TVB generated files/folders. ACCESS_MODE_TVB_FILES = 0744 ## Number used for estimation of TVB used storage space MAGIC_NUMBER = 9 def __init__(self, web_enabled=True): self.manager = stored.SettingsManager(self.TVB_CONFIG_FILE) ## Actual storage of all TVB related files self.TVB_STORAGE = self.manager.get_attribute(stored.KEY_STORAGE, self.FIRST_RUN_STORAGE, unicode) self.TVB_LOG_FOLDER = os.path.join(self.TVB_STORAGE, "logs") self.TVB_TEMP_FOLDER = os.path.join(self.TVB_STORAGE, "TEMP") self.TVB_PATH = self.manager.get_attribute(stored.KEY_TVB_PATH, '') self.env = Environment() self.cluster = ClusterSettings(self.manager) self.web = WebSettings(self.manager, web_enabled) self.db = DBSettings(self.manager, self.DEFAULT_STORAGE, self.TVB_STORAGE) self.version = VersionSettings(self.manager, self.BIN_FOLDER) self.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.BIN_FOLDER) if self.env.is_development(): self.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.EXTERNALS_FOLDER_PARENT) #The path to the matlab executable (if existent). Otherwise just return an empty string. value = self.manager.get_attribute(stored.KEY_MATLAB_EXECUTABLE, '', str) or '' if value == 'None': value = '' self.MATLAB_EXECUTABLE = value # Maximum number of vertices acceptable o be part of a surface at import time. self.MAX_SURFACE_VERTICES_NUMBER = self.manager.get_attribute(stored.KEY_MAX_NR_SURFACE_VERTEX, 300000, int) # Max number of ops that can be scheduled from UI in a PSE. To be correlated with the oarsub limitations self.MAX_RANGE_NUMBER = self.manager.get_attribute(stored.KEY_MAX_RANGE_NR, 2000, int) # Max number of threads in the pool of ops running in parallel. TO be correlated with CPU cores self.MAX_THREADS_NUMBER = self.manager.get_attribute(stored.KEY_MAX_THREAD_NR, 4, int) #The maximum disk space that can be used by one single user, in KB. self.MAX_DISK_SPACE = self.manager.get_attribute(stored.KEY_MAX_DISK_SPACE_USR, 5 * 1024 * 1024, int) ## Configure Traits self.TRAITS_CONFIGURATION = EnhancedDictionary() self.TRAITS_CONFIGURATION.interface_method_name = 'interface' self.TRAITS_CONFIGURATION.use_storage = True @property def BIN_FOLDER(self): """ Return path towards tvb_bin location. It will be used in some environment for determining the starting point """ try: import tvb_bin return os.path.dirname(os.path.abspath(tvb_bin.__file__)) except ImportError: return "." @property def PYTHON_INTERPRETER_PATH(self): """ Get Python path, based on current environment. """ if self.env.is_mac_deployment(): return os.path.join(os.path.dirname(sys.executable), "python") return sys.executable def prepare_for_operation_mode(self): """ Overwrite PostgreSQL number of connections when executed in the context of a node. """ self.db.MAX_CONNECTIONS = self.db.MAX_ASYNC_CONNECTIONS self.cluster.IN_OPERATION_EXECUTION_PROCESS = True def initialize_profile(self): """ Make sure tvb folders are created. """ if not os.path.exists(self.TVB_LOG_FOLDER): os.makedirs(self.TVB_LOG_FOLDER) if not os.path.exists(self.TVB_TEMP_FOLDER): os.makedirs(self.TVB_TEMP_FOLDER) if not os.path.exists(self.TVB_STORAGE): os.makedirs(self.TVB_STORAGE) def initialize_for_deployment(self): library_folder = self.env.get_library_folder(self.BIN_FOLDER) if self.env.is_windows_deployment(): # Add self.TVB_PATH as first in PYTHONPATH so we can find TVB there in case of GIT contributors self.env.setup_python_path(self.TVB_PATH, library_folder, os.path.join(library_folder, 'lib-tk')) self.env.append_to_path(library_folder) self.env.setup_tk_tcl_environ(library_folder) if self.env.is_mac_deployment(): # MacOS package structure is in the form: # Contents/Resorces/lib/python2.7/tvb . PYTHONPATH needs to be set # at the level Contents/Resources/lib/python2.7/ and the root path # from where to start looking for TK and TCL up to Contents/ tcl_root = os.path.dirname(os.path.dirname(os.path.dirname(library_folder))) self.env.setup_tk_tcl_environ(tcl_root) self.env.setup_python_path(self.TVB_PATH, library_folder, os.path.join(library_folder, 'site-packages.zip'), os.path.join(library_folder, 'lib-dynload')) if self.env.is_linux_deployment(): # Note that for the Linux package some environment variables like LD_LIBRARY_PATH, # LD_RUN_PATH, PYTHONPATH and PYTHONHOME are set also in the startup scripts. self.env.setup_python_path(self.TVB_PATH, library_folder, os.path.join(library_folder, 'lib-tk')) self.env.setup_tk_tcl_environ(library_folder) ### Correctly set MatplotLib Path, before start. mpl_data_path_maybe = os.path.join(library_folder, 'mpl-data') try: os.stat(mpl_data_path_maybe) os.environ['MATPLOTLIBDATA'] = mpl_data_path_maybe except: pass if self.TVB_PATH: # In case of contributor setup, we want to make sure that all dev files are loaded first, so # we need to reload all tvb related modules, since any call done with # 'python -m ...' will consider the current folder as the first to search in. sys.path = os.environ.get("PYTHONPATH", "").split(os.pathsep) + sys.path for key in sys.modules.keys(): if (key.startswith("tvb") and sys.modules[key] and not key.startswith("tvb.basic.profile") and not 'profile_settings' in key): try: reload(sys.modules[key]) except LibraryImportError: pass
_log(1, "Modifying PTH " + config.easy_install_pth) _modify_pth(config.easy_install_pth) _log(1, "Creating command files:") for target_file, content in config.commands_map.items(): config.command_factory(join(config.target_root, target_file), content) _log(1, "Introspecting 3rd party licenses...") zip_name = generate_artefact( config.target_site_packages, extra_licenses_check=config.to_read_licenses_from) zipfile.ZipFile(zip_name).extractall(config.target_3rd_licences_folder) os.remove(zip_name) _log(1, "Packing final ZIP...") if os.path.exists(config.target_before_zip): shutil.rmtree(config.target_before_zip, True) os.mkdir(config.target_before_zip) shutil.move(config.target_root, config.target_before_zip) _compress(config.target_before_zip, config.artifact_pth) shutil.rmtree(config.target_before_zip, True) _log(1, "Done TVB package " + config.artifact_pth) if __name__ == "__main__": if Environment.is_windows(): prepare_anaconda_dist(Config.win64()) else: prepare_anaconda_dist(Config.linux64())
class BaseSettingsProfile(object): TVB_USER_HOME = os.environ.get('TVB_USER_HOME', '~') TVB_CONFIG_FILE = os.path.expanduser( os.path.join(TVB_USER_HOME, '.tvb.configuration')) DEFAULT_STORAGE = os.path.expanduser( os.path.join(TVB_USER_HOME, 'TVB' + os.sep)) FIRST_RUN_STORAGE = os.path.expanduser( os.path.join(TVB_USER_HOME, '.tvb-temp')) LOGGER_CONFIG_FILE_NAME = "logger_config.conf" # Access rights for TVB generated files/folders. ACCESS_MODE_TVB_FILES = 0o744 # Number used for estimation of TVB used storage space MAGIC_NUMBER = 9 def __init__(self): self.manager = stored.SettingsManager(self.TVB_CONFIG_FILE) # Actual storage of all TVB related files self.KEYCLOAK_CONFIG = self.manager.get_attribute( stored.KEY_KC_CONFIGURATION, '') self.KEYCLOAK_LOGIN_ENABLED = self.manager.get_attribute( stored.KEY_ENABLE_KC_LOGIN, False, eval) self.KEYCLOAK_WEB_CONFIG = self.manager.get_attribute( stored.KEY_KC_WEB_CONFIGURATION, '') self.TVB_STORAGE = self.manager.get_attribute(stored.KEY_STORAGE, self.FIRST_RUN_STORAGE, str) self.UPLOAD_KEY_PATH = self.manager.get_attribute( stored.KEY_UPLOAD_PRIVATE_KEY_PATH, None, str) self.TRACE_USER_ACTIONS = self.manager.get_attribute( stored.KEY_TRACE_USER_ACTIONS, False, eval) self.TVB_LOG_FOLDER = os.path.join(self.TVB_STORAGE, "logs") self.TVB_TEMP_FOLDER = os.path.join(self.TVB_STORAGE, "TEMP") self.env = Environment() self.cluster = ClusterSettings(self.manager) self.hpc = HPCSettings(self.manager) self.web = WebSettings(self.manager) self.db = DBSettings(self.manager, self.DEFAULT_STORAGE, self.TVB_STORAGE) self.version = VersionSettings(self.manager, self.BIN_FOLDER) self.file_storage = self.manager.get_attribute(stored.KEY_FILE_STORAGE, 'h5', str) self.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.BIN_FOLDER) if not self.env.is_distribution(): self.EXTERNALS_FOLDER_PARENT = os.path.dirname( self.EXTERNALS_FOLDER_PARENT) # The path to the matlab executable (if existent). Otherwise just return an empty string. value = self.manager.get_attribute(stored.KEY_MATLAB_EXECUTABLE, '', str) or '' if value == 'None': value = '' self.MATLAB_EXECUTABLE = value # Maximum number of vertices acceptable o be part of a surface at import time. self.MAX_SURFACE_VERTICES_NUMBER = self.manager.get_attribute( stored.KEY_MAX_NR_SURFACE_VERTEX, 300000, int) # Max number of ops that can be scheduled from UI in a PSE. To be correlated with the oarsub limitations self.MAX_RANGE_NUMBER = self.manager.get_attribute( stored.KEY_MAX_RANGE_NR, 2000, int) # Max number of threads in the pool of ops running in parallel. TO be correlated with CPU cores self.MAX_THREADS_NUMBER = self.manager.get_attribute( stored.KEY_MAX_THREAD_NR, 4, int) # The maximum disk space that can be used by one single user, in KB. self.MAX_DISK_SPACE = self.manager.get_attribute( stored.KEY_MAX_DISK_SPACE_USR, 5 * 1024 * 1024, int) @property def BIN_FOLDER(self): """ Return path towards tvb_bin location. It will be used in some environment for determining the starting point """ try: import tvb_bin return os.path.dirname(os.path.abspath(tvb_bin.__file__)) except ImportError: return "." @property def PYTHON_INTERPRETER_PATH(self): """ Get Python path, based on current environment. """ if self.env.is_mac_deployment(): return os.path.join(os.path.dirname(sys.executable), "python") return sys.executable def prepare_for_operation_mode(self): """ Overwrite PostgreSQL number of connections when executed in the context of a node. """ self.db.MAX_CONNECTIONS = self.db.MAX_ASYNC_CONNECTIONS self.cluster.IN_OPERATION_EXECUTION_PROCESS = True self.hpc.IN_OPERATION_EXECUTION_PROCESS = True def initialize_profile(self): """ Make sure tvb folders are created. """ if not os.path.exists(self.TVB_LOG_FOLDER): os.makedirs(self.TVB_LOG_FOLDER) if not os.path.exists(self.TVB_TEMP_FOLDER): os.makedirs(self.TVB_TEMP_FOLDER) if not os.path.exists(self.TVB_STORAGE): os.makedirs(self.TVB_STORAGE) def initialize_for_deployment(self): library_folder = self.env.get_library_folder(self.BIN_FOLDER) if self.env.is_windows_deployment(): self.env.setup_python_path(library_folder, os.path.join(library_folder, 'lib-tk')) self.env.append_to_path(library_folder) self.env.setup_tk_tcl_environ(library_folder) if self.env.is_mac_deployment(): # MacOS package structure is in the form: # Contents/Resorces/lib/python2.7/tvb . PYTHONPATH needs to be set # at the level Contents/Resources/lib/python2.7/ and the root path # from where to start looking for TK and TCL up to Contents/ tcl_root = os.path.dirname( os.path.dirname(os.path.dirname(library_folder))) self.env.setup_tk_tcl_environ(tcl_root) self.env.setup_python_path( library_folder, os.path.join(library_folder, 'site-packages.zip'), os.path.join(library_folder, 'lib-dynload')) if self.env.is_linux_deployment(): # Note that for the Linux package some environment variables like LD_LIBRARY_PATH, # LD_RUN_PATH, PYTHONPATH and PYTHONHOME are set also in the startup scripts. self.env.setup_python_path(library_folder, os.path.join(library_folder, 'lib-tk')) self.env.setup_tk_tcl_environ(library_folder) # Correctly set MatplotLib Path, before start. mpl_data_path_maybe = os.path.join(library_folder, 'mpl-data') try: os.stat(mpl_data_path_maybe) os.environ['MATPLOTLIBDATA'] = mpl_data_path_maybe except: pass