]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
Add README files in packages
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 7 Sep 2016 09:37:04 +0000 (11:37 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 7 Sep 2016 09:37:04 +0000 (11:37 +0200)
commands/config.py
commands/package.py
src/__init__.py
src/internal_config/README_BIN.template [new file with mode: 0644]
src/internal_config/README_PROJECT.template [new file with mode: 0644]
src/internal_config/README_SAT.template [new file with mode: 0644]
src/internal_config/README_SRC.template [new file with mode: 0644]
src/template.py [new file with mode: 0755]

index 115984ae68455d03ab05a27d0e64a85c5dac04c5..9c03149760cf7407684491a571b6c41bfc2c79d0 100644 (file)
@@ -98,6 +98,7 @@ class ConfigManager:
         var['salometoolsway'] = os.path.dirname(
                                     os.path.dirname(os.path.abspath(__file__)))
         var['srcDir'] = os.path.join(var['salometoolsway'], 'src')
+        var['internal_dir'] = os.path.join(var['srcDir'], 'internal_config')
         var['sep']= os.path.sep
         
         # datadir has a default location
index d5c8cf15b0097ca541d200888e09fa2e30429948..d9faded43a84fd005563d9e6702184b7c19ad105 100644 (file)
@@ -19,6 +19,7 @@
 import os
 import stat
 import shutil
+import datetime
 import tarfile
 
 import src
@@ -79,16 +80,22 @@ project_file_paths : [$VARS.salometoolsway + $VARS.sep + \"..\" + $VARS.sep"""
 parser = src.options.Options()
 parser.add_option('b', 'binaries', 'boolean', 'binaries',
     _('Produce a binary package.'), False)
+parser.add_option('f', 'force_creation', 'boolean', 'force_creation',
+    _('Only binary package: produce the archive even if there are some missing '
+      'products.'), False)
+parser.add_option('', 'with_sources', 'boolean', 'with_sources',
+    _('Only binary package: produce and and a source archive in the binary '
+      'package.'), False)
 parser.add_option('s', 'sources', 'boolean', 'sources',
     _('Produce a compilable archive of the sources of the application.'), False)
+parser.add_option('', 'with_vcs', 'boolean', 'with_vcs',
+    _('Only source package: do not make archive of vcs products.'), False)
 parser.add_option('p', 'project', 'string', 'project',
     _('Produce an archive that contains a project.'), "")
-parser.add_option('', 'salometools', 'boolean', 'sat',
+parser.add_option('t', 'salometools', 'boolean', 'sat',
     _('Produce an archive that contains salomeTools.'), False)
 parser.add_option('n', 'name', 'string', 'name',
     _('The name or full path of the archive.'), None)
-parser.add_option('', 'with_vcs', 'boolean', 'with_vcs',
-    _('Only source package: do not make archive of vcs products.'), False)
 
 def add_files(tar, name_archive, d_content, logger):
     '''Create an archive containing all directories and files that are given in
@@ -149,10 +156,10 @@ def produce_relative_launcher(config,
     # Get the launcher template
     profile_install_dir = os.path.join(binaries_dir_name,
                                        config.APPLICATION.profile.product)
-    withProfile = src.fileEnviron.withProfile   
+    withProfile = src.fileEnviron.withProfile
     withProfile = withProfile.replace(
         "ABSOLUTE_APPLI_PATH'] = 'PROFILE_INSTALL_DIR'",
-        "ABSOLUTE_APPLI_PATH'] = out_dir_Path + '/" + profile_install_dir + "'")
+        "ABSOLUTE_APPLI_PATH'] = out_dir_Path + '" + config.VARS.sep + profile_install_dir + "'")
     withProfile = withProfile.replace(
         "os.path.join( 'PROFILE_INSTALL_DIR'",
         "os.path.join( out_dir_Path, '" + profile_install_dir + "'")
@@ -671,6 +678,51 @@ def project_package(project_file_path, tmp_working_dir):
     
     return d_project
 
+def add_readme(config, package_type, where):
+    readme_path = os.path.join(where, "README")
+    f = open(readme_path, 'w')
+    # prepare substitution dictionary
+    d = dict()
+    if package_type == BINARY:
+        d['application'] = config.VARS.application
+        d['user'] = config.VARS.user
+        d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
+        d['version'] = config.INTERNAL.sat_version
+        d['dist'] = config.VARS.dist
+        if 'profile' in config.APPLICATION:
+            d['launcher'] = config.APPLICATION.profile.launcher_name
+        readme_template_path = os.path.join(config.VARS.internal_dir,
+                                            "README_BIN.template")
+    if package_type == SOURCE:
+        d['application'] = config.VARS.application
+        d['user'] = config.VARS.user
+        d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
+        d['version'] = config.INTERNAL.sat_version
+        if 'profile' in config.APPLICATION:
+            d['profile'] = config.APPLICATION.profile.product
+            d['launcher'] = config.APPLICATION.profile.launcher_name
+        readme_template_path = os.path.join(config.VARS.internal_dir,
+                                    "README_SRC.template")
+
+    if package_type == PROJECT:
+        d['user'] = config.VARS.user
+        d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
+        d['version'] = config.INTERNAL.sat_version
+        readme_template_path = os.path.join(config.VARS.internal_dir,
+                                    "README_PROJECT.template")
+
+    if package_type == SAT:
+        d['user'] = config.VARS.user
+        d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
+        d['version'] = config.INTERNAL.sat_version
+        readme_template_path = os.path.join(config.VARS.internal_dir,
+                                    "README_SAT.template")
+    
+    f.write(src.template.substitute(readme_template_path, d))
+    
+    return readme_path
+        
+
 def description():
     '''method that is called when salomeTools is called with --help option.
     
@@ -695,7 +747,7 @@ def run(args, runner, logger):
     # Check that a type of package is called, and only one
     all_option_types = (options.binaries,
                         options.sources,
-                        options.project != "",
+                        options.project not in ["", None],
                         options.sat)
 
     # Check if no option for package type
@@ -784,6 +836,12 @@ def run(args, runner, logger):
             archive_name = (runner.cfg.APPLICATION.name +
                             "-" +
                             "SRC")
+            if options.with_vcs:
+                archive_name = (runner.cfg.APPLICATION.name +
+                            "-" +
+                            "SRC" +
+                            "-" +
+                            "VCS")
 
         if package_type == PROJECT:
             project_name, __ = os.path.splitext(
@@ -807,6 +865,8 @@ def run(args, runner, logger):
     tmp_working_dir = os.path.join(runner.cfg.VARS.tmp_root,
                                    runner.cfg.VARS.datehour)
     src.ensure_path_exists(tmp_working_dir)
+    logger.write("\n", 5)
+    logger.write(_("The temporary working directory: %s\n" % tmp_working_dir),5)
     
     logger.write("\n", 3)
 
@@ -814,13 +874,32 @@ def run(args, runner, logger):
     logger.write(src.printcolors.printcLabel(msg), 2)
     logger.write("\n", 2)
 
-    if package_type == BINARY:
+    if package_type == BINARY:           
         d_files_to_add = binary_package(runner.cfg,
                                         logger,
                                         options,
                                         tmp_working_dir)
         if not(d_files_to_add):
             return 1
+        
+        # Create and add the source package 
+        # if the option "with_sources" is called
+        if options.with_sources:
+            logger.write(_("Create a source archive (can be long) ... "), 3)
+            tmp_pkg_src_name = runner.cfg.APPLICATION.name + "-" + "SRC.tgz"
+            tmp_pkg_src_path = os.path.join(tmp_working_dir, tmp_pkg_src_name)
+            package_options = runner.cfg.VARS.application
+            package_options += " --sources --with_vcs --name "
+            package_options += tmp_pkg_src_path
+            # sat package <package_options>
+            runner.package(package_options,
+                           batch = True,
+                           verbose = 0,
+                           logger_add_link = logger)
+            d_files_to_add["SOURCES PACKAGE"] = (tmp_pkg_src_path,
+                                                 tmp_pkg_src_name)
+            logger.write(src.printcolors.printc("OK"), 3)
+            logger.write("\n", 3)
 
     if package_type == SOURCE:
         d_files_to_add = source_package(runner,
@@ -835,19 +914,34 @@ def run(args, runner, logger):
     if package_type == SAT:
         d_files_to_add = {"salomeTools" : (runner.cfg.VARS.salometoolsway, "")}
     
+    # Add the README file in the package
+    local_readme_tmp_path = add_readme(runner.cfg,
+                                       package_type,
+                                       tmp_working_dir)
+    d_files_to_add["README"] = (local_readme_tmp_path, "README")
+    
     logger.write("\n", 2)
 
     logger.write(src.printcolors.printcLabel(_("Actually do the package")), 2)
     logger.write("\n", 2)
     
-    # Creating the object tarfile
-    tar = tarfile.open(path_targz, mode='w:gz')
-    
-    # Add the files to the tarfile object
-    res = add_files(tar, archive_name, d_files_to_add, logger)
-    tar.close()
+    try:
+        # Creating the object tarfile
+        tar = tarfile.open(path_targz, mode='w:gz')
+        
+        # Add the files to the tarfile object
+        res = add_files(tar, archive_name, d_files_to_add, logger)
+        tar.close()
+    except KeyboardInterrupt:
+        logger.write(src.printcolors.printcError("\nERROR: forced interruption\n"), 1)
+        logger.write(_("Removing the temporary working directory ... "), 1)
+        # remove the working directory
+        shutil.rmtree(tmp_working_dir)
+        logger.write(_("OK"), 1)
+        logger.write(_("\n"), 1)
+        return 1
     
-    # remove the working directory
+    # remove the working directory    
     shutil.rmtree(tmp_working_dir)
     
     # Print again the path of the package
index 10783b7df58df4fccccd9fbc9f91b84d7cad4d17..fdefb41a044c9144ef56a5dffcc496c4905fdd46 100644 (file)
@@ -33,6 +33,7 @@ from . import environment
 from . import fileEnviron
 from . import compilation
 from . import test_module
+from . import template
 
 OK_STATUS = "OK"
 KO_STATUS = "KO"
diff --git a/src/internal_config/README_BIN.template b/src/internal_config/README_BIN.template
new file mode 100644 (file)
index 0000000..9831e40
--- /dev/null
@@ -0,0 +1,12 @@
+# This package was generated with sat ¤{version}
+# Date: ¤{date}
+# User: ¤{user}
+# Distribution : ¤{dist}
+
+In the following, $ROOT represents the directory where you install SALOME (the
+directory where this file is located).
+
+This package includes an installation of the application ¤{application}.
+
+ To run it, launch the following command :
+> $ROOT/¤{launcher}
diff --git a/src/internal_config/README_PROJECT.template b/src/internal_config/README_PROJECT.template
new file mode 100644 (file)
index 0000000..57b78d6
--- /dev/null
@@ -0,0 +1,7 @@
+# This package was generated with sat ¤{version}
+# Date: ¤{date}
+# User: ¤{user}
+
+In the following, $ROOT represents the directory where this file is located.
+
+This package includes a salomeTools project.
diff --git a/src/internal_config/README_SAT.template b/src/internal_config/README_SAT.template
new file mode 100644 (file)
index 0000000..133807c
--- /dev/null
@@ -0,0 +1,14 @@
+# This package was generated with sat ¤{version}
+# Date: ¤{date}
+# User: ¤{user}
+
+In the following, $ROOT represents the directory where this file is located.
+
+This package includes salomeTools.
+
+You can add a project to salomeTools by editing the file $ROOT/data/site.pyconf
+and add a project file in the section PROJECTS:
+PROJECTS :
+{
+    project_file_paths : ["HERE"]
+}
diff --git a/src/internal_config/README_SRC.template b/src/internal_config/README_SRC.template
new file mode 100644 (file)
index 0000000..bcd2c30
--- /dev/null
@@ -0,0 +1,65 @@
+# This package was generated with sat ¤{version}
+# Date: ¤{date}
+# User: ¤{user}
+# Application: ¤{application}
+
+Important
+=========
+The version of SAlomeTools included in this package is configured to work with 
+the application of the package.
+
+1) Introduction
+===============
+
+In the following, $ROOT represents the directory where you install your 
+application (the directory where this file is located).
+
+The sources of your application are located in the $ROOT/ARCHIVES directory.
+
+This package includes SAlomeTools (sat) a suite of scripts to manage
+operations on your application (get sources, compilation, test, packaging ...).
+
+sat is located in $ROOT and you can read its documentation in 
+$ROOT/salomeTools/doc or by using:
+> $ROOT/sat --help
+> $ROOT/sat doc
+
+If you use bash, you can have completion for sat by sourcing $ROOT/salomeTools/complete_sat.sh:
+> source $ROOT/salomeTools/complete_sat.sh
+
+2) Preparing the sources of your application
+============================================
+Tap the following command to get the source and apply the patches:
+> $ROOT/sat prepare ¤{application}
+
+3) Build ¤{application}
+=======================
+Tap the following command to compile and install the products of your application:
+> $ROOT/sat compile ¤{application}
+
+3) Set environment for libraries inside ¤{application}
+======================================================
+Tap the following command to produce the environment files:
+> $ROOT/sat environ ¤{application}
+
+4) Create a SALOME launcher
+===========================
+
+Create the launcher:
+> $ROOT/sat launcher ¤{application}
+
+5) How to set the Distene license
+=================================
+
+If your application is based on SALOME and embed the SMESH module and MeshGems 
+prerequisite, you may want to set the Distene license. 
+To do so, edit the following file:
+
+> $ROOT/INSTALL/¤{profile}/bin/salome/¤{launcher}
+
+Then, find the lines that begin with:
+
+    #[MeshGems]
+    # Here you can define your license parameters for MeshGems
+
+Set the variables corresponding to your licence after these lines.
diff --git a/src/template.py b/src/template.py
new file mode 100755 (executable)
index 0000000..2b29aa1
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2013  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import string
+
+class MyTemplate(string.Template):
+    delimiter = '¤'
+
+def substitute(template_file, subst_dic):
+    template = open(template_file, 'r')
+    template = MyTemplate(template.read())
+
+    return template.safe_substitute(subst_dic)
+