Salome HOME
sat #8581 : ajout d'une fonctionnalité de description fine de la version de salomeToo...
[tools/sat.git] / src / system.py
index bb1fc1ac789fe1d38ad10cc969e29ea4e2040eae..6b793397f12e8280bece2dd60d28b37caaadbe4c 100644 (file)
@@ -54,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.
@@ -97,32 +112,23 @@ git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s
 
   DBG.write("cmd", cmd)
 
-  # git commands may fail sometimes for various raisons (big module, network troubles, tuleap maintenance)
+  # 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
+  i_try = 0
+  max_number_of_tries = 3
+  sleep_delay = 30  # seconds
   while (True):
-    i_try+=1
+    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)
+      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()
 
-  """
-  res = subprocess.call(command,
-                        cwd=str(where.dir()),
-                        env=environment.environ.environ,
-                        shell=True,
-                        stdout=logger.logTxtFile,
-                        stderr=subprocess.STDOUT)
-  return (res == 0)
-  """
-
-
 
 def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None):
   '''Extracts sources from a subtree sub_dir of a git repository.