Salome HOME
gestion de path multiples dans la configuration projet
[tools/sat.git] / src / system.py
index 672149d12cd50ae3986d55d9798e26b7dae6b94d..c54452b4343efdadb1742d26ce59687418b4785d 100644 (file)
@@ -75,11 +75,12 @@ def git_describe(repo_path):
         return tag_description
 
 
-def git_extract(from_what, tag, where, logger, environment=None):
+def git_extract(from_what, tag, git_options, where, logger, environment=None):
   '''Extracts sources from a git repository.
 
   :param from_what str: The remote git repository.
   :param tag str: The tag.
+  :param git_options str: git options
   :param where str: The path where to extract.
   :param logger Logger: The logger instance to use.
   :param environment src.environment.Environ: The environment to source when extracting.
@@ -92,29 +93,35 @@ def git_extract(from_what, tag, where, logger, environment=None):
   where_git = os.path.join(str(where), ".git")
   if tag == "master" or tag == "HEAD":
     if src.architecture.is_windows():
-      cmd = "git clone %(remote)s %(where)s"
+      cmd = "git clone %(git_options)s %(remote)s %(where)s"
     else:
       cmd = r"""
 set -x
-git clone %(remote)s %(where)s
-touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s
+git clone %(git_options)s %(remote)s %(where)s
+res=$?
+if [ $res -eq 0 ]; then   touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s;fi
+exit $res
 """
-#git --git-dir=%(where_git)s  log -1 --format=date_format > %(where)s/last_commit_date.txt
-    cmd = cmd % {'remote': from_what, 'tag': tag, 'where': str(where), 'where_git': where_git}
+    cmd = cmd % {'git_options': git_options, 'remote': from_what, 'tag': tag, 'where': str(where), 'where_git': where_git}
   else:
     # NOTICE: this command only works with recent version of git
     #         because --work-tree does not work with an absolute path
     if src.architecture.is_windows():
-      cmd = "rmdir %(where)s && git clone %(remote)s %(where)s && git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s"
+      cmd = "rm -rf %(where)s && git clone %(git_options)s %(remote)s %(where)s && git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s"
     else:
+# for sat compile --update : changes the date of directory, only for branches, not tag
       cmd = r"""
 set -x
-rmdir %(where)s
-git clone %(remote)s %(where)s && \
+rm -rf %(where)s
+git clone %(git_options)s %(remote)s %(where)s && \
 git --git-dir=%(where_git)s --work-tree=%(where)s checkout %(tag)s
-touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s
+res=$?
+git --git-dir=%(where_git)s status|grep HEAD
+if [ $res -eq 0 -a $? -ne 0 ]; then   touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s;fi
+exit $res
 """
-    cmd = cmd % {'remote': from_what,
+    cmd = cmd % {'git_options': git_options,
+                 'remote': from_what,
                  'tag': tag,
                  'where': str(where),
                  'where_git': where_git}
@@ -125,7 +132,6 @@ touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s
   logger.logTxtFile.flush()
 
   DBG.write("cmd", cmd)
-
   # git commands may fail sometimes for various raisons 
   # (big module, network troubles, tuleap maintenance)
   # therefore we give several tries
@@ -144,11 +150,12 @@ touch -d "$(git --git-dir=%(where_git)s  log -1 --format=date_format)" %(where)s
   return rc.isOk()
 
 
-def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None):
+def git_extract_sub_dir(from_what, tag, git_options, where, sub_dir, logger, environment=None):
   '''Extracts sources from a subtree sub_dir of a git repository.
 
   :param from_what str: The remote git repository.
   :param tag str: The tag.
+  :param git_options str: git options
   :param where str: The path where to extract.
   :param sub_dir str: The relative path of subtree to extract.
   :param logger Logger: The logger instance to use.
@@ -165,7 +172,8 @@ def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None
   if os.path.isdir(strWhere):
     logger.error("do not override existing directory: %s" % strWhere)
     return False
-  aDict = {'remote': from_what,
+  aDict = {'git_options': git_options,
+           'remote': from_what,
            'tag': tag,
            'sub_dir': sub_dir,
            'where': strWhere,
@@ -178,7 +186,7 @@ def git_extract_sub_dir(from_what, tag, where, sub_dir, logger, environment=None
 set -x
 export tmpDir=%(tmpWhere)s && \
 rm -rf $tmpDir
-git clone %(remote)s $tmpDir && \
+git clone %(git_options)s %(remote)s $tmpDir && \
 cd $tmpDir && \
 git checkout %(tag)s && \
 mv %(sub_dir)s %(where)s && \
@@ -190,7 +198,7 @@ rm -rf $tmpDir
 
 set tmpDir=%(tmpWhere)s && \
 rm -rf $tmpDir
-git clone %(remote)s $tmpDir && \
+git clone %(git_options)s %(remote)s $tmpDir && \
 cd $tmpDir && \
 git checkout %(tag)s && \
 mv %(sub_dir)s %(where)s && \
@@ -367,35 +375,43 @@ def check_system_pkg(check_cmd,pkg):
     :return: a string with package name with status un message
     '''
     # build command
+    FNULL = open(os.devnull, 'w')
     cmd_is_package_installed=[]
     for cmd in check_cmd:
         cmd_is_package_installed.append(cmd)
     cmd_is_package_installed.append(pkg)
+
+
     if check_cmd[0]=="apt":
         # special treatment for apt
-        # (some debian packages have version numbers in their name, and also
-        # apt do not return status)
+        # apt output is too messy for being used
+        # some debian packages have version numbers in their name, we need to add a *
+        # also apt do not return status, we need to use grep
+        # and apt output is too messy for being used 
         cmd_is_package_installed[-1]+="*" # we don't specify in pyconf the exact name because of version numbers
-        cmd_is_package_installed.append('|')
-        cmd_is_package_installed.append('grep') # add a grep to get an exit status
-        cmd_is_package_installed.append(cmd) 
-        
-    p=subprocess.Popen(cmd_is_package_installed, 
-                       stdout=subprocess.PIPE, 
-                       stderr=subprocess.PIPE)
-    output, err = p.communicate()
-
-    rc = p.returncode
-    if rc==0:
-        msg_status=src.printcolors.printcSuccess("OK")
-        if check_cmd[0]=="rpm": # apt output is too messy for being used
+        p=subprocess.Popen(cmd_is_package_installed,
+                           stdout=subprocess.PIPE,
+                           stderr=FNULL)
+        try:
+            output = subprocess.check_output(['grep', pkg], stdin=p.stdout)
+            msg_status=src.printcolors.printcSuccess("OK")
+        except:
+            msg_status=src.printcolors.printcError("KO")
+            msg_status+=" (package is not installed!)\n"
+    else:
+        p=subprocess.Popen(cmd_is_package_installed,
+                           stdout=subprocess.PIPE,
+                           stderr=FNULL)
+        output, err = p.communicate()
+        rc = p.returncode
+        if rc==0:
+            msg_status=src.printcolors.printcSuccess("OK")
             # in python3 output is a byte and should be decoded
             if isinstance(output, bytes):
                 output = output.decode("utf-8", "ignore")
             msg_status+=" (" + output.replace('\n',' ') + ")\n" # remove output trailing \n
-    else:
-        msg_status=src.printcolors.printcError("KO") 
-        msg_status+=" (package is not installed!)\n"
+        else:
+            msg_status=src.printcolors.printcError("KO")
+            msg_status+=" (package is not installed!)\n"
 
     return msg_status
-