# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
-import shutil
-import re
-import subprocess
import src
-import prepare
+import source
import src.debug as DBG
# Define all possible option for patch command : sat patch <options>
return retcode
-def get_source_from_archive(config, product_info, source_dir, logger):
- """The method called if the product is to be get in archive mode
-
- :param config Config: The global configuration
- :param product_info Config: The configuration specific to
- the product to be prepared
- :param source_dir Path: The Path instance corresponding to the
- directory where to put the sources
- :param logger Logger: The logger instance to use for the display and logging
- :return: True if it succeed, else False
- :rtype: boolean
- """
-
- # check if pip should be used : pip mode id activated if the application
- # and product have pip property
- if src.appli_test_property(
- config, "pip", "yes"
- ) and src.product.product_test_property(product_info, "pip", "yes"):
- pip_msg = "PIP : do nothing, product will be downloaded later at compile time "
- logger.write(pip_msg, 3)
- return True
-
- # check archive exists
- if not os.path.exists(product_info.archive_info.archive_name):
- # The archive is not found on local file system (ARCHIVEPATH)
- # We try ftp!
- logger.write(
- "\n The archive is not found on local file system, we try ftp\n", 3
- )
- ret = src.find_file_in_ftppath(
- product_info.archive_info.archive_name,
- config.PATHS.ARCHIVEFTP,
- config.LOCAL.archive_dir,
- logger,
- )
- if ret:
- # archive was found on ftp and stored in ret
- product_info.archive_info.archive_name = ret
- else:
- raise src.SatException(
- _("Archive not found in ARCHIVEPATH, nor on ARCHIVEFTP: '%s'")
- % product_info.archive_info.archive_name
- )
-
- logger.write(
- "arc:%s ... "
- % src.printcolors.printcInfo(product_info.archive_info.archive_name),
- 3,
- False,
- )
- logger.flush()
- # Call the system function that do the extraction in archive mode
- retcode, NameExtractedDirectory = src.system.archive_extract(
- product_info.archive_info.archive_name, source_dir.dir(), logger
- )
-
- # Rename the source directory if
- # it does not match with product_info.source_dir
- if NameExtractedDirectory.replace("/", "") != os.path.basename(
- product_info.source_dir
- ):
- shutil.move(
- os.path.join(
- os.path.dirname(product_info.source_dir), NameExtractedDirectory
- ),
- product_info.source_dir,
- )
-
- return retcode
-
-
-def get_source_from_dir(product_info, source_dir, logger):
- if "dir_info" not in product_info:
- msg = _(
- "Error: you must put a dir_info section"
- " in the file %s.pyconf" % product_info.name
- )
- logger.write("\n%s\n" % src.printcolors.printcError(msg), 1)
- return False
-
- if "dir" not in product_info.dir_info:
- msg = _(
- "Error: you must put a dir in the dir_info section"
- " in the file %s.pyconf" % product_info.name
- )
- logger.write("\n%s\n" % src.printcolors.printcError(msg), 1)
- return False
-
- # check that source exists
- if not os.path.exists(product_info.dir_info.dir):
- msg = _(
- "Error: the dir %s defined in the file"
- " %s.pyconf does not exists"
- % (product_info.dir_info.dir, product_info.name)
- )
- logger.write("\n%s\n" % src.printcolors.printcError(msg), 1)
- return False
-
- logger.write(
- "DIR: %s ... " % src.printcolors.printcInfo(product_info.dir_info.dir), 3
- )
- logger.flush()
-
- retcode = src.Path(product_info.dir_info.dir).copy(source_dir)
-
- return retcode
-
-
-def get_source_from_cvs(
- user, product_info, source_dir, checkout, logger, pad, environ=None
-):
- """The method called if the product is to be get in cvs mode
-
- :param user str: The user to use in for the cvs command
- :param product_info Config: The configuration specific to
- the product to be prepared
- :param source_dir Path: The Path instance corresponding to the
- directory where to put the sources
- :param checkout boolean: If True, get the source in checkout mode
- :param logger Logger: The logger instance to use for the display and logging
- :param pad int: The gap to apply for the terminal display
- :param environ src.environment.Environ: The environment to source when
- extracting.
- :return: True if it succeed, else False
- :rtype: boolean
- """
- # Get the protocol to use in the command
- if "protocol" in product_info.cvs_info:
- protocol = product_info.cvs_info.protocol
- else:
- protocol = "pserver"
-
- # Construct the line to display
- if "protocol" in product_info.cvs_info:
- cvs_line = "%s:%s@%s:%s" % (
- protocol,
- user,
- product_info.cvs_info.server,
- product_info.cvs_info.product_base,
- )
- else:
- cvs_line = "%s / %s" % (
- product_info.cvs_info.server,
- product_info.cvs_info.product_base,
- )
-
- coflag = "cvs"
- if checkout:
- coflag = src.printcolors.printcHighlight(coflag.upper())
-
- logger.write("%s:%s" % (coflag, src.printcolors.printcInfo(cvs_line)), 3, False)
- logger.write(" " * (pad + 50 - len(cvs_line)), 3, False)
- logger.write(
- " src:%s" % src.printcolors.printcInfo(product_info.cvs_info.source), 3, False
- )
- logger.write(" " * (pad + 1 - len(product_info.cvs_info.source)), 3, False)
- logger.write(
- " tag:%s" % src.printcolors.printcInfo(product_info.cvs_info.tag), 3, False
- )
- # at least one '.' is visible
- logger.write(" %s. " % ("." * (10 - len(product_info.cvs_info.tag))), 3, False)
- logger.flush()
- logger.write("\n", 5, False)
-
- # Call the system function that do the extraction in cvs mode
- retcode = src.system.cvs_extract(
- protocol,
- user,
- product_info.cvs_info.server,
- product_info.cvs_info.product_base,
- product_info.cvs_info.tag,
- product_info.cvs_info.source,
- source_dir,
- logger,
- checkout,
- environ,
- )
- return retcode
-
-
-def get_source_from_svn(user, product_info, source_dir, checkout, logger, environ=None):
- """The method called if the product is to be get in svn mode
-
- :param user str: The user to use in for the svn command
- :param product_info Config: The configuration specific to
- the product to be prepared
- :param source_dir Path: The Path instance corresponding to the
- directory where to put the sources
- :param checkout boolean: If True, get the source in checkout mode
- :param logger Logger: The logger instance to use for the display and logging
- :param environ src.environment.Environ: The environment to source when
- extracting.
- :return: True if it succeed, else False
- :rtype: boolean
- """
- coflag = "svn"
- if checkout:
- coflag = src.printcolors.printcHighlight(coflag.upper())
-
- logger.write(
- "%s:%s ... " % (coflag, src.printcolors.printcInfo(product_info.svn_info.repo)),
- 3,
- False,
- )
- logger.flush()
- logger.write("\n", 5, False)
- # Call the system function that do the extraction in svn mode
- retcode = src.system.svn_extract(
- user,
- product_info.svn_info.repo,
- product_info.svn_info.tag,
- source_dir,
- logger,
- checkout,
- environ,
- )
- return retcode
-
-
def update_product_sources(
config, product_info, is_dev, source_dir, logger, pad, checkout=False
):
# Call the right function to get sources regarding the product settings
if not checkout and is_dev:
- return get_source_for_dev(config, product_info, source_dir, logger, pad)
+ return source.get_source_for_dev(config, product_info, source_dir, logger, pad)
if product_info.get_source == "git":
return update_source_from_git(
)
if product_info.get_source == "archive":
- return get_source_from_archive(config, product_info, source_dir, logger)
+ return source.get_source_from_archive(config, product_info, source_dir, logger)
if product_info.get_source == "dir":
- return get_source_from_dir(product_info, source_dir, logger)
+ return source.get_source_from_dir(product_info, source_dir, logger)
if product_info.get_source == "cvs":
cvs_user = config.USER.cvs_user
- return get_source_from_cvs(
+ return source.get_source_from_cvs(
cvs_user, product_info, source_dir, checkout, logger, pad, env_appli
)
if product_info.get_source == "svn":
svn_user = config.USER.svn_user
- return get_source_from_svn(
+ return source.get_source_from_svn(
svn_user, product_info, source_dir, checkout, logger, env_appli
)
logger.write(" - " + pkg + " : " + build_pkg[pkg] + "\n", 1)
if "KO" in build_pkg[pkg]:
result = False
- if result == False:
+ if not result:
logger.error(
"some system dependencies are missing, please install them with "
+ check_cmd[0]
# Get the maximum name length in order to format the terminal display
max_product_name_len = 1
if len(products) > 0:
- max_product_name_len = max(map(lambda l: len(l), products[0])) + 4
+ max_product_name_len = max(map(lambda lgth: len(lgth), products[0])) + 4
# The loop on all the products from which to get the sources
# DBG.write("source.get_all_product_sources config id", id(config), True)
logger.write(" " * (max_product_name_len - len(product_name)), 3, False)
logger.write("\n", 4, False)
- # TODO: check that there is no pb on not .git tracked products
- # if source_dir.exists():
- # logger.write("%s " % src.printcolors.printc(src.OK_STATUS), 3, False)
- # msg = (
- # _(
- # "INFO : Not doing anything because the source directory already exists:\n %s\n"
- # )
- # % source_dir
- # )
- # logger.write(msg, 3)
- # good_result = good_result + 1
- # # Do not get the sources and go to next product
- # continue
-
is_dev = src.product.product_is_dev(product_info)
# Call to the function that get the sources for one product
retcode = update_product_sources(
# 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 re
import os
-import pprint as PP
import src
-import src.debug as DBG
+import prepare
# Define all possible option for update command : sat update <options>
parser.add_option('', 'force_patch', 'boolean', 'force_patch',
_("Optional: force to apply patch to the products in development mode."))
-def find_products_already_prepared(l_products):
- """function that returns the list of products that have an existing source
- directory.
-
- :param l_products List: The list of products to check
- :return: The list of product configurations that have an existing source
- directory.
- :rtype: List
- """
- l_res = []
- for p_name_p_cfg in l_products:
- __, prod_cfg = p_name_p_cfg
- if "source_dir" in prod_cfg and os.path.exists(prod_cfg.source_dir):
- l_res.append(p_name_p_cfg)
- return l_res
def find_git_products(l_products):
"""
return l_res
-def find_products_with_patchs(l_products):
- """function that returns the list of products that have one or more patches.
-
- :param l_products List: The list of products to check
- :return: The list of product configurations that have one or more patches.
- :rtype: List
- """
- l_res = []
- for p_name_p_cfg in l_products:
- __, prod_cfg = p_name_p_cfg
- l_patchs = src.get_cfg_param(prod_cfg, "patches", [])
- if len(l_patchs) > 0:
- l_res.append(p_name_p_cfg)
- return l_res
-
def description():
"""method that is called when salomeTools is called with --help option.
"""
pi_already_prepared = find_git_products(self.products_infos)
l_already_prepared = [i for i, tmp in pi_already_prepared]
- newList, removedList = removeInList(self.products, l_already_prepared)
+ newList, removedList = prepare.removeInList(self.products, l_already_prepared)
if len(newList) == 0 and len(removedList) > 0:
msg = "\nAll the products are already installed, do nothing!\n"
self.logger.write(src.printcolors.printcWarning(msg), 1)
ldev_products = [p for p in self.products_infos if src.product.product_is_dev(p[1])]
productsToClean = listProdToPrepare # default
if len(ldev_products) > 0:
- l_products_not_getted = find_products_already_prepared(ldev_products)
+ l_products_not_getted = prepare.find_products_already_prepared(ldev_products)
listNot = [i for i, tmp in l_products_not_getted]
- productsToClean, removedList = removeInList(listProdToPrepare, listNot)
+ productsToClean, removedList = prepare.removeInList(listProdToPrepare, listNot)
if len(removedList) > 0:
msg = _(
"""
productsToPatch = listProdToPrepare # default
ldev_products = [p for p in self.products_infos if src.product.product_is_dev(p[1])]
if not self._force_patch and len(ldev_products) > 0:
- l_products_with_patchs = find_products_with_patchs(ldev_products)
+ l_products_with_patchs = prepare.find_products_with_patchs(ldev_products)
listNot = [i for i, tmp in l_products_with_patchs]
- productsToPatch, removedList = removeInList(listProdToPrepare, listNot)
+ productsToPatch, removedList = prepare.removeInList(listProdToPrepare, listNot)
if len(removedList) > 0:
msg = _(
"""
return res
-def removeInList(aList, removeList):
- """Removes elements of removeList list from aList
-
- :param aList: (list) The list from which to remove elements
- :param removeList: (list) The list which contains elements to remove
- :return: (list, list) (list with elements removed, list of elements removed)
- """
- res1 = [i for i in aList if i not in removeList]
- res2 = [i for i in aList if i in removeList]
- return (res1, res2)