]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
add missing commentaries
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 1 Feb 2016 11:14:03 +0000 (12:14 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 1 Feb 2016 11:14:03 +0000 (12:14 +0100)
src/common/__init__.py
src/common/printcolors.py
src/config.py

index 3a597b9b12ff808c336faaf9ae0949e7f79e722e..170ed33575f4b6399eaaa3d495846ac8a2b28f38 100644 (file)
@@ -25,13 +25,21 @@ from . import options
 from . import fileSystem
 
 class SatException(Exception):
+    '''rename Exception Class
+    '''
     pass
 
 def ensure_path_exists(p):
+    '''Create a path if not existing
+    :param p str: The path.
+    '''
     if not os.path.exists(p):
         os.mkdir(p)
         
 def check_config_has_application( config, details = None ):
+    '''check that the config has the key APPLICATION. Else raise an exception.
+    :param config class 'common.config_pyconf.Config': The config.
+    '''
     if 'APPLICATION' not in config:
         message = _("An APPLICATION is required. Use 'config --list' to get the list of available applications.\n")
         if details :
index bad832a93bb550e704821e777dbc194b12a5a643..20f2d45de9cc27120590ed92641ad2f1b66381f6 100755 (executable)
@@ -41,9 +41,14 @@ __colormap__ = {
 # list of available codes
 __code_range__ = [1, 4] + list(range(30, 38)) + list(range(40, 48)) + list(range(90, 98)) + list(range(100, 108))
 
-# print a text with colors
 def printc(txt, code=''):
-    # no code means 'auto mode'
+    '''print a text with colors
+    :param txt str: The text to be printed.
+    :param code str: The color to use.
+    :return: The colored text.
+    :rtype: str
+    '''
+    # no code means 'auto mode' (works only for OK, KO, NO and ERR*)
     if code == '':
         striptxt = txt.strip().upper()
         if striptxt == "OK":
@@ -60,46 +65,98 @@ def printc(txt, code=''):
     return __colormap__[code] + txt + '\033[0m'
 
 def printcInfo(txt):
+    '''print a text info color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_INFO)
 
 def printcError(txt):
+    '''print a text error color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_ERROR)
 
 def printcWarning(txt):
+    '''print a text warning color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_WARNING)
 
 def printcHeader(txt):
+    '''print a text header color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_HEADER)
 
 def printcLabel(txt):
+    '''print a text label color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_LABEL)
 
 def printcSuccess(txt):
+    '''print a text success color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_SUCCESS)
 
 def printcHighlight(txt):
+    '''print a text highlight color
+    :param txt str: The text to be printed.
+    :return: The colored text.
+    :rtype: str
+    '''
     return printc(txt, COLOR_HIGLIGHT)
 
 def cleancolor(message):
+    '''remove color from a colored text.
+    :param message str: The text to be cleaned.
+    :return: The cleaned text.
+    :rtype: str
+    '''
     message = message.replace('\033[0m', '')
     for i in __code_range__:
         message = message.replace('\033[%dm' % i, '')
     return message
 
-# shortcut method to print a label and a value with the info color
 def print_value(logger, label, value, level=1, suffix=""):
+    '''shortcut method to print a label and a value with the info color
+    :param logger class logger: the logger instance.
+    :param label int: the label to print.
+    :param value str: the value to print.
+    :param level int: the level of verboseness.
+    :param suffix str: the suffix to add at the end.
+    '''
     if logger is None:
         print("  %s = %s %s" % (label, printcInfo(str(value)), suffix))
     else:
         logger.write("  %s = %s %s\n" % (label, printcInfo(str(value)), suffix), level)
 
 def print_color_range(start, end):
+    '''print possible range values for colors
+    :param start int: The smaller value.
+    :param end int: The bigger value.
+    '''
     for k in range(start, end+1):
         print("\033[%dm%3d\033[0m" % (k, k),)
     print
 
 # This method prints the color map
 def print_color_map():
+    '''This method prints the color map
+    '''
     print("colormap:")
     print("{")
     for k in sorted(__colormap__.keys()):
