示例#1
0
    def is_distribution():
        """
        Return True when TVB is used with Python installed natively (with GitHub clone, SVN, pip or conda)
        """
        svn_variable = 'SVN_REVISION'
        if svn_variable in os.environ:
            # Usage in Hudson build
            return False

        try:
            import tvb_bin
        except ImportError:
            # No tvb_bin, it means usage from pip or conda
            return False

        try:
            _proc = Popen(["git", "status"], stdout=PIPE, stderr=PIPE)
            if "On branch " in str(_proc.communicate()):
                # usage from git
                return False
        except Exception:
            pass

        try:
            _proc = Popen(["svnversion", "."], stdout=PIPE, stderr=PIPE)
            version = VersionSettings.parse_svn_version(_proc.communicate()[0])
            if version:
                # usage from SVN
                return False
        except Exception:
            # Usage from tvb_distribution
            return True
示例#2
0
    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)
示例#3
0
def ensure_svn_current_version():
    """
    Enforce later revision number is written in 'tvb.version' file
    """
    import tvb.basic.config
    from tvb.basic.config.settings import VersionSettings
    config_folder = os.path.dirname(os.path.abspath(tvb.basic.config.__file__))

    svn_variable = 'SVN_REVISION'
    if svn_variable in os.environ:
        real_svn_number = int(os.environ[svn_variable])
    else:
        _proc = Popen(["svnversion", "."], stdout=PIPE)
        real_svn_number = VersionSettings.parse_svn_version(
            str(_proc.communicate()[0]))

    with open(os.path.join(config_folder, 'tvb.version'), 'r') as version_file:
        version_line = version_file.read()
        try:
            written_svn_number = VersionSettings.parse_svn_version(
                version_line)
        except ValueError:
            written_svn_number = 0

    if written_svn_number == real_svn_number:
        print("We will not change file tvb.version")
        return

    with open(os.path.join(config_folder, 'tvb.version'), 'w') as version_file:
        new_text = "Revision: " + str(real_svn_number + 1)
        version_file.write(new_text)
        print("Updating tvb.version content to: %s because %d != %d" %
              (new_text, written_svn_number, real_svn_number))

    # Update SVN_REVISION in the current build, as we are creating a new commit
    os.environ[svn_variable] = str(real_svn_number + 1)
    _proc = Popen([
        "svn", "commit", "../scientific_library/tvb/basic/config/tvb.version",
        "-m", "Update SVN revision number automatically from Hudson",
        "--trust-server-cert"
    ],
                  stdout=PIPE)
    print(_proc.communicate()[0])
示例#4
0
def ensure_tvb_current_revision(branch=None):
    """
    Enforce later revision number is written in 'tvb.version' file
    """
    import tvb.basic.config
    from tvb.basic.config.settings import VersionSettings
    config_folder = os.path.dirname(os.path.abspath(tvb.basic.config.__file__))

    if branch is None:
        branch = "master"

    print('Current branch {}'.format(branch))
    real_version_number = VersionSettings.fetch_current_revision(branch)

    with open(os.path.join(config_folder, 'tvb.version'), 'r') as version_file:
        version_line = version_file.read()
        try:
            written_tvb_number = VersionSettings.parse_revision_number(
                version_line)
        except ValueError:
            written_tvb_number = 0

    if written_tvb_number == real_version_number:
        print("We will not change file tvb.version")
        return

    tvb_version_path = "../scientific_library/tvb/basic/config/tvb.version"
    print("Tvb version file path: {}".format(tvb_version_path))
    paths = [tvb_version_path, os.path.join(config_folder, 'tvb.version')]
    for path in paths:
        with open(path, 'w') as version_file:
            new_text = "Revision: " + str(real_version_number + 1)
            version_file.write(new_text)
            print(
                "Updating tvb.version content in %s to: %s because %d != %d" %
                (path, new_text, written_tvb_number, real_version_number))
示例#5
0
    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
示例#6
0
    def is_distribution():
        """
        Return True when TVB_Distribution package, False when used from a GitHub clone, Pypi, Conda or Docker
        """

        try:
            import tvb_bin
        except ImportError:
            # No tvb_bin, it means usage from Pypi or Conda Forge
            return False

        try:
            _proc = Popen(["git", "status"], stdout=PIPE, stderr=PIPE)
            if "On branch " in str(_proc.communicate()):
                # usage from GitHub clone directly
                return False
        except Exception:
            pass

        if os.path.join(
                os.path.dirname(
                    os.path.dirname(
                        os.path.dirname(os.path.abspath(tvb_bin.__file__)))),
                "externals"):
            # usage from GitHub clone without got cmd or inside a Docker container (as a mounted volume)
            return False

        try:
            _proc = Popen(["svnversion", "."], stdout=PIPE, stderr=PIPE)
            version = VersionSettings.parse_svn_version(_proc.communicate()[0])
            if version:
                # usage from SVN (deprecated)
                return False
        except Exception:
            pass

        # We default as usage from TVB_Distribution
        return True