Salome HOME
correction bug introduit par 6cb6aac483a7d637f972f70e10500411e4cecfaf
[tools/sat.git] / commands / source.py
index 55b23a189f0ef5bd171825659084f9ee056a80d1..23b41d70c746ad7b28ca0f61ae7804d46b863f69 100644 (file)
 
 import os
 import shutil
+import re
 
 import src
 import prepare
+import src.debug as DBG
 
 # Define all possible option for patch command :  sat patch <options>
 parser = src.options.Options()
 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.'))
+    _('Optional: products from which to get the sources. This option accepts a comma separated list.'))
 
 def get_source_for_dev(config, product_info, source_dir, logger, pad):
     '''The method called if the product is in development mode
@@ -103,15 +104,36 @@ def get_source_from_git(product_info,
                  False)
     logger.flush()
     logger.write('\n', 5, 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, environ)
+
+    sub_dir = None
+
+    # what do we do with git tree structure and history
+    if is_dev and "sub_dir" in product_info.git_info:
+        logger.error("dev mode for product is incompatible with 'sub_dir' option")
+        return False
+
+    if not is_dev and "sub_dir" in product_info.git_info:
+        sub_dir = product_info.git_info.sub_dir
+
+    if sub_dir  is None:
+      # 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, environ)
+    else:
+      # Call the system function that do the extraction of a sub_dir in git mode
+      logger.write("sub_dir:%s " % sub_dir, 3)
+      retcode = src.system.git_extract_sub_dir(repo_git,
+                                   product_info.git_info.tag,
+                                   source_dir, sub_dir, logger, environ)
+
+
     return retcode
 
-def get_source_from_archive(product_info, source_dir, logger):
+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 
@@ -122,8 +144,17 @@ def get_source_from_archive(product_info, source_dir, logger):
     '''
     # check archive exists
     if not os.path.exists(product_info.archive_info.archive_name):
-        raise src.SatException(_("Archive not found: '%s'") % 
-                               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),
@@ -325,7 +356,7 @@ def get_product_sources(config,
                                     is_dev,env_appli)
 
     if product_info.get_source == "archive":
-        return get_source_from_archive(product_info, source_dir, logger)
+        return 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)
@@ -394,6 +425,7 @@ def get_all_product_sources(config, products, logger):
         max_product_name_len = max(map(lambda l: len(l), 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)
     for product_name, product_info in products:
         # get product name, product informations and the directory where to put
         # the sources
@@ -412,11 +444,8 @@ def get_all_product_sources(config, products, logger):
         # the product is not in development mode
         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('%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
@@ -501,6 +530,7 @@ def description():
 def run(args, runner, logger):
     '''method that is called when salomeTools is called with source parameter.
     '''
+    DBG.write("source.run()", args)
     # Parse the options
     (options, args) = parser.parse_args(args)
     
@@ -515,7 +545,7 @@ def run(args, runner, logger):
     logger.write("\n", 2, False)
        
     # Get the products list with products informations regarding the options
-    products_infos = prepare.get_products_list(options, runner.cfg, logger)
+    products_infos = src.product.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,