Salome HOME
sat #8581 : ajout d'une fonctionnalité de description fine de la version de salomeToo...
authorcrouzet <nicolas.crouzet@cea.fr>
Wed, 6 Feb 2019 14:52:37 +0000 (15:52 +0100)
committercrouzet <nicolas.crouzet@cea.fr>
Wed, 6 Feb 2019 14:52:37 +0000 (15:52 +0100)
commands/package.py
src/__init__.py
src/logger.py
src/salomeTools.py
src/system.py

index 99bd2d18320e47e4e8a4195fc0a3f9f7e8ce9acd..5335863f34ddad462be7ac5cf78fd5699edbd14c 100644 (file)
@@ -1209,7 +1209,7 @@ The procedure to do it is:
         d = dict()
         d['user'] = config.VARS.user
         d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
-        d['version'] = config.INTERNAL.sat_version
+        d['version'] = src.get_salometool_version(config)
         d['dist'] = config.VARS.dist
         f.write(readme_header_tpl.substitute(d)) # write the general header (common)
 
@@ -1396,7 +1396,7 @@ Please add it in file:
             archive_name += ("PROJECT-" + project_name)
  
         if options.sat:
-            archive_name += ("salomeTools_" + runner.cfg.INTERNAL.sat_version)
+            archive_name += ("salomeTools_" + src.get_salometool_version(runner.cfg))
         if len(archive_name)==0: # no option worked 
             msg = _("Error: Cannot name the archive\n"
                     " check if at least one of the following options was "
index 02f27a6e521a8ae290942c1331fa2c4c930b1bd2..ca569a05d6a89c5f85857af4e7e7a1dfbab07376 100644 (file)
@@ -228,6 +228,22 @@ def get_log_path(config):
     
     return log_dir_path
 
+def get_salometool_version(config):
+   """Return the salomeTool version.
+
+   :param config Config: The global Config instance.
+   :return: the description of this version of sat in terms of tag and commit
+   """
+   # we use : 
+   # config.VARS.salometoolsway : the full path of salomeTool
+   # config.INTERNAL.sat_version : the static salomeTool version, 
+   # in case we are not in a git repo  
+   sat_version=system.git_describe(config.VARS.salometoolsway) 
+   if sat_version == False:
+       return config.INTERNAL.sat_version
+   else:
+       return sat_version
+
 def get_salome_version(config):
     import versionMinorMajorPatch as VMMP
 
index 439b540cbbd20e5cd26b04a7215569769b7c94c4..545ac0b8dfbe368f7d2333b23129455ed653dffa 100755 (executable)
@@ -134,7 +134,7 @@ class Logger(object):
                                                      self.config.VARS.command})
         # version of salomeTools
         self.xmlFile.append_node_attrib("Site", attrib={"satversion" : 
-                                            self.config.INTERNAL.sat_version})
+                                            src.get_salometool_version(self.config)})
         # machine name on which the command has been launched
         self.xmlFile.append_node_attrib("Site", attrib={"hostname" : 
                                                     self.config.VARS.hostname})
index 251d6ea730b715b9c4b9b6e1c41a72ba586cba1c..543baeabdf34cf032382ce824cdab6c11247dd4c 100755 (executable)
@@ -696,7 +696,7 @@ def get_version():
     cfgManager = CONFIG.ConfigManager()
     cfg = cfgManager.get_config()
     # print the key corresponding to salomeTools version
-    msg = (src.printcolors.printcHeader( _("Version: ") ) + cfg.INTERNAL.sat_version)
+    msg = (src.printcolors.printcHeader( _("Version: ") ) + src.get_salometool_version(cfg))
     return msg
 
 
index 6e7a788bdd41eead121c8f9cd459d56256f1d432..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.