Salome HOME
Change 'modules' key word to 'products' and improve prepare command
[tools/sat.git] / src / product.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 '''In this file are implemented the classes and methods 
19    relative to the product notion of salomeTools
20 '''
21
22 import src
23
24 AVAILABLE_VCS = ['git', 'svn', 'cvs']
25
26 def get_product_config(config, product_name, version):
27     '''Get the specific configuration of a product from the global configuration
28     
29     :param config Config: The global configuration
30     :param product_name str: The name of the product
31     :param version str: The version of the product
32     :return: the specific configuration of the product
33     :rtype: Config
34     '''
35     vv = version
36     # substitute some character with _
37     for c in ".-": vv = vv.replace(c, "_")
38     full_product_name = product_name + '_' + vv
39
40     prod_info = None
41     # If it exists, get the information of the product_version
42     if full_product_name in config.PRODUCTS:
43         # returns specific information for the given version
44         prod_info = config.PRODUCTS[full_product_name]    
45     # Get the standard informations
46     elif product_name in config.PRODUCTS:
47         # returns the generic information (given version not found)
48         prod_info = config.PRODUCTS[product_name]
49     
50     # merge opt_depend in depend
51     if prod_info is not None and 'opt_depend' in prod_info:
52         for depend in prod_info.opt_depend:
53             if depend in config.PRODUCTS:
54                 prod_info.depend.append(depend,'')
55                 
56     # Check if the product is defined as native in the application
57     pass # to be done
58     
59     # In case of a product get with a vcs, put the tag (equal to the version)
60     if prod_info is not None and prod_info.get_source in AVAILABLE_VCS:
61         
62         if prod_info.get_source == 'git':
63             prod_info.git_info.tag = version
64         
65         if prod_info.get_source == 'svn':
66             prod_info.svn_info.tag = version
67         
68         if prod_info.get_source == 'cvs':
69             prod_info.cvs_info.tag = version
70     
71     # In case of a fixed product, define the install_dir (equal to the version)
72     if prod_info is not None and prod_info.get_source=="fixed":
73         prod_info.install_dir = version
74     
75     return prod_info
76
77 def get_products_infos(lproducts, config):
78     '''Get the specific configuration of a list of products
79     
80     :param lproducts List: The list of product names
81     :param config Config: The global configuration
82     :return: the list of tuples 
83              (product name, specific configuration of the product)
84     :rtype: [(str, Config)]
85     '''
86     products_infos = []
87     # Loop on product names
88     for prod in lproducts:
89         # Get the version of the product from the application definition
90         version_prod = config.APPLICATION.products[prod]
91         # if no version, then take the default one defined in the application
92         if isinstance(version_prod, bool): 
93             version_prod = config.APPLICATION.tag
94         
95         # Get the specific configuration of the product
96         prod_info = get_product_config(config, prod, version_prod)
97         if prod_info is not None:
98             products_infos.append((prod, prod_info))
99         else:
100             msg = _("The %s product has no definition in the configuration.") % prod
101             raise src.SatException(msg)
102     return products_infos
103
104
105 def product_is_sample(product_info):
106     '''Know if a product has the sample type
107     
108     :param product_info Config: The configuration specific to 
109                                the product
110     :return: True if the product has the sample type, else False
111     :rtype: boolean
112     '''
113     mtype = product_info.type
114     return mtype.lower() == 'sample'
115
116 def product_is_fixed(product_info):
117     '''Know if a product is fixed
118     
119     :param product_info Config: The configuration specific to 
120                                the product
121     :return: True if the product is fixed, else False
122     :rtype: boolean
123     '''
124     get_src = product_info.get_source
125     return get_src.lower() == 'fixed'