Exemplo n.º 1
0
    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())
Exemplo n.º 2
0
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.EXTERNALS_FOLDER_PARENT = os.path.dirname(self.BIN_FOLDER)

        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)

        #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_EXE_NAME(self):
        """
        Returns the name of the python executable depending on the specific OS
        """
        if self.env.is_windows():
            return 'python.exe'
        else:
            return 'python'

    @property
    def PYTHON_PATH(self):
        """
        Get Python path, based on current environment.
        """
        exe_name = self.PYTHON_EXE_NAME
        if self.env.is_development():
            python_path = 'python'
        elif self.env.is_windows_deployment() or self.env.is_linux_deployment(
        ):
            python_path = os.path.join(os.path.dirname(self.BIN_FOLDER), 'exe',
                                       exe_name)
        elif self.env.is_mac_deployment():
            root_dir = os.path.dirname(
                os.path.dirname(
                    os.path.dirname(os.path.dirname(self.BIN_FOLDER))))
            python_path = os.path.join(root_dir, 'MacOS', exe_name)
        else:
            python_path = 'python'

        try:
            # check if file actually exists
            os.stat(python_path)
            return python_path
        except:
            # otherwise best guess is the current interpreter!
            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