コード例 #1
0
    def simple_clone(self, release_top_location, branch=""):
        """Clone an accessible remote git address to a top location

            :param release_top_location: (str existing branch)  a place to install
            :param branch: (str)  an optional existing branch
            :return ResultRepoInstall: success errors log atag
        """

        if not os.path.isdir(release_top_location):
            log.error("release area needs to exist, %s doen't" %
                      release_top_location)
            return False

        x = GitUtils(release_top_location)

        try:
            #The repo gets clone in this function
            x.clone_repo(self.src_repo, "", branch)
        except Exception as e:
            log.error(str(e))
            return ResultRepoInstall(False, [str(e)], ['failed simple_clone'],
                                     None)

        return ResultRepoInstall(True, ["no error"], ['done simple_clone'],
                                 None)
コード例 #2
0
    def _push_new_version(self, gitrepo):
        """ Query, increment tag and push to remote repo
        """
        x = GitUtils(gitrepo)
        ver = x.get_git_version()
        if ver in ["", "NONE"]:
            ver = "v0.0.0"
        else:
            verob = DirVersioned(ver)
            if verob.is_valid():
                verob.inc_patch()  # need an argument for minor
                ver = verob.format()
        glog = x.get_git_log(20)
        # we only push if head is not tagged
        do_tag = True

        for l in glog:
            log.info("log check for HEAD %s" % l)
            if l[-1] == True:
                log.warning("HEAD is already tag, will not create new tag")
                do_tag = False
                break
        if do_tag:
            x.create_tag(ver)
            x.push_tag(ver)
            log.info("new tag will be created: %r" % x.get_git_version())
コード例 #3
0
    def install(self,
                release_top_location,
                branch="",
                do_version=False,
                new_version=False):
        """Clone an accessible remote git address to a top location by using
            name and tag to build the install area

            :param    release_top_location: (str existing branch)
            :param    branch: (str)  an optional existing branch
            :param do_version: add a tag
            :param new_version: when do_version is incremental try incremenent
            :returns ResultRepoInstall: success errors log atag

        """

        if not os.path.isdir(release_top_location):
            log.error("release area needs to exist, %s doen't" %
                      release_top_location)
            return False

        tempdir = GitUtils.get_temp_git_clone_place_dir()
        x = GitUtils(tempdir)
        tempdest = x.get_temp_zone("REPO")

        res = ""
        try:
            #The repo gets clone in this function
            res = x.clone_repo(self.src_repo, tempdest, branch)
        except Exception as e:
            log.error(str(e))
            return ResultRepoInstall(False, [str(e)], None)

        if isinstance(res, str):
            res = [res]

        for r in res:
            # most likely to belong to the output in case of failure
            if 'fatal' in r:
                return ResultRepoInstall(False, res, "")

        if new_version == True and do_version == True and branch == "":
            # query tag, increment pach tag, push tag
            self._push_new_version(tempdest)

        # copy the temp repo contain in the release area
        res = self._copy_versionned_to_area(tempdest, release_top_location,
                                            branch, do_version)
        return res
コード例 #4
0
    def _copy_versionned_to_area(self, source, dest_release, branch,
                                 do_version):
        """Source is a repo clone area
           dest_release is an existing direct to which the name of the repo name and the
           version will be copied under   dest_release/tools_name/v?.?.?

            :paramsource: a valid git place (with a .git directory)
            :param dest_release
            :return ResultRepoInstall:

        """

        # Check that source has all the criteria
        x = GitUtils(source)
        if not x.is_valid():
            errors = ["Not a valid git:{}".format(source)]
            return ResultRepoInstall(False, errors,
                                     ['copy_versionned_to_area.source'], None)
        name = x.get_git_name()
        if name == "":
            errors = ["Not a valid name:{}".format(name)]
            return ResultRepoInstall(False, errors,
                                     ['copy_versionned_to_area.name'], None)

        atag = ""
        if do_version:
            atag = branch
            if branch == "":
                atag = x.get_git_version()
                if atag == "":
                    errors = ["Not a valid tag:{}".format(atag)]
                    return ResultRepoInstall(False, errors,
                                             ['copy_versionned_to_area.tag'],
                                             None)

        elif branch != "":  # branch willbe in subdirectory
            atag = branch

        todolist = BaseFileProc()
        todolist.copy_folder_release(source, dest_release, name, atag)
        res = todolist.execute_stop_first_failed()
        if res.success == False:
            return ResultRepoInstall(False, res.errors, res.log, None)
        return ResultRepoInstall(True, res.errors, res.log, atag)
コード例 #5
0
def test_version_when_tag():
    x = GitUtils(DEV_ENV)
    tag = x.get_git_version()
    rootname = x.get_git_name()
    assert rootname != ""
    assert tag != ""
コード例 #6
0
def test_log_git():
    x = GitUtils(DEV_ENV)
    assert len(x.get_git_log_raw(30)) > 1
コード例 #7
0
def test_list_date():
    x = GitUtils(DEV_ENV)
    assert len(x.get_git_date(1)) == 1
コード例 #8
0
def test_git_name():
    x = GitUtils(DEV_ENV)
    assert x.get_git_name() != ""
コード例 #9
0
def test_version():
    x = GitUtils(DEV_ENV)
    assert x.get_git_version() != ""
コード例 #10
0
def test_repo_exist():
    x = GitUtils(DEV_ENV)
    assert x.is_valid() == True
コード例 #11
0
ファイル: test_envi.py プロジェクト: erictexier/dsksoftkit
def test_version_when_tag_from_temp():
    pytest.skip("test not multi-user friendly")
    RELEASE_LOCATION_DISK = '/mnt/dev/eric/packages'
    SRC_REPO = 'https://gitlab.com/erictexier/devsoftkit.git'
    try:
        from dsk.base.utils.git_utils import GitUtils
    except ImportError:
        print("needed: envi -p base_envi")
        sys.exit(0)

    tempdir = GitUtils.get_temp_git_clone_place_dir()
    x = GitUtils(tempdir)
    tempdest = x.get_temp_zone("REPO")
    res = x.clone_repo(SRC_REPO, tempdest)
    if res and len(res) > 0:
        if res[0] != "failed":# check
            x = GitUtils(tempdest)
            assert x.is_valid()
            print(x.get_git_version())
            assert x.get_git_name() in SRC_REPO
            assert x.get_git_version().startswith("v")
            res = x.copy_versionned_to_area(tempdest, RELEASE_LOCATION_DISK)
            print(res)
            assert res.success == True