From 4f2f852c8c0b307b10c4f53d6622d1dd557c7d7a Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Wed, 20 Apr 2016 09:59:33 +0200 Subject: [PATCH] Modifying source command behavior as requested by CEA in 18/03/2016 meeting. The source command do not remove the directories. --- commands/clean.py | 2 +- commands/source.py | 88 +++++++++++++++----------------- data/products/PRODUCT_GIT.pyconf | 1 + src/__init__.py | 15 ++++++ src/product.py | 8 ++- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/commands/clean.py b/commands/clean.py index 4484cb0..f3570a0 100644 --- a/commands/clean.py +++ b/commands/clean.py @@ -149,7 +149,7 @@ def run(args, runner, logger): l_dir_to_suppress = [] if options.all: l_dir_to_suppress += (get_source_directories(products_infos, - options.sources_without_dev) + + options.sources_without_dev) + get_build_directories(products_infos) + get_install_directories(products_infos)) else: diff --git a/commands/source.py b/commands/source.py index c13335b..b452900 100644 --- a/commands/source.py +++ b/commands/source.py @@ -27,10 +27,8 @@ parser = src.options.Options() parser.add_option('p', 'product', 'list2', 'products', _('products from which to get the sources. This option can be' ' passed several time to get the sources of several products.')) -parser.add_option('f', 'force', 'boolean', 'force', - _("force to remove the sources before getting them (in development mode only).")) -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 @@ -38,34 +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: - # If the source path exists (it means that force option is invoked) - # remove the source path - if source_dir.exists(): - source_dir.rm() - - # 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) @@ -248,7 +235,6 @@ def get_product_sources(config, product_info, is_dev, source_dir, - force, logger, pad, checkout=False): @@ -260,7 +246,6 @@ 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 @@ -271,7 +256,6 @@ def get_product_sources(config, return get_source_for_dev(config, product_info, source_dir, - force, logger, pad) @@ -299,12 +283,22 @@ def get_product_sources(config, 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 the get_source is not in [git, archive, cvs, svn, fixed, native] @@ -314,12 +308,11 @@ def get_product_sources(config, 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) @@ -352,17 +345,22 @@ def get_all_product_sources(config, products, force, logger): # Remove the existing source directory if # the product is not in development mode is_dev = src.product.product_is_dev(product_info) - if source_dir.exists() and not is_dev: - logger.write(" " + _('remove %s') % source_dir, 4) - logger.write("\n ", 4, False) - source_dir.rm() + 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) @@ -391,7 +389,9 @@ 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 @@ -419,21 +419,13 @@ def run(args, runner, logger): 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...) diff --git a/data/products/PRODUCT_GIT.pyconf b/data/products/PRODUCT_GIT.pyconf index 4637aba..34dbdc2 100644 --- a/data/products/PRODUCT_GIT.pyconf +++ b/data/products/PRODUCT_GIT.pyconf @@ -20,5 +20,6 @@ PRODUCT_GIT : type : "sample" source_dir : $APPLICATION.workdir + $VARS.sep + 'SOURCES' + $VARS.sep + $name build_dir : $APPLICATION.workdir + $VARS.sep + 'BUILD' + $VARS.sep + $name + install_dir : "base" patches : [] } \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py index 237ccc3..8e68a1c 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -76,6 +76,21 @@ def print_info(logger, info): printcolors.print_value(logger, sp + i[0], i[1], 2) logger.write("\n", 2) +def get_base_path(config): + '''Returns the path of the product base. + + :param config Config: The global Config instance. + :return: The path of the product base. + :rtype: str + ''' + if "base" in config.APPLICATION: + base_name = config.APPLICATION.base + base_path = config.USER.bases[base_name] + else: + # default base + base_path = config.USER.bases.base + return base_path + ## # Utils class to simplify path manipulations. class Path: diff --git a/src/product.py b/src/product.py index a5c5fb1..de0e1d3 100644 --- a/src/product.py +++ b/src/product.py @@ -111,7 +111,7 @@ def get_product_config(config, product_name): raise src.SatException(msg) # If there is no definition but the product is declared as native, - # construct a new defifnition containing only the get_source key + # construct a new definition containing only the get_source key if prod_info is None and version == "native": prod_info = src.pyconf.Config() prod_info.name = product_name @@ -128,6 +128,12 @@ def get_product_config(config, product_name): prod_info.install_dir = os.path.join(config.APPLICATION.workdir, "INSTALL", prod_info.name) + else: + if prod_info.install_dir == "base": + # Get the product base of the application + base_path = src.get_base_path(config) + prod_info.install_dir = os.path.join(base_path, + prod_info.name) return prod_info -- 2.30.2