3 # Copyright (C) 2010-2012 CEA/DEN
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 from application import get_SALOME_modules
36 ARCHIVE_DIR = "ARCHIVES"
37 PROJECT_DIR = "PROJECT"
39 IGNORED_DIRS = [".git", ".svn"]
40 IGNORED_EXTENSIONS = []
42 PROJECT_TEMPLATE = """#!/usr/bin/env python
45 # The path to the archive root directory
46 root_path : $PWD + "/../"
48 project_path : $PWD + "/"
50 # Where to search the archives of the products
51 ARCHIVEPATH : $root_path + "ARCHIVES"
52 # Where to search the pyconf of the applications
53 APPLICATIONPATH : $project_path + "applications/"
54 # Where to search the pyconf of the products
55 PRODUCTPATH : $project_path + "products/"
56 # Where to search the pyconf of the jobs of the project
57 JOBPATH : $project_path + "jobs/"
58 # Where to search the pyconf of the machines of the project
59 MACHINEPATH : $project_path + "machines/"
62 LOCAL_TEMPLATE = ("""#!/usr/bin/env python
70 archive_dir : 'default'
77 project_file_paths : [$VARS.salometoolsway + $VARS.sep + \"..\" + $VARS.sep"""
78 """ + \"""" + PROJECT_DIR + """\" + $VARS.sep + "project.pyconf"]
82 # Define all possible option for the package command : sat package <options>
83 parser = src.options.Options()
84 parser.add_option('b', 'binaries', 'boolean', 'binaries',
85 _('Optional: Produce a binary package.'), False)
86 parser.add_option('f', 'force_creation', 'boolean', 'force_creation',
87 _('Optional: Only binary package: produce the archive even if '
88 'there are some missing products.'), False)
89 parser.add_option('s', 'sources', 'boolean', 'sources',
90 _('Optional: Produce a compilable archive of the sources of the '
91 'application.'), False)
92 parser.add_option('', 'with_vcs', 'boolean', 'with_vcs',
93 _('Optional: Only source package: do not make archive of vcs products.'),
95 parser.add_option('p', 'project', 'string', 'project',
96 _('Optional: Produce an archive that contains a project.'), "")
97 parser.add_option('t', 'salometools', 'boolean', 'sat',
98 _('Optional: Produce an archive that contains salomeTools.'), False)
99 parser.add_option('n', 'name', 'string', 'name',
100 _('Optional: The name or full path of the archive.'), None)
101 parser.add_option('', 'add_files', 'list2', 'add_files',
102 _('Optional: The list of additional files to add to the archive.'), [])
103 parser.add_option('', 'without_commercial', 'boolean', 'without_commercial',
104 _('Optional: do not add commercial licence.'), False)
105 parser.add_option('', 'without_property', 'string', 'without_property',
106 _('Optional: Filter the products by their properties.\n\tSyntax: '
107 '--without_property <property>:<value>'))
110 def add_files(tar, name_archive, d_content, logger, f_exclude=None):
111 '''Create an archive containing all directories and files that are given in
112 the d_content argument.
114 :param tar tarfile: The tarfile instance used to make the archive.
115 :param name_archive str: The name of the archive to make.
116 :param d_content dict: The dictionary that contain all directories and files
117 to add in the archive.
119 (path_on_local_machine, path_in_archive)
120 :param logger Logger: the logging instance
121 :param f_exclude Function: the function that filters
122 :return: 0 if success, 1 if not.
125 # get the max length of the messages in order to make the display
126 max_len = len(max(d_content.keys(), key=len))
129 # loop over each directory or file stored in the d_content dictionary
130 for name in d_content.keys():
131 # display information
132 len_points = max_len - len(name)
133 logger.write(name + " " + len_points * "." + " ", 3)
134 # Get the local path and the path in archive
135 # of the directory or file to add
136 local_path, archive_path = d_content[name]
137 in_archive = os.path.join(name_archive, archive_path)
138 # Add it in the archive
140 tar.add(local_path, arcname=in_archive, exclude=f_exclude)
141 logger.write(src.printcolors.printcSuccess(_("OK")), 3)
142 except Exception as e:
143 logger.write(src.printcolors.printcError(_("KO ")), 3)
144 logger.write(str(e), 3)
146 logger.write("\n", 3)
149 def exclude_VCS_and_extensions(filename):
150 ''' The function that is used to exclude from package the link to the
151 VCS repositories (like .git)
153 :param filename Str: The filname to exclude (or not).
154 :return: True if the file has to be exclude
157 for dir_name in IGNORED_DIRS:
158 if dir_name in filename:
160 for extension in IGNORED_EXTENSIONS:
161 if filename.endswith(extension):
165 def produce_relative_launcher(config,
170 with_commercial=True):
171 '''Create a specific SALOME launcher for the binary package. This launcher
174 :param config Config: The global configuration.
175 :param logger Logger: the logging instance
176 :param file_dir str: the directory where to put the launcher
177 :param file_name str: The launcher name
178 :param binaries_dir_name str: the name of the repository where the binaries
180 :return: the path of the produced launcher
184 # get KERNEL installation path
185 kernel_root_dir = os.path.join(binaries_dir_name, "KERNEL")
187 # set kernel bin dir (considering fhs property)
188 kernel_cfg = src.product.get_product_config(config, "KERNEL")
189 if src.get_property_in_product_cfg(kernel_cfg, "fhs"):
190 bin_kernel_install_dir = os.path.join(kernel_root_dir,"bin")
192 bin_kernel_install_dir = os.path.join(kernel_root_dir,"bin","salome")
194 # Get the launcher template and do substitutions
195 withProfile = src.fileEnviron.withProfile
197 withProfile = withProfile.replace(
198 "ABSOLUTE_APPLI_PATH'] = 'KERNEL_INSTALL_DIR'",
199 "ABSOLUTE_APPLI_PATH'] = out_dir_Path + '" + config.VARS.sep + kernel_root_dir + "'")
200 withProfile = withProfile.replace(
201 " 'BIN_KERNEL_INSTALL_DIR'",
202 " out_dir_Path + '" + config.VARS.sep + bin_kernel_install_dir + "'")
204 before, after = withProfile.split(
205 "# here your local standalone environment\n")
207 # create an environment file writer
208 writer = src.environment.FileEnvWriter(config,
213 filepath = os.path.join(file_dir, file_name)
214 # open the file and write into it
215 launch_file = open(filepath, "w")
216 launch_file.write(before)
218 writer.write_cfgForPy_file(launch_file,
219 for_package = binaries_dir_name,
220 with_commercial=with_commercial)
221 launch_file.write(after)
224 # Little hack to put out_dir_Path outside the strings
225 src.replace_in_file(filepath, 'r"out_dir_Path', 'out_dir_Path + r"' )
227 # A hack to put a call to a file for distene licence.
228 # It does nothing to an application that has no distene product
229 hack_for_distene_licence(filepath)
231 # change the rights in order to make the file executable for everybody
243 def hack_for_distene_licence(filepath):
244 '''Replace the distene licence env variable by a call to a file.
246 :param filepath Str: The path to the launcher to modify.
248 shutil.move(filepath, filepath + "_old")
250 filein = filepath + "_old"
251 fin = open(filein, "r")
252 fout = open(fileout, "w")
253 text = fin.readlines()
254 # Find the Distene section
256 for i,line in enumerate(text):
257 if "# Set DISTENE License" in line:
261 # No distene product, there is nothing to do
267 del text[num_line +1]
268 del text[num_line +1]
269 text_to_insert =""" import imp
271 distene = imp.load_source('distene_licence', '/data/tmpsalome/salome/prerequis/install/LICENSE/dlim8.var.py')
272 distene.set_distene_variables(context)
275 text.insert(num_line + 1, text_to_insert)
282 def produce_relative_env_files(config,
286 '''Create some specific environment files for the binary package. These
287 files use relative paths.
289 :param config Config: The global configuration.
290 :param logger Logger: the logging instance
291 :param file_dir str: the directory where to put the files
292 :param binaries_dir_name str: the name of the repository where the binaries
294 :return: the list of path of the produced environment files
297 # create an environment file writer
298 writer = src.environment.FileEnvWriter(config,
304 filepath = writer.write_env_file("env_launch.sh",
307 for_package = binaries_dir_name)
309 # Little hack to put out_dir_Path as environment variable
310 src.replace_in_file(filepath, '"out_dir_Path', '"${out_dir_Path}' )
312 # change the rights in order to make the file executable for everybody
324 def produce_install_bin_file(config,
329 '''Create a bash shell script which do substitutions in BIRARIES dir
330 in order to use it for extra compilations.
332 :param config Config: The global configuration.
333 :param logger Logger: the logging instance
334 :param file_dir str: the directory where to put the files
335 :param d_sub, dict: the dictionnary that contains the substitutions to be done
336 :param file_name str: the name of the install script file
337 :return: the produced file
341 filepath = os.path.join(file_dir, file_name)
342 # open the file and write into it
343 # use codec utf-8 as sat variables are in unicode
344 with codecs.open(filepath, "w", 'utf-8') as installbin_file:
345 installbin_template_path = os.path.join(config.VARS.internal_dir,
346 "INSTALL_BIN.template")
348 # build the name of the directory that will contain the binaries
349 binaries_dir_name = "BINARIES-" + config.VARS.dist
350 # build the substitution loop
351 loop_cmd = "for f in $(grep -RIl"
353 loop_cmd += " -e "+ key
354 loop_cmd += ' INSTALL); do\n sed -i "\n'
356 loop_cmd += " s?" + key + "?$(pwd)/" + d_sub[key] + "?g\n"
357 loop_cmd += ' " $f\ndone'
360 d["BINARIES_DIR"] = binaries_dir_name
361 d["SUBSTITUTION_LOOP"]=loop_cmd
363 # substitute the template and write it in file
364 content=src.template.substitute(installbin_template_path, d)
365 installbin_file.write(content)
366 # change the rights in order to make the file executable for everybody
378 def product_appli_creation_script(config,
382 '''Create a script that can produce an application (EDF style) in the binary
385 :param config Config: The global configuration.
386 :param logger Logger: the logging instance
387 :param file_dir str: the directory where to put the file
388 :param binaries_dir_name str: the name of the repository where the binaries
390 :return: the path of the produced script file
393 template_name = "create_appli.py.for_bin_packages.template"
394 template_path = os.path.join(config.VARS.internal_dir, template_name)
395 text_to_fill = open(template_path, "r").read()
396 text_to_fill = text_to_fill.replace("TO BE FILLED 1",
397 '"' + binaries_dir_name + '"')
400 for product_name in get_SALOME_modules(config):
401 product_info = src.product.get_product_config(config, product_name)
403 if src.product.product_is_smesh_plugin(product_info):
406 if 'install_dir' in product_info and bool(product_info.install_dir):
407 if src.product.product_is_cpp(product_info):
409 for cpp_name in src.product.get_product_components(product_info):
410 line_to_add = ("<module name=\"" +
412 "\" gui=\"yes\" path=\"''' + "
413 "os.path.join(dir_bin_name, \"" +
414 cpp_name + "\") + '''\"/>")
417 line_to_add = ("<module name=\"" +
419 "\" gui=\"yes\" path=\"''' + "
420 "os.path.join(dir_bin_name, \"" +
421 product_name + "\") + '''\"/>")
422 text_to_add += line_to_add + "\n"
424 filled_text = text_to_fill.replace("TO BE FILLED 2", text_to_add)
426 tmp_file_path = os.path.join(file_dir, "create_appli.py")
427 ff = open(tmp_file_path, "w")
428 ff.write(filled_text)
431 # change the rights in order to make the file executable for everybody
432 os.chmod(tmp_file_path,
443 def binary_package(config, logger, options, tmp_working_dir):
444 '''Prepare a dictionary that stores all the needed directories and files to
445 add in a binary package.
447 :param config Config: The global configuration.
448 :param logger Logger: the logging instance
449 :param options OptResult: the options of the launched command
450 :param tmp_working_dir str: The temporary local directory containing some
451 specific directories or files needed in the
453 :return: the dictionary that stores all the needed directories and files to
454 add in a binary package.
455 {label : (path_on_local_machine, path_in_archive)}
459 # Get the list of product installation to add to the archive
460 l_products_name = config.APPLICATION.products.keys()
461 l_product_info = src.product.get_products_infos(l_products_name,
466 l_sources_not_present = []
467 for prod_name, prod_info in l_product_info:
469 # Add the sources of the products that have the property
470 # sources_in_package : "yes"
471 if src.get_property_in_product_cfg(prod_info,
472 "sources_in_package") == "yes":
473 if os.path.exists(prod_info.source_dir):
474 l_source_dir.append((prod_name, prod_info.source_dir))
476 l_sources_not_present.append(prod_name)
478 # ignore the native and fixed products for install directories
479 if (src.product.product_is_native(prod_info)
480 or src.product.product_is_fixed(prod_info)
481 or not src.product.product_compiles(prod_info)):
483 if src.product.check_installation(prod_info):
484 l_install_dir.append((prod_name, prod_info.install_dir))
486 l_not_installed.append(prod_name)
488 # Add also the cpp generated modules (if any)
489 if src.product.product_is_cpp(prod_info):
491 for name_cpp in src.product.get_product_components(prod_info):
492 install_dir = os.path.join(config.APPLICATION.workdir,
494 if os.path.exists(install_dir):
495 l_install_dir.append((name_cpp, install_dir))
497 l_not_installed.append(name_cpp)
499 # Print warning or error if there are some missing products
500 if len(l_not_installed) > 0:
501 text_missing_prods = ""
502 for p_name in l_not_installed:
503 text_missing_prods += "-" + p_name + "\n"
504 if not options.force_creation:
505 msg = _("ERROR: there are missing products installations:")
506 logger.write("%s\n%s" % (src.printcolors.printcError(msg),
511 msg = _("WARNING: there are missing products installations:")
512 logger.write("%s\n%s" % (src.printcolors.printcWarning(msg),
516 # Do the same for sources
517 if len(l_sources_not_present) > 0:
518 text_missing_prods = ""
519 for p_name in l_sources_not_present:
520 text_missing_prods += "-" + p_name + "\n"
521 if not options.force_creation:
522 msg = _("ERROR: there are missing products sources:")
523 logger.write("%s\n%s" % (src.printcolors.printcError(msg),
528 msg = _("WARNING: there are missing products sources:")
529 logger.write("%s\n%s" % (src.printcolors.printcWarning(msg),
533 # construct the name of the directory that will contain the binaries
534 binaries_dir_name = "BINARIES-" + config.VARS.dist
536 # construct the correlation table between the product names, there
537 # actual install directories and there install directory in archive
539 for prod_name, install_dir in l_install_dir:
540 path_in_archive = os.path.join(binaries_dir_name, prod_name)
541 d_products[prod_name + " (bin)"] = (install_dir, path_in_archive)
543 for prod_name, source_dir in l_source_dir:
544 path_in_archive = os.path.join("SOURCES", prod_name)
545 d_products[prod_name + " (sources)"] = (source_dir, path_in_archive)
547 # for packages of SALOME applications including KERNEL,
548 # we produce a salome launcher or a virtual application (depending on salome version)
549 if 'KERNEL' in config.APPLICATION.products:
550 VersionSalome = src.get_salome_version(config)
551 # Case where SALOME has the launcher that uses the SalomeContext API
552 if VersionSalome >= 730:
553 # create the relative launcher and add it to the files to add
554 launcher_name = src.get_launcher_name(config)
555 launcher_package = produce_relative_launcher(config,
560 not(options.without_commercial))
562 d_products["launcher"] = (launcher_package, launcher_name)
564 # if we mix binaries and sources, we add a copy of the launcher,
565 # prefixed with "bin",in order to avoid clashes
566 d_products["launcher (copy)"] = (launcher_package, "bin"+launcher_name)
568 # Provide a script for the creation of an application EDF style
569 appli_script = product_appli_creation_script(config,
574 d_products["appli script"] = (appli_script, "create_appli.py")
576 # Put also the environment file
577 env_file = produce_relative_env_files(config,
582 d_products["environment file"] = (env_file, "env_launch.sh")
586 def source_package(sat, config, logger, options, tmp_working_dir):
587 '''Prepare a dictionary that stores all the needed directories and files to
588 add in a source package.
590 :param config Config: The global configuration.
591 :param logger Logger: the logging instance
592 :param options OptResult: the options of the launched command
593 :param tmp_working_dir str: The temporary local directory containing some
594 specific directories or files needed in the
596 :return: the dictionary that stores all the needed directories and files to
597 add in a source package.
598 {label : (path_on_local_machine, path_in_archive)}
602 # Get all the products that are prepared using an archive
603 logger.write("Find archive products ... ")
604 d_archives, l_pinfo_vcs = get_archives(config, logger)
605 logger.write("Done\n")
607 if not options.with_vcs and len(l_pinfo_vcs) > 0:
608 # Make archives with the products that are not prepared using an archive
609 # (git, cvs, svn, etc)
610 logger.write("Construct archives for vcs products ... ")
611 d_archives_vcs = get_archives_vcs(l_pinfo_vcs,
616 logger.write("Done\n")
619 logger.write("Create the project ... ")
620 d_project = create_project_for_src_package(config,
623 logger.write("Done\n")
626 tmp_sat = add_salomeTools(config, tmp_working_dir)
627 d_sat = {"salomeTools" : (tmp_sat, "salomeTools")}
629 # Add a sat symbolic link if not win
630 if not src.architecture.is_windows():
631 tmp_satlink_path = os.path.join(tmp_working_dir, 'sat')
635 # In the jobs, os.getcwd() can fail
636 t = config.LOCAL.workdir
637 os.chdir(tmp_working_dir)
638 if os.path.lexists(tmp_satlink_path):
639 os.remove(tmp_satlink_path)
640 os.symlink(os.path.join('salomeTools', 'sat'), 'sat')
643 d_sat["sat link"] = (tmp_satlink_path, "sat")
645 d_source = src.merge_dicts(d_archives, d_archives_vcs, d_project, d_sat)
648 def get_archives(config, logger):
649 '''Find all the products that are get using an archive and all the products
650 that are get using a vcs (git, cvs, svn) repository.
652 :param config Config: The global configuration.
653 :param logger Logger: the logging instance
654 :return: the dictionary {name_product :
655 (local path of its archive, path in the package of its archive )}
656 and the list of specific configuration corresponding to the vcs
660 # Get the list of product informations
661 l_products_name = config.APPLICATION.products.keys()
662 l_product_info = src.product.get_products_infos(l_products_name,
666 for p_name, p_info in l_product_info:
667 # ignore the native and fixed products
668 if (src.product.product_is_native(p_info)
669 or src.product.product_is_fixed(p_info)):
671 if p_info.get_source == "archive":
672 archive_path = p_info.archive_info.archive_name
673 archive_name = os.path.basename(archive_path)
675 l_pinfo_vcs.append((p_name, p_info))
677 d_archives[p_name] = (archive_path,
678 os.path.join(ARCHIVE_DIR, archive_name))
679 return d_archives, l_pinfo_vcs
681 def add_salomeTools(config, tmp_working_dir):
682 '''Prepare a version of salomeTools that has a specific local.pyconf file
683 configured for a source package.
685 :param config Config: The global configuration.
686 :param tmp_working_dir str: The temporary local directory containing some
687 specific directories or files needed in the
689 :return: The path to the local salomeTools directory to add in the package
692 # Copy sat in the temporary working directory
693 sat_tmp_path = src.Path(os.path.join(tmp_working_dir, "salomeTools"))
694 sat_running_path = src.Path(config.VARS.salometoolsway)
695 sat_running_path.copy(sat_tmp_path)
697 # Update the local.pyconf file that contains the path to the project
698 local_pyconf_name = "local.pyconf"
699 local_pyconf_dir = os.path.join(tmp_working_dir, "salomeTools", "data")
700 local_pyconf_file = os.path.join(local_pyconf_dir, local_pyconf_name)
701 # Remove the .pyconf file in the root directory of salomeTools if there is
702 # any. (For example when launching jobs, a pyconf file describing the jobs
703 # can be here and is not useful)
704 files_or_dir_SAT = os.listdir(os.path.join(tmp_working_dir, "salomeTools"))
705 for file_or_dir in files_or_dir_SAT:
706 if file_or_dir.endswith(".pyconf") or file_or_dir.endswith(".txt"):
707 file_path = os.path.join(tmp_working_dir,
712 ff = open(local_pyconf_file, "w")
713 ff.write(LOCAL_TEMPLATE)
716 return sat_tmp_path.path
718 def get_archives_vcs(l_pinfo_vcs, sat, config, logger, tmp_working_dir):
719 '''For sources package that require that all products are get using an
720 archive, one has to create some archive for the vcs products.
721 So this method calls the clean and source command of sat and then create
724 :param l_pinfo_vcs List: The list of specific configuration corresponding to
726 :param sat Sat: The Sat instance that can be called to clean and source the
728 :param config Config: The global configuration.
729 :param logger Logger: the logging instance
730 :param tmp_working_dir str: The temporary local directory containing some
731 specific directories or files needed in the
733 :return: the dictionary that stores all the archives to add in the source
734 package. {label : (path_on_local_machine, path_in_archive)}
737 # clean the source directory of all the vcs products, then use the source
738 # command and thus construct an archive that will not contain the patches
739 l_prod_names = [pn for pn, __ in l_pinfo_vcs]
741 logger.write(_("clean sources\n"))
742 args_clean = config.VARS.application
743 args_clean += " --sources --products "
744 args_clean += ",".join(l_prod_names)
745 sat.clean(args_clean, batch=True, verbose=0, logger_add_link = logger)
747 logger.write(_("get sources"))
748 args_source = config.VARS.application
749 args_source += " --products "
750 args_source += ",".join(l_prod_names)
751 sat.source(args_source, batch=True, verbose=0, logger_add_link = logger)
753 # make the new archives
755 for pn, pinfo in l_pinfo_vcs:
756 path_archive = make_archive(pn, pinfo, tmp_working_dir)
757 d_archives_vcs[pn] = (path_archive,
758 os.path.join(ARCHIVE_DIR, pn + ".tgz"))
759 return d_archives_vcs
761 def make_archive(prod_name, prod_info, where):
762 '''Create an archive of a product by searching its source directory.
764 :param prod_name str: The name of the product.
765 :param prod_info Config: The specific configuration corresponding to the
767 :param where str: The path of the repository where to put the resulting
769 :return: The path of the resulting archive
772 path_targz_prod = os.path.join(where, prod_name + ".tgz")
773 tar_prod = tarfile.open(path_targz_prod, mode='w:gz')
774 local_path = prod_info.source_dir
775 tar_prod.add(local_path,
777 exclude=exclude_VCS_and_extensions)
779 return path_targz_prod
781 def create_project_for_src_package(config, tmp_working_dir, with_vcs):
782 '''Create a specific project for a source package.
784 :param config Config: The global configuration.
785 :param tmp_working_dir str: The temporary local directory containing some
786 specific directories or files needed in the
788 :param with_vcs boolean: True if the package is with vcs products (not
789 transformed into archive products)
790 :return: The dictionary
791 {"project" : (produced project, project path in the archive)}
795 # Create in the working temporary directory the full project tree
796 project_tmp_dir = os.path.join(tmp_working_dir, PROJECT_DIR)
797 products_pyconf_tmp_dir = os.path.join(project_tmp_dir,
799 compil_scripts_tmp_dir = os.path.join(project_tmp_dir,
802 env_scripts_tmp_dir = os.path.join(project_tmp_dir,
805 patches_tmp_dir = os.path.join(project_tmp_dir,
808 application_tmp_dir = os.path.join(project_tmp_dir,
810 for directory in [project_tmp_dir,
811 compil_scripts_tmp_dir,
814 application_tmp_dir]:
815 src.ensure_path_exists(directory)
817 # Create the pyconf that contains the information of the project
818 project_pyconf_name = "project.pyconf"
819 project_pyconf_file = os.path.join(project_tmp_dir, project_pyconf_name)
820 ff = open(project_pyconf_file, "w")
821 ff.write(PROJECT_TEMPLATE)
824 # Loop over the products to get there pyconf and all the scripts
825 # (compilation, environment, patches)
826 # and create the pyconf file to add to the project
827 lproducts_name = config.APPLICATION.products.keys()
828 l_products = src.product.get_products_infos(lproducts_name, config)
829 for p_name, p_info in l_products:
830 find_product_scripts_and_pyconf(p_name,
834 compil_scripts_tmp_dir,
837 products_pyconf_tmp_dir)
839 find_application_pyconf(config, application_tmp_dir)
841 d_project = {"project" : (project_tmp_dir, PROJECT_DIR )}
844 def find_product_scripts_and_pyconf(p_name,
848 compil_scripts_tmp_dir,
851 products_pyconf_tmp_dir):
852 '''Create a specific pyconf file for a given product. Get its environment
853 script, its compilation script and patches and put it in the temporary
854 working directory. This method is used in the source package in order to
855 construct the specific project.
857 :param p_name str: The name of the product.
858 :param p_info Config: The specific configuration corresponding to the
860 :param config Config: The global configuration.
861 :param with_vcs boolean: True if the package is with vcs products (not
862 transformed into archive products)
863 :param compil_scripts_tmp_dir str: The path to the temporary compilation
864 scripts directory of the project.
865 :param env_scripts_tmp_dir str: The path to the temporary environment script
866 directory of the project.
867 :param patches_tmp_dir str: The path to the temporary patch scripts
868 directory of the project.
869 :param products_pyconf_tmp_dir str: The path to the temporary product
870 scripts directory of the project.
873 # read the pyconf of the product
874 product_pyconf_path = src.find_file_in_lpath(p_name + ".pyconf",
875 config.PATHS.PRODUCTPATH)
876 product_pyconf_cfg = src.pyconf.Config(product_pyconf_path)
878 # find the compilation script if any
879 if src.product.product_has_script(p_info):
880 compil_script_path = src.Path(p_info.compil_script)
881 compil_script_path.copy(compil_scripts_tmp_dir)
882 product_pyconf_cfg[p_info.section].compil_script = os.path.basename(
883 p_info.compil_script)
884 # find the environment script if any
885 if src.product.product_has_env_script(p_info):
886 env_script_path = src.Path(p_info.environ.env_script)
887 env_script_path.copy(env_scripts_tmp_dir)
888 product_pyconf_cfg[p_info.section].environ.env_script = os.path.basename(
889 p_info.environ.env_script)
890 # find the patches if any
891 if src.product.product_has_patches(p_info):
892 patches = src.pyconf.Sequence()
893 for patch_path in p_info.patches:
894 p_path = src.Path(patch_path)
895 p_path.copy(patches_tmp_dir)
896 patches.append(os.path.basename(patch_path), "")
898 product_pyconf_cfg[p_info.section].patches = patches
901 # put in the pyconf file the resolved values
902 for info in ["git_info", "cvs_info", "svn_info"]:
904 for key in p_info[info]:
905 product_pyconf_cfg[p_info.section][info][key] = p_info[
908 # if the product is not archive, then make it become archive.
909 if src.product.product_is_vcs(p_info):
910 product_pyconf_cfg[p_info.section].get_source = "archive"
911 if not "archive_info" in product_pyconf_cfg[p_info.section]:
912 product_pyconf_cfg[p_info.section].addMapping("archive_info",
913 src.pyconf.Mapping(product_pyconf_cfg),
915 product_pyconf_cfg[p_info.section
916 ].archive_info.archive_name = p_info.name + ".tgz"
918 # write the pyconf file to the temporary project location
919 product_tmp_pyconf_path = os.path.join(products_pyconf_tmp_dir,
921 ff = open(product_tmp_pyconf_path, 'w')
922 ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n")
923 product_pyconf_cfg.__save__(ff, 1)
926 def find_application_pyconf(config, application_tmp_dir):
927 '''Find the application pyconf file and put it in the specific temporary
928 directory containing the specific project of a source package.
930 :param config Config: The global configuration.
931 :param application_tmp_dir str: The path to the temporary application
932 scripts directory of the project.
934 # read the pyconf of the application
935 application_name = config.VARS.application
936 application_pyconf_path = src.find_file_in_lpath(
937 application_name + ".pyconf",
938 config.PATHS.APPLICATIONPATH)
939 application_pyconf_cfg = src.pyconf.Config(application_pyconf_path)
942 application_pyconf_cfg.APPLICATION.workdir = src.pyconf.Reference(
943 application_pyconf_cfg,
945 'VARS.salometoolsway + $VARS.sep + ".."')
947 # Prevent from compilation in base
948 application_pyconf_cfg.APPLICATION.no_base = "yes"
950 # write the pyconf file to the temporary application location
951 application_tmp_pyconf_path = os.path.join(application_tmp_dir,
952 application_name + ".pyconf")
953 ff = open(application_tmp_pyconf_path, 'w')
954 ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n")
955 application_pyconf_cfg.__save__(ff, 1)
958 def project_package(project_file_path, tmp_working_dir):
959 '''Prepare a dictionary that stores all the needed directories and files to
960 add in a project package.
962 :param project_file_path str: The path to the local project.
963 :param tmp_working_dir str: The temporary local directory containing some
964 specific directories or files needed in the
966 :return: the dictionary that stores all the needed directories and files to
967 add in a project package.
968 {label : (path_on_local_machine, path_in_archive)}
972 # Read the project file and get the directories to add to the package
973 project_pyconf_cfg = src.pyconf.Config(project_file_path)
974 paths = {"ARCHIVEPATH" : "archives",
975 "APPLICATIONPATH" : "applications",
976 "PRODUCTPATH" : "products",
978 "MACHINEPATH" : "machines"}
979 # Loop over the project paths and add it
981 if path not in project_pyconf_cfg:
983 # Add the directory to the files to add in the package
984 d_project[path] = (project_pyconf_cfg[path], paths[path])
985 # Modify the value of the path in the package
986 project_pyconf_cfg[path] = src.pyconf.Reference(
989 'project_path + "/' + paths[path] + '"')
992 if "project_path" not in project_pyconf_cfg:
993 project_pyconf_cfg.addMapping("project_path",
994 src.pyconf.Mapping(project_pyconf_cfg),
996 project_pyconf_cfg.project_path = src.pyconf.Reference(project_pyconf_cfg,
1000 # Write the project pyconf file
1001 project_file_name = os.path.basename(project_file_path)
1002 project_pyconf_tmp_path = os.path.join(tmp_working_dir, project_file_name)
1003 ff = open(project_pyconf_tmp_path, 'w')
1004 ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n")
1005 project_pyconf_cfg.__save__(ff, 1)
1007 d_project["Project hat file"] = (project_pyconf_tmp_path, project_file_name)
1011 def add_readme(config, options, where):
1012 readme_path = os.path.join(where, "README")
1013 with codecs.open(readme_path, "w", 'utf-8') as f:
1015 # templates for building the header
1017 # This package was generated with sat $version
1020 # Distribution : $dist
1022 In the following, $$ROOT represents the directory where you have installed
1023 SALOME (the directory where this file is located).
1026 readme_compilation_with_binaries="""
1028 compilation based on the binaries used as prerequisites
1029 =======================================================
1031 If you fail to compile the complete application (for example because
1032 you are not root on your system and cannot install missing packages), you
1033 may try a partial compilation based on the binaries.
1034 For that it is necessary to copy the binaries from BINARIES to INSTALL,
1035 and do some substitutions on cmake and .la files (replace the build directories
1037 The procedure to do it is:
1038 1) Remove or rename INSTALL directory if it exists
1039 2) Execute the shell script install_bin.sh:
1042 3) Use SalomeTool (as explained in Sources section) and compile only the
1043 modules you need to (with -p option)
1046 readme_header_tpl=string.Template(readme_header)
1047 readme_template_path_bin = os.path.join(config.VARS.internal_dir,
1048 "README_BIN.template")
1049 readme_template_path_bin_launcher = os.path.join(config.VARS.internal_dir,
1050 "README_LAUNCHER.template")
1051 readme_template_path_bin_virtapp = os.path.join(config.VARS.internal_dir,
1052 "README_BIN_VIRTUAL_APP.template")
1053 readme_template_path_src = os.path.join(config.VARS.internal_dir,
1054 "README_SRC.template")
1055 readme_template_path_pro = os.path.join(config.VARS.internal_dir,
1056 "README_PROJECT.template")
1057 readme_template_path_sat = os.path.join(config.VARS.internal_dir,
1058 "README_SAT.template")
1060 # prepare substitution dictionary
1062 d['user'] = config.VARS.user
1063 d['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
1064 d['version'] = config.INTERNAL.sat_version
1065 d['dist'] = config.VARS.dist
1066 f.write(readme_header_tpl.substitute(d)) # write the general header (common)
1068 if options.binaries or options.sources:
1069 d['application'] = config.VARS.application
1070 f.write("# Application: " + d['application'] + "\n")
1071 if 'KERNEL' in config.APPLICATION.products:
1072 VersionSalome = src.get_salome_version(config)
1073 # Case where SALOME has the launcher that uses the SalomeContext API
1074 if VersionSalome >= 730:
1075 d['launcher'] = config.APPLICATION.profile.launcher_name
1077 d['virtual_app'] = 'runAppli' # this info is not used now)
1079 # write the specific sections
1080 if options.binaries:
1081 f.write(src.template.substitute(readme_template_path_bin, d))
1082 if "virtual_app" in d:
1083 f.write(src.template.substitute(readme_template_path_bin_virtapp, d))
1085 f.write(src.template.substitute(readme_template_path_bin_launcher, d))
1088 f.write(src.template.substitute(readme_template_path_src, d))
1090 if options.binaries and options.sources:
1091 f.write(readme_compilation_with_binaries)
1094 f.write(src.template.substitute(readme_template_path_pro, d))
1097 f.write(src.template.substitute(readme_template_path_sat, d))
1101 def update_config(config, prop, value):
1102 '''Remove from config.APPLICATION.products the products that have the property given as input.
1104 :param config Config: The global config.
1105 :param prop str: The property to filter
1106 :param value str: The value of the property to filter
1108 src.check_config_has_application(config)
1109 l_product_to_remove = []
1110 for product_name in config.APPLICATION.products.keys():
1111 prod_cfg = src.product.get_product_config(config, product_name)
1112 if src.get_property_in_product_cfg(prod_cfg, prop) == value:
1113 l_product_to_remove.append(product_name)
1114 for product_name in l_product_to_remove:
1115 config.APPLICATION.products.__delitem__(product_name)
1118 '''method that is called when salomeTools is called with --help option.
1120 :return: The text to display for the package command description.
1123 return _("The package command creates an archive.\nThere are 4 kinds of "
1124 "archive, which can be mixed:\n 1- The binary archive. It contains all the product "
1125 "installation directories and a launcher,\n 2- The sources archive."
1126 " It contains the products archives, a project corresponding to "
1127 "the application and salomeTools,\n 3- The project archive. It "
1128 "contains a project (give the project file path as argument),\n 4-"
1129 " The salomeTools archive. It contains salomeTools.\n\nexample:"
1130 "\nsat package SALOME-master --bineries --sources")
1132 def run(args, runner, logger):
1133 '''method that is called when salomeTools is called with package parameter.
1137 (options, args) = parser.parse_args(args)
1139 # Check that a type of package is called, and only one
1140 all_option_types = (options.binaries,
1142 options.project not in ["", None],
1145 # Check if no option for package type
1146 if all_option_types.count(True) == 0:
1147 msg = _("Error: Precise a type for the package\nUse one of the "
1148 "following options: --binaries, --sources, --project or"
1150 logger.write(src.printcolors.printcError(msg), 1)
1151 logger.write("\n", 1)
1154 # The repository where to put the package if not Binary or Source
1155 package_default_path = runner.cfg.LOCAL.workdir
1157 # if the package contains binaries or sources:
1158 if options.binaries or options.sources:
1159 # Check that the command has been called with an application
1160 src.check_config_has_application(runner.cfg)
1162 # Display information
1163 logger.write(_("Packaging application %s\n") % src.printcolors.printcLabel(
1164 runner.cfg.VARS.application), 1)
1166 # Get the default directory where to put the packages
1167 package_default_path = os.path.join(runner.cfg.APPLICATION.workdir,
1169 src.ensure_path_exists(package_default_path)
1171 # if the package contains a project:
1173 # check that the project is visible by SAT
1174 if options.project not in runner.cfg.PROJECTS.project_file_paths:
1175 local_path = os.path.join(runner.cfg.VARS.salometoolsway,
1178 msg = _("ERROR: the project %(proj)s is not visible by salomeTools."
1179 "\nPlease add it in the %(local)s file." % {
1180 "proj" : options.project, "local" : local_path})
1181 logger.write(src.printcolors.printcError(msg), 1)
1182 logger.write("\n", 1)
1185 # Remove the products that are filtered by the --without_property option
1186 if options.without_property:
1187 [prop, value] = options.without_property.split(":")
1188 update_config(runner.cfg, prop, value)
1190 # get the name of the archive or build it
1192 if os.path.basename(options.name) == options.name:
1193 # only a name (not a path)
1194 archive_name = options.name
1195 dir_name = package_default_path
1197 archive_name = os.path.basename(options.name)
1198 dir_name = os.path.dirname(options.name)
1200 # suppress extension
1201 if archive_name[-len(".tgz"):] == ".tgz":
1202 archive_name = archive_name[:-len(".tgz")]
1203 if archive_name[-len(".tar.gz"):] == ".tar.gz":
1204 archive_name = archive_name[:-len(".tar.gz")]
1208 dir_name = package_default_path
1209 if options.binaries or options.sources:
1210 archive_name = runner.cfg.APPLICATION.name
1212 if options.binaries:
1213 archive_name += "-"+runner.cfg.VARS.dist
1216 archive_name += "-SRC"
1217 if options.with_vcs:
1218 archive_name += "-VCS"
1221 project_name, __ = os.path.splitext(
1222 os.path.basename(options.project))
1223 archive_name += ("PROJECT-" + project_name)
1226 archive_name += ("salomeTools_" + runner.cfg.INTERNAL.sat_version)
1227 if len(archive_name)==0: # no option worked
1228 msg = _("Error: Cannot name the archive\n"
1229 " check if at least one of the following options was "
1230 "selected : --binaries, --sources, --project or"
1232 logger.write(src.printcolors.printcError(msg), 1)
1233 logger.write("\n", 1)
1236 path_targz = os.path.join(dir_name, archive_name + ".tgz")
1238 src.printcolors.print_value(logger, "Package path", path_targz, 2)
1240 # Create a working directory for all files that are produced during the
1241 # package creation and that will be removed at the end of the command
1242 tmp_working_dir = os.path.join(runner.cfg.VARS.tmp_root,
1243 runner.cfg.VARS.datehour)
1244 src.ensure_path_exists(tmp_working_dir)
1245 logger.write("\n", 5)
1246 logger.write(_("The temporary working directory: %s\n" % tmp_working_dir),5)
1248 logger.write("\n", 3)
1250 msg = _("Preparation of files to add to the archive")
1251 logger.write(src.printcolors.printcLabel(msg), 2)
1252 logger.write("\n", 2)
1254 d_files_to_add={} # content of the archive
1256 # a dict to hold paths that will need to be substitute for users recompilations
1257 d_paths_to_substitute={}
1259 if options.binaries:
1260 d_bin_files_to_add = binary_package(runner.cfg,
1264 # for all binaries dir, store the substitution that will be required
1265 # for extra compilations
1266 for key in d_bin_files_to_add:
1267 if key.endswith("(bin)"):
1268 source_dir = d_bin_files_to_add[key][0]
1269 path_in_archive = d_bin_files_to_add[key][1].replace("BINARIES-" + runner.cfg.VARS.dist,"INSTALL")
1270 if os.path.basename(source_dir)==os.path.basename(path_in_archive):
1271 # if basename is the same we will just substitute the dirname
1272 d_paths_to_substitute[os.path.dirname(source_dir)]=\
1273 os.path.dirname(path_in_archive)
1275 d_paths_to_substitute[source_dir]=path_in_archive
1277 d_files_to_add.update(d_bin_files_to_add)
1280 d_files_to_add.update(source_package(runner,
1285 if options.binaries:
1286 # for archives with bin and sources we provide a shell script able to
1287 # install binaries for compilation
1288 file_install_bin=produce_install_bin_file(runner.cfg,logger,
1290 d_paths_to_substitute,
1292 d_files_to_add.update({"install_bin" : (file_install_bin, "install_bin.sh")})
1293 logger.write("substitutions that need to be done later : \n", 5)
1294 logger.write(str(d_paths_to_substitute), 5)
1295 logger.write("\n", 5)
1297 # --salomeTool option is not considered when --sources is selected, as this option
1298 # already brings salomeTool!
1300 d_files_to_add.update({"salomeTools" : (runner.cfg.VARS.salometoolsway, "")})
1304 d_files_to_add.update(project_package(options.project, tmp_working_dir))
1306 if not(d_files_to_add):
1307 msg = _("Error: Empty dictionnary to build the archive!\n")
1308 logger.write(src.printcolors.printcError(msg), 1)
1309 logger.write("\n", 1)
1312 # Add the README file in the package
1313 local_readme_tmp_path = add_readme(runner.cfg,
1316 d_files_to_add["README"] = (local_readme_tmp_path, "README")
1318 # Add the additional files of option add_files
1319 if options.add_files:
1320 for file_path in options.add_files:
1321 if not os.path.exists(file_path):
1322 msg = _("WARNING: the file %s is not accessible.\n" % file_path)
1324 file_name = os.path.basename(file_path)
1325 d_files_to_add[file_name] = (file_path, file_name)
1327 logger.write("\n", 2)
1329 logger.write(src.printcolors.printcLabel(_("Actually do the package")), 2)
1330 logger.write("\n", 2)
1333 # Creating the object tarfile
1334 tar = tarfile.open(path_targz, mode='w:gz')
1336 # get the filtering function if needed
1337 filter_function = exclude_VCS_and_extensions
1339 # Add the files to the tarfile object
1340 res = add_files(tar, archive_name, d_files_to_add, logger, f_exclude=filter_function)
1342 except KeyboardInterrupt:
1343 logger.write(src.printcolors.printcError("\nERROR: forced interruption\n"), 1)
1344 logger.write(_("Removing the temporary working directory ... "), 1)
1345 # remove the working directory
1346 shutil.rmtree(tmp_working_dir)
1347 logger.write(_("OK"), 1)
1348 logger.write(_("\n"), 1)
1351 # remove the working directory
1352 shutil.rmtree(tmp_working_dir)
1354 # Print again the path of the package
1355 logger.write("\n", 2)
1356 src.printcolors.print_value(logger, "Package path", path_targz, 2)