index 791e5db63d1a610aa413dcb9b65e19f3959df639..85e1579b1acf22ea01263ce3b68a774ead74fbed 100644 (file)
@@ -41,20 +41,13 @@ parser.add_option('c', 'copy', 'boolean', 'copy',
 \tWARNING the included files are not copied.
 \tIf a name is given the new config file takes the given name."""))
 
-'''
-class MergeHandler:
-    def __init__(self):
-        pass
-
-    def __call__(self, map1, map2, key):
-        if '__overwrite__' in map2 and key in map2.__overwrite__:
-            return "overwrite"
-        else:
-            return common.config_pyconf.overwriteMergeResolve(map1, map2, key)
-'''
-
 class ConfigOpener:
+    ''' Class that helps to find an application pyconf in all the possible directories (pathList)
+    '''
     def __init__(self, pathList):
+        '''Initialization
+        :param pathList list: The list of paths where to serach a pyconf.
+        '''
         self.pathList = pathList
 
     def __call__(self, name):
@@ -65,6 +58,9 @@ class ConfigOpener:
         raise IOError(_("Configuration file '%s' not found") % name)
 
     def getPath( self, name ):
+        '''The method that returns the entire path of the pyconf searched
+        :param name str: The name of the searched pyconf.
+        '''
         for path in self.pathList:
             if os.path.exists(os.path.join(path, name)):
                 return path
@@ -164,7 +160,7 @@ class ConfigManager:
     def getConfig(self, application=None, options=None, command=None, dataDir=None):
         '''get the config from all the configuration files.
         :param application str: The application for which salomeTools is called.
-        :param options TODO
+        :param options calss Options: The general salomeToosl options (--overwrite or -l5, for example)
         :param command str: The command that is called.
         :param dataDir str: The repository that contain external data for salomeTools.
         :return: The final config.
@@ -184,7 +180,8 @@ class ConfigManager:
         cfg.VARS = common.config_pyconf.Mapping(cfg)
         for variable in var:
             cfg.VARS[variable] = var[variable]
-
+        
+        # apply overwrite from command line if needed
         for rule in self.get_command_line_overrides(options, ["VARS"]):
             exec('cfg.' + rule) # this cannot be factorized because of the exec
         
@@ -197,9 +194,10 @@ class ConfigManager:
         except common.config_pyconf.ConfigError as e:
             raise common.SatException(_("Error in configuration file: salomeTools.pyconf\n  %(error)s") % \
                 {'error': str(e) })
-
+        
         merger.merge(cfg, internal_cfg)
 
+        # apply overwrite from command line if needed
         for rule in self.get_command_line_overrides(options, ["INTERNAL"]):
             exec('cfg.' + rule) # this cannot be factorized because of the exec        
         
@@ -223,6 +221,7 @@ class ConfigManager:
         
         merger.merge(cfg, site_cfg)
 
+        # apply overwrite from command line if needed
         for rule in self.get_command_line_overrides(options, ["SITE"]):
             exec('cfg.' + rule) # this cannot be factorized because of the exec
   
@@ -243,6 +242,7 @@ class ConfigManager:
 
             merger.merge(cfg, application_cfg)
 
+            # apply overwrite from command line if needed
             for rule in self.get_command_line_overrides(options, ["APPLICATION"]):
                 exec('cfg.' + rule) # this cannot be factorized because of the exec
         
@@ -252,7 +252,7 @@ class ConfigManager:
         # The directory containing the softwares definition
         softsDir = os.path.join(cfg.VARS.dataDir, 'software_pyconf')
         
-        # Loop on all files that are in softsDir directory and read its config
+        # Loop on all files that are in softsDir directory and read their config
         for fName in os.listdir(softsDir):
             if fName.endswith(".pyconf"):
                 common.config_pyconf.streamOpener = ConfigOpener([softsDir])
@@ -267,6 +267,7 @@ class ConfigManager:
                 
                 merger.merge(cfg, soft_cfg)
 
+        # apply overwrite from command line if needed
         for rule in self.get_command_line_overrides(options, ["SOFTWARE"]):
             exec('cfg.' + rule) # this cannot be factorized because of the exec
 
@@ -278,6 +279,7 @@ class ConfigManager:
         user_cfg = common.config_pyconf.Config(open(user_cfg_file))
         merger.merge(cfg, user_cfg)
 
+        # apply overwrite from command line if needed
         for rule in self.get_command_line_overrides(options, ["USER"]):
             exec('cfg.' + rule) # this cannot be factorize because of the exec
 
@@ -286,10 +288,12 @@ class ConfigManager:
     def setUserConfigFile(self, config):
         '''Set the user config file name and path.
         If necessary, build it from another one or create it from scratch.
+        :param config class 'common.config_pyconf.Config': The global config (containing all pyconf).
         '''
         if not config:
             raise common.SatException(_("Error in setUserConfigFile: config is None"))
         sat_version = config.INTERNAL.sat_version
+        # get the expected name and path of the file
         self.config_file_name = 'salomeTools-%s.pyconf'%sat_version
         self.user_config_file_path = os.path.join(config.VARS.personalDir, self.config_file_name)
         if not os.path.isfile(self.user_config_file_path):
@@ -308,6 +312,10 @@ class ConfigManager:
         '''Get a pyconf file younger than the given sat version in the given directory
         The file basename can be one of salometools-<younger version>.pyconf or salomeTools.pyconf
         Returns the file path or None if no file has been found.
+        :param userDir str: the directory that contain the user pyconf to find. (~/.salomeTools)
+        :param sat_version str: the version of salomeTools.
+        :return: the path to the already existing user pyconf.
+        :rtype: str
         '''
         file_path = None  
         # Get a younger pyconf version   
@@ -331,6 +339,11 @@ class ConfigManager:
         return file_path 
     
     def createConfigFile(self, config):
+        '''This method is called when there are no user config file. It build it from scratch.
+        :param config class 'common.config_pyconf.Config': The global config.
+        :return: the config corresponding to the file created.
+        :rtype: config class 'common.config_pyconf.Config'
+        '''
         
         cfg_name = self.getUserConfigFile()
 
@@ -364,6 +377,8 @@ class ConfigManager:
 
     def getUserConfigFile(self):
         '''Get the user config file
+        :return: path to the user config file.
+        :rtype: str
         '''
         if not self.user_config_file_path:
             raise common.SatException(_("Error in getUserConfigFile: missing user config file path"))
@@ -377,8 +392,6 @@ def print_value(config, path, show_label, level=0, show_full_path=False):
     :param show_label boolean: if True, do a basic display. (useful for bash completion)
     :param level int: The number of spaces to add before display.
     :param show_full_path :
-    :return: The final config.
-    :rtype: class 'common.config_pyconf.Config'
     '''            
     
     # display all the path or not
@@ -418,10 +431,17 @@ def print_value(config, path, show_label, level=0, show_full_path=False):
         sys.stdout.write("%s\n" % val)
 
 def description():
+    '''method that is called when salomeTools is called with --help option.
+    :return: The text to display for the config command description.
+    :rtype: str
+    '''
     return _("The config command allows manipulation and operation on config files.")
     
 
 def run(args, runner):
+    '''method that is called when salomeTools is called with config parameter.
+    '''
+    # Parse the options
     (options, args) = parser.parse_args(args)
     
     # case : print a value of the config