# set platform parameters
dist_name = src.architecture.get_distribution(codes=distrib_cfg.DISTRIBUTIONS)
- dist_version = src.architecture.get_distrib_version(dist_name, codes=distrib_cfg.VERSIONS)
- dist_version_full = src.architecture.get_infosys()
+ dist_version = src.architecture.get_distrib_version(dist_name)
+ dist_version_full = src.architecture.get_version_XY()
dist = dist_name + dist_version
var['dist_name'] = dist_name
"The projects definition\n")
for project_pyconf_path in cfg.PROJECTS.project_file_paths:
+ if not os.path.isabs(project_pyconf_path):
+ # for a relative path (archive case) we complete with sat path
+ project_pyconf_path = os.path.join(cfg.VARS.salometoolsway,
+ project_pyconf_path)
if not os.path.exists(project_pyconf_path):
msg = _("WARNING: The project file %s cannot be found. "
"It will be ignored\n" % project_pyconf_path)
product_file_path = src.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH)
if product_file_path:
products_dir = os.path.dirname(product_file_path)
+ # for a relative path (archive case) we complete with sat path
+ if not os.path.isabs(products_dir):
+ products_dir = os.path.join(cfg.VARS.salometoolsway,
+ products_dir)
try:
prod_cfg = src.pyconf.Config(open(product_file_path),
PWD=("", products_dir))
application_pyconf_cfg.__save__(ff, 1)
ff.close()
-def project_package(config, name_project, project_file_path, ftp_mode, tmp_working_dir, logger):
+def sat_package(config, tmp_working_dir, project_name, project_file_path, logger):
+ '''Prepare a dictionary that stores all the needed directories and files to
+ add in a salomeTool package.
+
+ :param tmp_working_dir str: The temporary local working directory
+ :param project Boolean : Does the archive contain projects
+ :param project_file_path : The path to the local project
+ :return: the dictionary that stores all the needed directories and files to
+ add in a salomeTool package.
+ {label : (path_on_local_machine, path_in_archive)}
+ :rtype: dict
+ '''
+ d_project = {}
+
+ # we include sat himself
+ d_project["all_sat"]=(config.VARS.salometoolsway, "")
+
+ # and we overwrite local.pyconf with a clean wersion.
+ local_pyconf_tmp_path = os.path.join(tmp_working_dir, "local.pyconf")
+ local_file_path = os.path.join(config.VARS.datadir, "local.pyconf")
+ local_cfg = src.pyconf.Config(local_file_path)
+ local_cfg.PROJECTS.project_file_paths=src.pyconf.Sequence(local_cfg.PROJECTS)
+ local_cfg.LOCAL["base"] = "default"
+ local_cfg.LOCAL["workdir"] = "default"
+ local_cfg.LOCAL["log_dir"] = "default"
+ local_cfg.LOCAL["archive_dir"] = "default"
+ local_cfg.LOCAL["VCS"] = "None"
+ local_cfg.LOCAL["tag"] = src.get_salometool_version(config)
+
+ # if the archive contains a project, we write its relative path in local.pyconf
+ if project_name:
+ project_arch_path = os.path.join("projects", project_name,
+ os.path.basename(project_file_path))
+ local_cfg.PROJECTS.project_file_paths.append(project_arch_path, "")
+
+ ff = open(local_pyconf_tmp_path, 'w')
+ local_cfg.__save__(ff, 1)
+ ff.close()
+ d_project["local.pyconf"]=(local_pyconf_tmp_path, "data/local.pyconf")
+ return d_project
+
+
+def project_package(config, name_project, project_file_path, ftp_mode, tmp_working_dir, embedded_in_sat, logger):
'''Prepare a dictionary that stores all the needed directories and files to
add in a project package.
:param tmp_working_dir str: The temporary local directory containing some
specific directories or files needed in the
project package
+ :param embedded_in_sat boolean : the project package is embedded in a sat package
:return: the dictionary that stores all the needed directories and files to
add in a project package.
{label : (path_on_local_machine, path_in_archive)}
paths["ARCHIVEPATH"] = "archives"
# Loop over the project paths and add it
+ project_file_name = os.path.basename(project_file_path)
for path in paths:
if path not in project_pyconf_cfg:
continue
+ if embedded_in_sat:
+ dest_path = os.path.join("projects", name_project, paths[path])
+ project_file_dest = os.path.join("projects", name_project, project_file_name)
+ else:
+ dest_path = paths[path]
+ project_file_dest = project_file_name
+
# Add the directory to the files to add in the package
- d_project[path] = (project_pyconf_cfg[path], paths[path])
+ d_project[path] = (project_pyconf_cfg[path], dest_path)
+
# Modify the value of the path in the package
project_pyconf_cfg[path] = src.pyconf.Reference(
project_pyconf_cfg,
project_pyconf_cfg.project_path = src.pyconf.Reference(project_pyconf_cfg,
src.pyconf.DOLLAR,
'PWD')
+ # we don't want to export these two fields
+ project_pyconf_cfg.__delitem__("file_path")
+ project_pyconf_cfg.__delitem__("PWD")
+ if ftp_mode:
+ project_pyconf_cfg.__delitem__("ARCHIVEPATH")
# Write the project pyconf file
- project_file_name = os.path.basename(project_file_path)
project_pyconf_tmp_path = os.path.join(tmp_working_dir, project_file_name)
ff = open(project_pyconf_tmp_path, 'w')
ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n")
project_pyconf_cfg.__save__(ff, 1)
ff.close()
- d_project["Project hat file"] = (project_pyconf_tmp_path, project_file_name)
+ d_project["Project hat file"] = (project_pyconf_tmp_path, project_file_dest)
return d_project
if options.with_vcs:
archive_name += "-VCS"
+ if options.sat:
+ archive_name += ("salomeTools_" + src.get_salometool_version(runner.cfg))
+
if options.project:
+ if options.sat:
+ archive_name += "_"
project_name = options.project
- archive_name += ("PROJECT-" + project_name)
+ archive_name += ("satproject_" + project_name)
- if options.sat:
- 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 "
# --salomeTool option is not considered when --sources is selected, as this option
# already brings salomeTool!
if options.sat:
- d_files_to_add.update({"salomeTools" : (runner.cfg.VARS.salometoolsway, "")})
+ d_files_to_add.update(sat_package(runner.cfg, tmp_working_dir,
+ project_name, options.project_file_path, logger))
if options.project:
DBG.write("config for package %s" % project_name, runner.cfg)
- d_files_to_add.update(project_package(runner.cfg, project_name, options.project_file_path, options.ftp, tmp_working_dir, logger))
+ d_files_to_add.update(project_package(runner.cfg, project_name, options.project_file_path, options.ftp, tmp_working_dir, options.sat, logger))
if not(d_files_to_add):
msg = _("Error: Empty dictionnary to build the archive!\n")
import pwd
return pwd.getpwuid(os.getuid())[0]
-def _lsb_release(args):
- '''Get system information with lsb_release.
-
- :param args str: The arguments to give to lsb_release.
- :return: The distribution.
- :rtype: str
- '''
- try:
- path = '/usr/local/bin:/usr/bin:/bin'
- lsb_path = os.getenv("LSB_PATH")
- if lsb_path is not None:
- path = lsb_path + ":" + path
-
- from subprocess import Popen, PIPE
- res = Popen(['lsb_release', args], env={'PATH': path}, stdout=PIPE).communicate()[0][:-1]
- # in case of python3, convert byte to str
- if isinstance(res, bytes):
- res = res.decode()
- return res
- except OSError:
- sys.stderr.write(_(u"lsb_release not installed\n"))
- sys.stderr.write(_(u"You can define $LSB_PATH to give the path to lsb_release\n"))
- sys.exit(-1)
def get_distribution(codes):
'''Gets the code for the distribution
if is_windows():
return "Win"
- # Call to lsb_release
- distrib = _lsb_release('-si')
- if codes is not None and distrib in codes:
- distrib = codes[distrib]
- else:
+ # else get linux distribution description from platform, and encode it with code
+ lin_distrib = platform.dist()[0].lower()
+ distrib="not found"
+ for dist in codes:
+ if dist in lin_distrib:
+ distrib = codes[dist]
+ break
+ if distrib=="not found":
sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib)
sys.stderr.write(_(u"Please add your distribution to src/internal_config/distrib.pyconf\n"))
sys.exit(-1)
return distrib
-def get_infosys():
+def get_version_XY():
"""
- from a CentOS example,
- returns '7.6' from command 'lsb_release -ds'
- extracted from 'CentOS Linux release 7.6.1810 (Core)'
- and also for RedHat fedora etc.
+ Return major and minor version of the distribution
+ from a CentOS example, returns '7.6'
+ extracted from platform.dist()
"""
- import re
- osys = ""
- version = ""
- architecture = ""
- osys_value = "Unknown"
- os_dict = {"mandrivalinux":"MD",
- "centos":"CO",
- "RedHatEnterpriseServer":"CO",
- "RedHatEnterpriseWorkstation":"CO",
- "fedora":"FD",
- "ubuntu":"UB",
- "debian":"DB",
- "mageia":"MG",}
- # lsb_cmd = "lsb_release -ds"
- args = "-ds"
- output = _lsb_release(args)
- # print("lsb_release output %s" % output)
- regexp = r"(^[0-9]+([.]?[0-9]+)+)"
- for an_item in output.replace('"','').split():
- if re.match(regexp, an_item) is not None and not version:
- version = ".".join(an_item.split(".")[:2])
- else:
- for sub_item in os_dict.keys():
- if sub_item == an_item.lower():
- osys = an_item
- osys_value = os_dict[sub_item]
- if version and osys: break
- return version
+ dist_version=platform.dist()[1].split('.')
+ if len(dist_version)==1:
+ version = dist_version[0]
+ else:
+ version = dist_version[0] + "." + dist_version[1]
+ return version
-def get_distrib_version(distrib, codes):
- '''Gets the version of the distribution
+
+def get_distrib_version(distrib):
+ '''Return the sat encoded version of the distribution
+ This code is used in config to apend the name of the application directories
+ withdistribution info"
:param distrib str: The distribution on which the version will be found.
- :param codes L{Mapping}: The map containing distribution correlation table.
:return: The version of the distribution on which salomeTools is running,
regarding the distribution correlation table contained in codes
variable.
if is_windows():
return platform.release()
- # Call to lsb_release
- version = _lsb_release('-sr')
- if distrib in codes:
- if version in codes[distrib]:
- version = codes[distrib][version]
+ # get version from platform
+ dist_version=platform.dist()[1].split('.')
+ # encode it (conform to src/internal_config/distrib.pyconf VERSIONS dist
if distrib == "CO":
- version=version[0] #for centos, we only care for major version
+ version=dist_version[0] # for centos, we only care for major version
+ elif distrib == "UB":
+ # for ubuntu, we care for major + minor version
+ version=dist_version[0] + "." + dist_version[1]
+ elif distrib == "DB":
+ if len(dist_version[0]) == 1:
+ version="0"+dist_version[0]
+ else:
+ version=dist_version[0] # unstable, and version >= 10
+ elif distrib == "MG":
+ version="0"+dist_version[0]
+ else:
+ version=dist_version[0]
+
return version
def get_python_version():
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"]
-}
# If no code is found an error will be raised.
DISTRIBUTIONS :
{
- "bullxServer": "BS"
- "CentOS": "CO"
- "Debian": "DB"
- "Fedora": "FD"
- "LinuxMint": "MN"
- "Mageia": "MG"
- "MandrivaLinux": "MD"
- "RedHatEnterpriseServer": "CO"
- "RedHatEnterpriseWorkstation" : "CO"
- "Ubuntu": "UB"
- "openSUSE project":"OS"
+ "centos": "CO"
+ "debian": "DB"
+ "fedora": "FD"
+ "linuxmint": "MN"
+ "mageia": "MG"
+ "mandriva": "MD"
+ "redhat": "CO"
+ "ubuntu": "UB"
+ "opensuse":"OS"
}
-
-# versions substitution
-# Code to use for release, to the replace value returned by: lsb_release -sr
-# If no code is found the value is used.
-VERSIONS :
-{
-
- # Do not do anything for the ubuntu machines (CEA descision).
-
- "DB":
- {
- "unstable": "sid"
- "5.0": "05"
- "4.0": "04"
- "6.0.7" : "06"
- "6.0.10": "06"
- "7.1" : "07"
- "7.11" : "07"
- "7.2" : "07"
- "7.3" : "07"
- "7.5" : "07"
- "8.1" : "08"
- "8.2" : "08"
- "8.3" : "08"
- "8.4" : "08"
- "8.5" : "08"
- "8.6" : "08"
- "8.7" : "08"
- "8.8" : "08"
- "9.1" : "09"
- "9.2" : "09"
- "9.3" : "09"
- "9.4" : "09"
- "9.5" : "09"
- "9.6" : "09"
- "9.7" : "09"
- "9.8" : "09"
- }
- "MD":
- {
- "2008.0": "08"
- "2010.0": "10"
- "2010.1": "10"
- "2010.2": "10"
- "2007.1": "07"
- "2006.0": "06"
- "4" : "06"
- }
- "MG":
- {
- "3": "03"
- "4": "04"
- "5": "05"
- "6": "06"
- }
- "CO":
- {
- "7.1.1503": "7"
- "7.2.1511": "7"
- "7.3.1611": "7"
- "6.1" : "6"
- "6.2" : "6"
- "6.3" : "6"
- "6.4" : "6"
- "6.5" : "6"
- "6.6" : "6"
- "6.7" : "6"
- }
-}
-
else:
ko.append(p_name)
except:
- ok.append(p_name)
+ ko.append(p_name)
if len(ok) != len(resAll):
logger.trace("on properties %s\n products accepted:\n %s\n products rejected:\n %s\n" %