From c3f03fb1a8d8a5a20baef855572c2e999433ff13 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Tue, 2 Feb 2016 15:31:18 +0100 Subject: [PATCH] Remarks from sprint 1 meeting : rename some files and directories, and minor code changes --- .../softA.pyconf | 0 .../softB.pyconf | 0 doc/Makefile | 4 +- doc/src/commands/apidoc/modules.rst | 7 +++ doc/src/commands/apidoc/src.common.rst | 54 +++++++++++++++++ doc/src/commands/apidoc/src.rst | 45 ++++++++++++++ doc/{source => src}/commands/config.rst | 0 doc/{source => src}/conf.py | 0 doc/{source => src}/index.rst | 0 src/common/__init__.py | 6 +- src/common/{config_pyconf.py => pyconf.py} | 0 src/common/{fileSystem.py => system.py} | 0 src/config.py | 60 +++++++++---------- src/salomeTools.py | 8 +-- .../HTMLTestRunner.py | 0 test/{__TOOLS__ => _testTools}/tools.py | 0 .../{integration => }/create_user_pyconf.py | 6 +- test/config/{integration => }/option_copy.py | 6 +- test/config/{integration => }/option_value.py | 6 +- .../{integration => }/option_value_2.py | 6 +- test/run_all.sh | 8 +-- 21 files changed, 161 insertions(+), 55 deletions(-) rename data/{software_pyconf => softwares}/softA.pyconf (100%) rename data/{software_pyconf => softwares}/softB.pyconf (100%) create mode 100644 doc/src/commands/apidoc/modules.rst create mode 100644 doc/src/commands/apidoc/src.common.rst create mode 100644 doc/src/commands/apidoc/src.rst rename doc/{source => src}/commands/config.rst (100%) rename doc/{source => src}/conf.py (100%) rename doc/{source => src}/index.rst (100%) rename src/common/{config_pyconf.py => pyconf.py} (100%) rename src/common/{fileSystem.py => system.py} (100%) rename test/{__TOOLS__ => _testTools}/HTMLTestRunner.py (100%) rename test/{__TOOLS__ => _testTools}/tools.py (100%) rename test/config/{integration => }/create_user_pyconf.py (92%) rename test/config/{integration => }/option_copy.py (90%) rename test/config/{integration => }/option_value.py (93%) rename test/config/{integration => }/option_value_2.py (93%) diff --git a/data/software_pyconf/softA.pyconf b/data/softwares/softA.pyconf similarity index 100% rename from data/software_pyconf/softA.pyconf rename to data/softwares/softA.pyconf diff --git a/data/software_pyconf/softB.pyconf b/data/softwares/softB.pyconf similarity index 100% rename from data/software_pyconf/softB.pyconf rename to data/softwares/softB.pyconf diff --git a/doc/Makefile b/doc/Makefile index f79ee77..a514380 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -10,7 +10,7 @@ BUILDDIR = build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) src SILENT = &>/dev/null .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest @@ -139,4 +139,4 @@ doctest: "results in $(BUILDDIR)/doctest/output.txt." apidoc: - @sphinx-apidoc -o source/commands/apidoc ../src + @sphinx-apidoc -o src/commands/apidoc ../src diff --git a/doc/src/commands/apidoc/modules.rst b/doc/src/commands/apidoc/modules.rst new file mode 100644 index 0000000..e9ff8ac --- /dev/null +++ b/doc/src/commands/apidoc/modules.rst @@ -0,0 +1,7 @@ +src +=== + +.. toctree:: + :maxdepth: 4 + + src diff --git a/doc/src/commands/apidoc/src.common.rst b/doc/src/commands/apidoc/src.common.rst new file mode 100644 index 0000000..90d59ee --- /dev/null +++ b/doc/src/commands/apidoc/src.common.rst @@ -0,0 +1,54 @@ +src.common package +================== + +Submodules +---------- + +src.common.architecture module +------------------------------ + +.. automodule:: src.common.architecture + :members: + :undoc-members: + :show-inheritance: + +src.common.config_pyconf module +------------------------------- + +.. automodule:: src.common.config_pyconf + :members: + :undoc-members: + :show-inheritance: + +src.common.fileSystem module +---------------------------- + +.. automodule:: src.common.fileSystem + :members: + :undoc-members: + :show-inheritance: + +src.common.options module +------------------------- + +.. automodule:: src.common.options + :members: + :undoc-members: + :show-inheritance: + +src.common.printcolors module +----------------------------- + +.. automodule:: src.common.printcolors + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: src.common + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/src/commands/apidoc/src.rst b/doc/src/commands/apidoc/src.rst new file mode 100644 index 0000000..0c66dd5 --- /dev/null +++ b/doc/src/commands/apidoc/src.rst @@ -0,0 +1,45 @@ +src package +=========== + +Subpackages +----------- + +.. toctree:: + + src.common + +Submodules +---------- + +src.config module +----------------- + +.. automodule:: src.config + :members: + :undoc-members: + :show-inheritance: + +src.salomeTools module +---------------------- + +.. automodule:: src.salomeTools + :members: + :undoc-members: + :show-inheritance: + +src.test_command module +----------------------- + +.. automodule:: src.test_command + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: src + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/commands/config.rst b/doc/src/commands/config.rst similarity index 100% rename from doc/source/commands/config.rst rename to doc/src/commands/config.rst diff --git a/doc/source/conf.py b/doc/src/conf.py similarity index 100% rename from doc/source/conf.py rename to doc/src/conf.py diff --git a/doc/source/index.rst b/doc/src/index.rst similarity index 100% rename from doc/source/index.rst rename to doc/src/index.rst diff --git a/src/common/__init__.py b/src/common/__init__.py index bad9eb5..629fb4f 100644 --- a/src/common/__init__.py +++ b/src/common/__init__.py @@ -18,11 +18,11 @@ import os -from . import config_pyconf +from . import pyconf from . import architecture from . import printcolors from . import options -from . import fileSystem +from . import system class SatException(Exception): '''rename Exception Class @@ -40,7 +40,7 @@ def ensure_path_exists(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. + :param config class 'common.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") diff --git a/src/common/config_pyconf.py b/src/common/pyconf.py similarity index 100% rename from src/common/config_pyconf.py rename to src/common/pyconf.py diff --git a/src/common/fileSystem.py b/src/common/system.py similarity index 100% rename from src/common/fileSystem.py rename to src/common/system.py diff --git a/src/config.py b/src/config.py index 9a9bec5..5f18159 100644 --- a/src/config.py +++ b/src/config.py @@ -53,9 +53,9 @@ class ConfigOpener: def __call__(self, name): if os.path.isabs(name): - return common.config_pyconf.ConfigInputStream(open(name, 'rb')) + return common.pyconf.ConfigInputStream(open(name, 'rb')) else: - return common.config_pyconf.ConfigInputStream( open(os.path.join( self.getPath(name), name ), 'rb') ) + return common.pyconf.ConfigInputStream( open(os.path.join( self.getPath(name), name ), 'rb') ) raise IOError(_("Configuration file '%s' not found") % name) def getPath( self, name ): @@ -96,7 +96,7 @@ class ConfigManager: var['personalDir'] = os.path.join(os.path.expanduser('~'), '.salomeTools') # read linux distributions dictionary - distrib_cfg = common.config_pyconf.Config(os.path.join(var['srcDir'], 'common', 'internal_config', 'distrib.pyconf')) + distrib_cfg = common.pyconf.Config(os.path.join(var['srcDir'], 'common', 'internal_config', 'distrib.pyconf')) # set platform parameters dist_name = common.architecture.get_distribution(codes=distrib_cfg.DISTRIBUTIONS) @@ -168,20 +168,20 @@ class ConfigManager: :param command str: The command that is called. :param dataDir str: The repository that contain external data for salomeTools. :return: The final config. - :rtype: class 'common.config_pyconf.Config' + :rtype: class 'common.pyconf.Config' ''' # create a ConfigMerger to handle merge - merger = common.config_pyconf.ConfigMerger()#MergeHandler()) + merger = common.pyconf.ConfigMerger()#MergeHandler()) # create the configuration instance - cfg = common.config_pyconf.Config() + cfg = common.pyconf.Config() # ======================================================================================= # create VARS section var = self._create_vars(application=application, command=command, dataDir=dataDir) # add VARS to config - cfg.VARS = common.config_pyconf.Mapping(cfg) + cfg.VARS = common.pyconf.Mapping(cfg) for variable in var: cfg.VARS[variable] = var[variable] @@ -192,10 +192,10 @@ class ConfigManager: # ======================================================================================= # Load INTERNAL config # read src/common/internal_config/salomeTools.pyconf - common.config_pyconf.streamOpener = ConfigOpener([os.path.join(cfg.VARS.srcDir, 'common', 'internal_config')]) + common.pyconf.streamOpener = ConfigOpener([os.path.join(cfg.VARS.srcDir, 'common', 'internal_config')]) try: - internal_cfg = common.config_pyconf.Config(open(os.path.join(cfg.VARS.srcDir, 'common', 'internal_config', 'salomeTools.pyconf'))) - except common.config_pyconf.ConfigError as e: + internal_cfg = common.pyconf.Config(open(os.path.join(cfg.VARS.srcDir, 'common', 'internal_config', 'salomeTools.pyconf'))) + except common.pyconf.ConfigError as e: raise common.SatException(_("Error in configuration file: salomeTools.pyconf\n %(error)s") % \ {'error': str(e) }) @@ -208,10 +208,10 @@ class ConfigManager: # ======================================================================================= # Load SITE config file # search only in the data directory - common.config_pyconf.streamOpener = ConfigOpener([cfg.VARS.dataDir]) + common.pyconf.streamOpener = ConfigOpener([cfg.VARS.dataDir]) try: - site_cfg = common.config_pyconf.Config(open(os.path.join(cfg.VARS.dataDir, 'site.pyconf'))) - except common.config_pyconf.ConfigError as e: + site_cfg = common.pyconf.Config(open(os.path.join(cfg.VARS.dataDir, 'site.pyconf'))) + except common.pyconf.ConfigError as e: raise common.SatException(_("Error in configuration file: site.pyconf\n %(error)s") % \ {'error': str(e) }) except IOError as error: @@ -235,12 +235,12 @@ class ConfigManager: if application is not None: # search APPLICATION file in all directories in configPath cp = cfg.SITE.config.configPath - common.config_pyconf.streamOpener = ConfigOpener(cp) + common.pyconf.streamOpener = ConfigOpener(cp) try: - application_cfg = common.config_pyconf.Config(application + '.pyconf') + application_cfg = common.pyconf.Config(application + '.pyconf') except IOError as e: raise common.SatException(_("%s, use 'config --list' to get the list of available applications.") %e) - except common.config_pyconf.ConfigError as e: + except common.pyconf.ConfigError as e: raise common.SatException(_("Error in configuration file: %(application)s.pyconf\n %(error)s") % \ { 'application': application, 'error': str(e) } ) @@ -254,15 +254,15 @@ class ConfigManager: # Load softwares config files in SOFTWARE section # The directory containing the softwares definition - softsDir = os.path.join(cfg.VARS.dataDir, 'software_pyconf') + softsDir = os.path.join(cfg.VARS.dataDir, 'softwares') # 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]) + common.pyconf.streamOpener = ConfigOpener([softsDir]) try: - soft_cfg = common.config_pyconf.Config(open(os.path.join(softsDir, fName))) - except common.config_pyconf.ConfigError as e: + soft_cfg = common.pyconf.Config(open(os.path.join(softsDir, fName))) + except common.pyconf.ConfigError as e: raise common.SatException(_("Error in configuration file: %(soft)s\n %(error)s") % \ {'soft' : fName, 'error': str(e) }) except IOError as error: @@ -280,7 +280,7 @@ class ConfigManager: # load USER config self.setUserConfigFile(cfg) user_cfg_file = self.getUserConfigFile() - user_cfg = common.config_pyconf.Config(open(user_cfg_file)) + user_cfg = common.pyconf.Config(open(user_cfg_file)) merger.merge(cfg, user_cfg) # apply overwrite from command line if needed @@ -293,7 +293,7 @@ class ConfigManager: '''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). + :param config class 'common.pyconf.Config': The global config (containing all pyconf). ''' if not config: raise common.SatException(_("Error in setUserConfigFile: config is None")) @@ -347,16 +347,16 @@ class ConfigManager: 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. + :param config class 'common.pyconf.Config': The global config. :return: the config corresponding to the file created. - :rtype: config class 'common.config_pyconf.Config' + :rtype: config class 'common.pyconf.Config' ''' cfg_name = self.getUserConfigFile() - user_cfg = common.config_pyconf.Config() + user_cfg = common.pyconf.Config() # - user_cfg.addMapping('USER', common.config_pyconf.Mapping(user_cfg), "") + user_cfg.addMapping('USER', common.pyconf.Mapping(user_cfg), "") # user_cfg.USER.addMapping('workDir', os.path.expanduser('~'), @@ -395,7 +395,7 @@ class ConfigManager: def print_value(config, path, show_label, level=0, show_full_path=False): '''Prints a value from the configuration. Prints recursively the values under the initial path. - :param config class 'common.config_pyconf.Config': The configuration from which the value is displayed. + :param config class 'common.pyconf.Config': The configuration from which the value is displayed. :param path str : the path in the configuration of the value to print. :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. @@ -429,7 +429,7 @@ def print_value(config, path, show_label, level=0, show_full_path=False): if show_label: sys.stdout.write("\n") for v in sorted(val.keys()): print_value(config, path + '.' + v, show_label, level + 1) - elif val.__class__ == common.config_pyconf.Sequence or isinstance(val, list): # in this case, value is a list (or a Sequence) + elif val.__class__ == common.pyconf.Sequence or isinstance(val, list): # in this case, value is a list (or a Sequence) if show_label: sys.stdout.write("\n") index = 0 for v in val: @@ -468,13 +468,13 @@ def run(args, runner): editor = runner.cfg.USER.editor if 'APPLICATION' not in runner.cfg: # edit user pyconf usercfg = os.path.join(runner.cfg.VARS.personalDir, 'salomeTools-%s.pyconf'%runner.cfg.INTERNAL['sat_version']) - common.fileSystem.show_in_editor(editor, usercfg) + common.system.show_in_editor(editor, usercfg) else: # search for file .pyconf and open it for path in runner.cfg.SITE.config.configPath: pyconf_path = os.path.join(path, runner.cfg.VARS.application + ".pyconf") if os.path.exists(pyconf_path): - common.fileSystem.show_in_editor(editor, pyconf_path) + common.system.show_in_editor(editor, pyconf_path) break # case : copy an existing .pyconf to ~/.salomeTools/Applications/LOCAL_.pyconf diff --git a/src/salomeTools.py b/src/salomeTools.py index 8fcf244..a120254 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -47,7 +47,7 @@ def find_command_list(dirPath): ''' cmd_list = [] for item in os.listdir(dirPath): - if item.endswith('.py') and item!='salomeTools.py': + if item.endswith('.py') and item!='salomeTools.py' and item!='__init__.py': cmd_list.append(item[:-len('.py')]) return cmd_list @@ -64,7 +64,7 @@ parser.add_option('g', 'debug', 'boolean', 'debug_mode', _("run salomeTools in d class salomeTools(object): '''The main class that stores all the commands of salomeTools ''' - def __init__(self, opt, dataDir=None): + def __init__(self, opt='', dataDir=None): '''Initialization :param opt str: The sat options @@ -79,7 +79,7 @@ class salomeTools(object): # initialization of class attributes self.__dict__ = dict() - self.cfg = None # the config that will be read using config_pyconf module + self.cfg = None # the config that will be read using pyconf module self.options = options # the options passed to salomeTools self.dataDir = dataDir # default value will be /data # set the commands by calling the dedicated function @@ -115,7 +115,7 @@ class salomeTools(object): (file_, pathname, description) = imp.find_module(nameCmd, [dirPath]) module = imp.load_module(nameCmd, file_, pathname, description) - def run_command(args): + def run_command(args=''): '''The function that will load the configuration (all pyconf) and return the function run of the command corresponding to module diff --git a/test/__TOOLS__/HTMLTestRunner.py b/test/_testTools/HTMLTestRunner.py similarity index 100% rename from test/__TOOLS__/HTMLTestRunner.py rename to test/_testTools/HTMLTestRunner.py diff --git a/test/__TOOLS__/tools.py b/test/_testTools/tools.py similarity index 100% rename from test/__TOOLS__/tools.py rename to test/_testTools/tools.py diff --git a/test/config/integration/create_user_pyconf.py b/test/config/create_user_pyconf.py similarity index 92% rename from test/config/integration/create_user_pyconf.py rename to test/config/create_user_pyconf.py index 4deb1da..4b5a256 100644 --- a/test/config/integration/create_user_pyconf.py +++ b/test/config/create_user_pyconf.py @@ -23,8 +23,8 @@ import shutil # get execution path testdir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'src')) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'test', '__TOOLS__')) +sys.path.append(os.path.join(testdir, '..', '..', 'src')) +sys.path.append(os.path.join(testdir, '..', '..', 'test', '_testTools')) from salomeTools import salomeTools import HTMLTestRunner @@ -59,4 +59,4 @@ class TestConfig(unittest.TestCase): # test launch if __name__ == '__main__': - HTMLTestRunner.main() \ No newline at end of file + HTMLTestRunner.main() diff --git a/test/config/integration/option_copy.py b/test/config/option_copy.py similarity index 90% rename from test/config/integration/option_copy.py rename to test/config/option_copy.py index 1ad39c6..cd80b87 100644 --- a/test/config/integration/option_copy.py +++ b/test/config/option_copy.py @@ -23,8 +23,8 @@ import shutil # get execution path testdir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'src')) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'test', '__TOOLS__')) +sys.path.append(os.path.join(testdir, '..', '..', 'src')) +sys.path.append(os.path.join(testdir, '..', '..', 'test', '_testTools')) from salomeTools import salomeTools import HTMLTestRunner @@ -54,4 +54,4 @@ class TestConfig(unittest.TestCase): # test launch if __name__ == '__main__': - HTMLTestRunner.main() \ No newline at end of file + HTMLTestRunner.main() diff --git a/test/config/integration/option_value.py b/test/config/option_value.py similarity index 93% rename from test/config/integration/option_value.py rename to test/config/option_value.py index 821c76a..2b1d903 100644 --- a/test/config/integration/option_value.py +++ b/test/config/option_value.py @@ -22,8 +22,8 @@ import sys # get execution path testdir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'src')) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'test', '__TOOLS__')) +sys.path.append(os.path.join(testdir, '..', '..', 'src')) +sys.path.append(os.path.join(testdir, '..', '..', 'test', '_testTools')) from salomeTools import salomeTools from tools import outRedirection @@ -79,4 +79,4 @@ class TestConfig(unittest.TestCase): # test launch if __name__ == '__main__': - HTMLTestRunner.main() \ No newline at end of file + HTMLTestRunner.main() diff --git a/test/config/integration/option_value_2.py b/test/config/option_value_2.py similarity index 93% rename from test/config/integration/option_value_2.py rename to test/config/option_value_2.py index 5f43acd..ddf0528 100644 --- a/test/config/integration/option_value_2.py +++ b/test/config/option_value_2.py @@ -22,8 +22,8 @@ import sys # get execution path testdir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'src')) -sys.path.append(os.path.join(testdir, '..', '..', '..', 'test', '__TOOLS__')) +sys.path.append(os.path.join(testdir, '..', '..', 'src')) +sys.path.append(os.path.join(testdir, '..', '..', 'test', '_testTools')) from salomeTools import salomeTools from tools import outRedirection @@ -79,4 +79,4 @@ class TestConfig(unittest.TestCase): # test launch if __name__ == '__main__': - HTMLTestRunner.main() \ No newline at end of file + HTMLTestRunner.main() diff --git a/test/run_all.sh b/test/run_all.sh index ccdd9ae..84f8632 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -16,8 +16,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -coverage run --source=../src/config.py config/integration/option_value.py > test_res.html -coverage run --source=../src/config.py -a config/integration/option_value_2.py >> test_res.html -coverage run --source=../src/config.py -a config/integration/create_user_pyconf.py >> test_res.html -coverage run --source=../src/config.py -a config/integration/option_copy.py >> test_res.html +coverage run --source=../src/config.py config/option_value.py > test_res.html +coverage run --source=../src/config.py -a config/option_value_2.py >> test_res.html +coverage run --source=../src/config.py -a config/create_user_pyconf.py >> test_res.html +coverage run --source=../src/config.py -a config/option_copy.py >> test_res.html coverage html -- 2.39.2