X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=commands%2Fsource.py;h=b40a6b4f3c962fafe2eae80a1136e9a32cc51750;hb=8907858912a4ceb6358a1f6659e8b9dbd6ef4ef4;hp=be83c0c25a2d2a0b1f022a4b9001ac92f7534ae6;hpb=713d5abd2d3bb247d0175df72ada29cfaa3129de;p=tools%2Fsat.git diff --git a/commands/source.py b/commands/source.py index be83c0c..b40a6b4 100644 --- a/commands/source.py +++ b/commands/source.py @@ -22,17 +22,13 @@ import shutil import src import prepare -# Define all possible option for log command : sat log +# Define all possible option for patch command : sat patch parser = src.options.Options() -parser.add_option('p', 'product', 'list2', 'products', - _('products from which to get the sources. This option can be' +parser.add_option('p', 'products', 'list2', 'products', + _('Optional: products from which to get the sources. This option can be' ' passed several time to get the sources of several products.')) -parser.add_option('', 'no_sample', 'boolean', 'no_sample', - _("do not get sources from sample products.")) -parser.add_option('f', 'force', 'boolean', 'force', - _("force to get the sources of the products in development mode.")) -def get_source_for_dev(config, product_info, source_dir, force, logger, pad): +def get_source_for_dev(config, product_info, source_dir, logger, pad): '''The method called if the product is in development mode :param config Config: The global configuration @@ -40,29 +36,23 @@ def get_source_for_dev(config, product_info, source_dir, force, logger, pad): the product to be prepared :param source_dir Path: The Path instance corresponding to the directory where to put the sources - :param force boolean: True if the --force option was invoked :param logger Logger: The logger instance to use for the display and logging :param pad int: The gap to apply for the terminal display :return: True if it succeed, else False :rtype: boolean ''' - retcode = 'N\A' - # if the product source directory does not exist, - # get it in checkout mode, else, do not do anything - # unless the force option is invoked - if not os.path.exists(product_info.source_dir) or force: - # Call the function corresponding to get the sources with True checkout - retcode = get_product_sources(config, - product_info, - True, - source_dir, - force, - logger, - pad, - checkout=True) - logger.write("\n", 3, False) - # +2 because product name is followed by ': ' - logger.write(" " * (pad+2), 3, False) + + # Call the function corresponding to get the sources with True checkout + retcode = get_product_sources(config, + product_info, + True, + source_dir, + logger, + pad, + checkout=True) + logger.write("\n", 3, False) + # +2 because product name is followed by ': ' + logger.write(" " * (pad+2), 3, False) logger.write('dev: %s ... ' % src.printcolors.printcInfo(product_info.source_dir), 3, False) @@ -70,7 +60,12 @@ def get_source_for_dev(config, product_info, source_dir, force, logger, pad): return retcode -def get_source_from_git(product_info, source_dir, logger, pad, is_dev=False): +def get_source_from_git(product_info, + source_dir, + logger, + pad, + is_dev=False, + environ = None): '''The method called if the product is to be get in git mode :param product_info Config: The configuration specific to @@ -80,6 +75,8 @@ def get_source_from_git(product_info, source_dir, logger, pad, is_dev=False): :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 is_dev boolean: True if the product is in development mode + :param environ src.environment.Environ: The environment to source when + extracting. :return: True if it succeed, else False :rtype: boolean ''' @@ -109,7 +106,7 @@ def get_source_from_git(product_info, source_dir, logger, pad, is_dev=False): # Call the system function that do the extraction in git mode retcode = src.system.git_extract(repo_git, product_info.git_info.tag, - source_dir, logger) + source_dir, logger, environ) return retcode def get_source_from_archive(product_info, source_dir, logger): @@ -148,7 +145,13 @@ def get_source_from_archive(product_info, source_dir, logger): return retcode -def get_source_from_cvs(user, product_info, source_dir, checkout, logger, pad): +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 @@ -159,6 +162,8 @@ def get_source_from_cvs(user, product_info, source_dir, checkout, logger, pad): :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 ''' @@ -206,10 +211,15 @@ def get_source_from_cvs(user, product_info, source_dir, checkout, logger, pad): product_info.cvs_info.product_base, product_info.cvs_info.tag, product_info.cvs_info.source, - source_dir, logger, checkout) + source_dir, logger, checkout, environ) return retcode -def get_source_from_svn(user, product_info, source_dir, checkout, logger): +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 @@ -219,6 +229,8 @@ def get_source_from_svn(user, product_info, source_dir, checkout, logger): 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 ''' @@ -238,14 +250,14 @@ def get_source_from_svn(user, product_info, source_dir, checkout, logger): product_info.svn_info.tag, source_dir, logger, - checkout) + checkout, + environ) return retcode def get_product_sources(config, product_info, is_dev, source_dir, - force, logger, pad, checkout=False): @@ -257,24 +269,30 @@ def get_product_sources(config, :param is_dev boolean: True if the product is in development mode :param source_dir Path: The Path instance corresponding to the directory where to put the sources - :param force boolean: True if the --force option was invoked :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 checkout boolean: If True, get the source in checkout mode :return: True if it succeed, else False :rtype: boolean ''' + + # Get the application environment + logger.write(_("Set the application environment\n"), 5) + env_appli = src.environment.SalomeEnviron(config, + src.environment.Environ(dict(os.environ))) + env_appli.set_application_env(logger) + + # 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, - force, logger, pad) if product_info.get_source == "git": return get_source_from_git(product_info, source_dir, logger, pad, - is_dev) + is_dev,env_appli) if product_info.get_source == "archive": return get_source_from_archive(product_info, source_dir, logger) @@ -286,42 +304,48 @@ def get_product_sources(config, source_dir, checkout, logger, - pad) + pad, + env_appli) if product_info.get_source == "svn": svn_user = config.USER.svn_user return get_source_from_svn(svn_user, product_info, source_dir, checkout, - logger) + logger, + env_appli) if product_info.get_source == "native": # skip - logger.write('%s ...' % _("native (ignored)"), 3, False) + logger.write('%s ' % src.printcolors.printc(src.OK_STATUS), + 3, + False) + msg = _('INFORMATION : Not doing anything because the product' + ' is of type "native".\n') + logger.write(msg, 3) return True if product_info.get_source == "fixed": # skip - logger.write('%s ...' % _("fixed (ignored)"), 3, False) + logger.write('%s ' % src.printcolors.printc(src.OK_STATUS), + 3, + False) + msg = _('INFORMATION : Not doing anything because the product' + ' is of type "fixed".\n') + logger.write(msg, 3) return True - - if len(product_info.get_source) == 0: - # skip - logger.write('%s ...' % _("ignored"), 3, False) - return True - # if the get_source is not in [git, archive, cvs, svn, dir] - logger.write(_("Unknown get_mehtod %(get)s for product %(product)s") % \ + # if the get_source is not in [git, archive, cvs, svn, fixed, native] + logger.write(_("Unknown get source method \"%(get)s\" for product %(product)s") % \ { 'get': product_info.get_source, 'product': product_info.name }, 3, False) logger.write(" ... ", 3, False) logger.flush() return False -def get_all_product_sources(config, products, force, logger): +def get_all_product_sources(config, products, logger): '''Get all the product sources. :param config Config: The global configuration :param products List: The list of tuples (product name, product informations) - :param force boolean: True if the --force option was invoked :param logger Logger: The logger instance to be used for the logging :return: the tuple (number of success, dictionary product_name/success_fail) :rtype: (int,dict) @@ -340,7 +364,8 @@ def get_all_product_sources(config, products, force, logger): for product_name, product_info in products: # get product name, product informations and the directory where to put # the sources - if not src.product.product_is_fixed(product_info): + if (not (src.product.product_is_fixed(product_info) or + src.product.product_is_native(product_info))): source_dir = src.Path(product_info.source_dir) else: source_dir = src.Path('') @@ -352,19 +377,23 @@ def get_all_product_sources(config, products, force, logger): # Remove the existing source directory if # the product is not in development mode - is_dev = ("dev_products" in config.APPLICATION and - product_name in config.APPLICATION.dev_products) - if source_dir.exists() and not is_dev: - logger.write(" " + _('remove %s') % source_dir, 4) - logger.write("\n ", 4, False) - source_dir.rm() + is_dev = src.product.product_is_dev(product_info) + if source_dir.exists(): + logger.write('%s ' % src.printcolors.printc(src.OK_STATUS), + 3, + False) + msg = _("INFORMATION : Not doing anything because the source" + " directory already exists.\n") + logger.write(msg, 3) + good_result = good_result + 1 + # Do not get the sources and go to next product + continue # Call to the function that get the sources for one product retcode = get_product_sources(config, product_info, is_dev, source_dir, - force, logger, max_product_name_len, checkout=False) @@ -374,18 +403,23 @@ def get_all_product_sources(config, products, force, logger): if product_info.no_rpath: hack_no_rpath(config, product_info, logger) ''' + + # Check that the sources are correctly get using the files to be tested + # in product information + if retcode: + check_OK, wrong_path = check_sources(product_info, logger) + if not check_OK: + # Print the missing file path + msg = _("The required file %s does not exists. " % wrong_path) + logger.write(src.printcolors.printcError("\nERROR: ") + msg, 3) + retcode = False # show results results[product_name] = retcode - if retcode == 'N\A': - # The case where the product was not prepared because it is - # in development mode - res =(src.printcolors.printc(src.OK_STATUS) + - src.printcolors.printcWarning(_( - ' source directory already exists'))) - good_result = good_result + 1 - elif retcode: + if retcode: # The case where it succeed + + res = src.OK_STATUS good_result = good_result + 1 else: @@ -393,10 +427,36 @@ def get_all_product_sources(config, products, force, logger): res = src.KO_STATUS # print the result - logger.write('%s\n' % src.printcolors.printc(res), 3, False) + if not(src.product.product_is_fixed(product_info) or + src.product.product_is_native(product_info)): + logger.write('%s\n' % src.printcolors.printc(res), 3, False) return good_result, results +def check_sources(product_info, logger): + '''Check that the sources are correctly get, using the files to be tested + in product information + + :param product_info Config: The configuration specific to + the product to be prepared + :return: True if the files exists (or no files to test is provided). + :rtype: boolean + ''' + # Get the files to test if there is any + if ("present_files" in product_info and + "source" in product_info.present_files): + l_files_to_be_tested = product_info.present_files.source + for file_path in l_files_to_be_tested: + # The path to test is the source directory + # of the product joined the file path provided + path_to_test = os.path.join(product_info.source_dir, file_path) + logger.write(_("\nTesting existence of file: \n"), 5) + logger.write(path_to_test, 5) + if not os.path.exists(path_to_test): + return False, path_to_test + logger.write(src.printcolors.printcSuccess(" OK\n"), 5) + return True, "" + def description(): '''method that is called when salomeTools is called with --help option. @@ -404,7 +464,8 @@ def description(): :rtype: str ''' return _("The source command gets the sources of the application products " - "from cvs, git, an archive or a directory..") + "from cvs, git or an archive.\n\nexample:" + "\nsat source SALOME-master --products KERNEL,GUI") def run(args, runner, logger): '''method that is called when salomeTools is called with source parameter. @@ -418,24 +479,16 @@ def run(args, runner, logger): # Print some informations logger.write(_('Getting sources of the application %s\n') % src.printcolors.printcLabel(runner.cfg.VARS.application), 1) - src.printcolors.print_value(logger, 'out_dir', - runner.cfg.APPLICATION.out_dir, 2) + src.printcolors.print_value(logger, 'workdir', + runner.cfg.APPLICATION.workdir, 2) logger.write("\n", 2, False) - - # Get the force option if it was passed - force = options.force - if force: - msg = _("Warning: the --force option has effect only " - "on products in development mode\n\n") - logger.write(src.printcolors.printcWarning(msg)) - + # Get the products list with products informations regarding the options products_infos = prepare.get_products_list(options, runner.cfg, logger) # Call to the function that gets all the sources good_result, results = get_all_product_sources(runner.cfg, products_infos, - force, logger) # Display the results (how much passed, how much failed, etc...)