Salome HOME
spns #40779: implement git multiserver approach: github, gitpub, tuleap
[tools/sat.git] / commands / source.py
index 0df9e67ca580efe06e126d7cca9c7efd1fde851c..7f0d8a0ead4969dfa82108b146982e21174e78bc 100644 (file)
@@ -85,24 +85,42 @@ def get_source_from_git(config,
     '''
     # The str to display
     coflag = 'git'
-
-    use_repo_dev=False
-    if ("APPLICATION" in config  and
-            "properties"  in config.APPLICATION  and
-            "repo_dev"    in config.APPLICATION.properties  and
-            config.APPLICATION.properties.repo_dev == "yes") :
-                use_repo_dev=True
-
     # Get the repository address.
     # If the application has the repo_dev property
     # Or if the product is in dev mode
     # Then we use repo_dev if the key exists
-    if (is_dev or use_repo_dev) and 'repo_dev' in product_info.git_info:
-        coflag = src.printcolors.printcHighlight(coflag.upper())
-        repo_git = product_info.git_info.repo_dev    
+    coflag = src.printcolors.printcHighlight(coflag.upper())
+    repo_git = None
+    git_server = src.get_git_server(config,logger)
+    product_file = product_info.from_file.split('/').pop()
+    if 'git_info' in  product_info and 'repositories' in product_info.git_info:
+        if git_server in product_info.git_info.repositories.keys(): # keys are git servers
+            repo_git = product_info.git_info.repositories[git_server]
+        elif 'properties' in product_info and 'is_opensource' in product_info.properties and product_info.properties.is_opensource == 'yes' :
+            for git_server in product_info.git_info.repositories.keys():
+                if git_server in config.VARS.opensource_git_servers:
+                    repo_git =  product_info.git_info.repositories[git_server]
+                    break
+        elif 'properties' in product_info and not 'is_opensource' in product_info.properties:
+            for git_server in product_info.git_info.repositories.keys():
+                if git_server in config.VARS.opensource_git_servers:
+                    repo_git =  product_info.git_info.repositories[git_server]
+                    logger.warning("Using opensource repository ({}) for product {}".format(git_server, product_info.name))
+                    logger.flush()
+                    break
+        else:
+            logger.error("Error in configuration file: define git repository for product: {} in file {}".format(product_info.name, product_file))
+            return False
+
+    elif 'repo_dev' in product_info.git_info:
+        repo_git = product_info.git_info.repo_dev
     else:
-        repo_git = product_info.git_info.repo    
-        
+        logger.error("Error in configuration file: define git repository for product: {}".format(product_info.name))
+        return False
+
+    if repo_git is None:
+        logger.error("Error in configuration file: define git repository for product: {} in file {}.".format(product_info.name, product_file))
+        return False
 
     # Display informations
     logger.write('%s:%s' % (coflag, src.printcolors.printcInfo(repo_git)), 3, 
@@ -117,8 +135,11 @@ def get_source_from_git(config,
     logger.flush()
     logger.write('\n', 5, False)
 
-    sub_dir = None
+    git_options= ''
+    if "git_options" in product_info.git_info:
+        git_options = product_info.git_info.git_options
 
+    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")
@@ -127,16 +148,16 @@ def get_source_from_git(config,
     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:
+    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,
+                                   product_info.git_info.tag, git_options,
                                    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,
+                                   product_info.git_info.tag,git_options,
                                    source_dir, sub_dir, logger, environ)
 
 
@@ -158,17 +179,9 @@ def get_source_from_archive(config, product_info, source_dir, logger):
     # 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")):
-        # download whl in local archive dir
-        pip_wheels_dir=os.path.join(config.LOCAL.archive_dir,"wheels")
-        pip_download_cmd="pip download --disable-pip-version-check --destination-directory %s --no-deps %s==%s " %\
-                         (pip_wheels_dir, product_info.name, product_info.version)
-        logger.write(pip_download_cmd, 3, False) 
-        res_pip = (subprocess.call(pip_download_cmd, 
-                                   shell=True, 
-                                   cwd=config.LOCAL.workdir,
-                                   stdout=logger.logTxtFile, 
-                                   stderr=subprocess.STDOUT) == 0)        
-        return res_pip
+        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):
@@ -381,7 +394,7 @@ def get_product_sources(config,
 
     if product_info.get_source == "git":
         return get_source_from_git(config, product_info, source_dir, logger, pad, 
-                                    is_dev,env_appli)
+                                    is_dev, env_appli)
 
     if product_info.get_source == "archive":
         return get_source_from_archive(config, product_info, source_dir, logger)
@@ -391,30 +404,32 @@ def get_product_sources(config,
     
     if product_info.get_source == "cvs":
         cvs_user = config.USER.cvs_user
-        return get_source_from_cvs(cvs_user, 
-                                    product_info, 
-                                    source_dir, 
-                                    checkout, 
-                                    logger,
-                                    pad,
-                                    env_appli)
+        return 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(svn_user, product_info, source_dir, 
-                                    checkout,
-                                    logger,
-                                    env_appli)
+                                    checkout, logger, env_appli)
 
     if product_info.get_source == "native":
-        # skip
-        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        
+        # for native products we check the corresponding system packages are installed
+        logger.write("Native : Checking system packages are installed\n" , 3)
+        check_cmd=src.system.get_pkg_check_cmd(config.VARS.dist_name) # (either rmp or apt)
+        run_pkg,build_pkg=src.product.check_system_dep(config.VARS.dist, check_cmd, product_info)
+        result=True
+        for pkg in run_pkg:
+            logger.write(" - " + pkg + " : " + run_pkg[pkg] + '\n', 1)
+            if "KO" in run_pkg[pkg]:
+                result=False
+        for pkg in build_pkg:
+            logger.write(" - " + pkg + " : " + build_pkg[pkg] + '\n', 1)
+            if "KO" in build_pkg[pkg]:
+                result=False
+        if result==False:
+            logger.error("some system dependencies are missing, please install them with "+\
+                         check_cmd[0])
+        return result        
 
     if product_info.get_source == "fixed":
         # skip
@@ -483,12 +498,8 @@ def get_all_product_sources(config, products, logger):
             continue
 
         # Call to the function that get the sources for one product
-        retcode = get_product_sources(config, 
-                                     product_info, 
-                                     is_dev, 
-                                     source_dir,
-                                     logger, 
-                                     max_product_name_len, 
+        retcode = get_product_sources(config, product_info, is_dev, 
+                                     source_dir, logger, max_product_name_len, 
                                      checkout=False)
         
         '''
@@ -579,9 +590,7 @@ def run(args, runner, 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, 
-                                                  products_infos,
-                                                  logger)
+    good_result, results = get_all_product_sources(runner.cfg, products_infos, logger)
 
     # Display the results (how much passed, how much failed, etc...)
     status = src.OK_STATUS