Exemplo n.º 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
Exemplo n.º 2
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])
Exemplo n.º 3
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