X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fsystem.py;h=6b793397f12e8280bece2dd60d28b37caaadbe4c;hb=d828b7da029994130b3717855155e49d58ee87ea;hp=46d7942c3c97cfe331676889b57a90cc665f465e;hpb=c3f7ac953b1096dbb4880b1a59bdb1e5b044d16f;p=tools%2Fsat.git diff --git a/src/system.py b/src/system.py index 46d7942..6b79339 100644 --- a/src/system.py +++ b/src/system.py @@ -21,8 +21,9 @@ In this file : all functions that do a system call, like open a browser or an editor, or call a git command ''' -import subprocess import os +import subprocess +import time import tarfile import debug as DBG @@ -53,6 +54,21 @@ def show_in_editor(editor, filePath, logger): logger.write(printcolors.printcError(_("Unable to edit file %s\n") % filePath), 1) +def git_describe(repo_path): + '''Use git describe --tags command to return tag description of the git repository" + :param repo_path str: The git repository to describe + ''' + git_cmd="cd %s;git describe --tags" % repo_path + p = subprocess.Popen(git_cmd, shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + p.wait() + if p.returncode != 0: + return False + else: + return p.stdout.readlines()[0].strip() + def git_extract(from_what, tag, where, logger, environment=None): '''Extracts sources from a git repository. @@ -81,7 +97,7 @@ git clone %(remote)s %(where)s cmd = r""" set -x -rmdir %(where)s && \ +rmdir %(where)s git clone %(remote)s %(where)s && \ git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s """ @@ -95,19 +111,23 @@ git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s logger.logTxtFile.flush() DBG.write("cmd", cmd) - rc = UTS.Popen(cmd, cwd=str(where.dir()), env=environment.environ.environ, logger=logger) - return rc.isOk() - """ - res = subprocess.call(command, - cwd=str(where.dir()), - env=environment.environ.environ, - shell=True, - stdout=logger.logTxtFile, - stderr=subprocess.STDOUT) - return (res == 0) - """ + # git commands may fail sometimes for various raisons + # (big module, network troubles, tuleap maintenance) + # therefore we give several tries + i_try = 0 + max_number_of_tries = 3 + sleep_delay = 30 # seconds + while (True): + i_try += 1 + rc = UTS.Popen(cmd, cwd=str(where.dir()), env=environment.environ.environ, logger=logger) + if rc.isOk() or (i_try>=max_number_of_tries): + break + logger.write('\ngit command failed! Wait %d seconds and give an other try (%d/%d)\n' % \ + (sleep_delay, i_try + 1, max_number_of_tries), 3) + time.sleep(sleep_delay) # wait a little + return rc.isOk() def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None): @@ -143,7 +163,7 @@ def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None cmd = r""" set -x export tmpDir=%(tmpWhere)s && \ -rm -rf $tmpDir && \ +rm -rf $tmpDir git clone %(remote)s $tmpDir && \ cd $tmpDir && \ git checkout %(tag)s && \ @@ -152,9 +172,13 @@ git log -1 > %(where)s/README_git_log.txt && \ rm -rf $tmpDir """ % aDict DBG.write("cmd", cmd) - rc = UTS.Popen(cmd, cwd=parentWhere, env=environment.environ.environ, logger=logger) - return rc.isOk() + for nbtry in range(0,3): # retries case of network problem + rc = UTS.Popen(cmd, cwd=parentWhere, env=environment.environ.environ, logger=logger) + if rc.isOk(): break + time.sleep(30) # wait a little + + return rc.isOk() def archive_extract(from_what, where, logger): '''Extracts sources from an archive. @@ -278,4 +302,4 @@ def svn_extract(user, shell=True, stdout=logger.logTxtFile, stderr=subprocess.STDOUT) - return (res == 0) \ No newline at end of file + return (res == 0)