From: Christian Van Wambeke Date: Fri, 13 Apr 2018 12:25:32 +0000 (+0200) Subject: fix apidoc sphinx ERROR: Unexpected indentation X-Git-Tag: 5.1.0~39^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=773921a7f074f95a39e748f0b7bfdf0e071edab7;p=tools%2Fsat.git fix apidoc sphinx ERROR: Unexpected indentation --- diff --git a/doc/src/Makefile_tmp b/doc/src/Makefile_tmp new file mode 100644 index 0000000..cdd6fff --- /dev/null +++ b/doc/src/Makefile_tmp @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +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 +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/toto.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/toto.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/toto" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/toto" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/doc/src/commands/application.rst b/doc/src/commands/application.rst index f753b39..65878c8 100644 --- a/doc/src/commands/application.rst +++ b/doc/src/commands/application.rst @@ -42,7 +42,8 @@ Some useful configuration pathes ================================= The virtual application can be configured with the virtual_app section of the configutation file. -* APPLICATION.virtual_app + +* **APPLICATION.virtual_app** * **name**: name of the launcher (to replace the default runAppli). * **application_name**: (optional) the name of the virtual application directory. diff --git a/doc/src/commands/launcher.rst b/doc/src/commands/launcher.rst index 93468f9..5c5da14 100644 --- a/doc/src/commands/launcher.rst +++ b/doc/src/commands/launcher.rst @@ -37,7 +37,7 @@ Usage Some useful configuration pathes ================================= -* APPLICATION.profile +* **APPLICATION.profile** * **product**: the name of the profile product (the product in charge of holding the application stuff, like logos, splashscreen) * **launcher_name**: the name of the launcher. diff --git a/doc/src/commands/prepare.rst b/doc/src/commands/prepare.rst index 55755dc..7fc79d5 100644 --- a/doc/src/commands/prepare.rst +++ b/doc/src/commands/prepare.rst @@ -4,12 +4,15 @@ Command prepare Description =========== -The **prepare** command brings the sources of an application in the SOURCES application directory, in order to compile them with the compile command. +The **prepare** command brings the sources of an application in the SOURCES +application directory, in order to compile them with the compile command. The sources can be prepared from VCS software (*cvs*,*svn*, *git*), an archive or a directory. -.. warning:: When sat prepares a product, it first removes the existing directory, except if the developement mode is activated. - When you are working on a product,, you need to declare in the application configuration this product in **dev** mode. +.. warning:: When sat prepares a product, it first removes the + existing directory, except if the development mode is activated. + When you are working on a product, you need to declare in + the application configuration this product in **dev** mode. Remarks ======= @@ -20,25 +23,36 @@ VCS bases (git, svn, cvs) The *prepare* command does not manage authentication on the cvs server. For example, to prepare modules from a cvs server, you first need to login once. -To avoid typing a password for each product, you may use a ssh key with passphrase, or store your password (in .cvspass or .gitconfig). -If you have security concerns, it is also possible to use a bash agent and type your password only once. +To avoid typing a password for each product, +you may use a ssh key with passphrase, or store your password +(in .cvspass or .gitconfig). +If you have security concerns, it is also possible to use +a bash agent and type your password only once. Dev mode -------- -By default *prepare* uses *export* mode: it creates an image of the sources, corresponding to the tag or branch specified, without any link to the VCS base. -To perform a *checkout* (svn, cvs) or a *git clone* (git), you need to declare the product in dev mode in your application configuration. +By default *prepare* uses *export* mode: it creates an image +of the sources, corresponding to the tag or branch specified, +without any link to the VCS base. +To perform a *checkout* (svn, cvs) or a *git clone* (git), +you need to declare the product in dev mode in your application configuration. For that, edit the application configuration and modify the product declaration: :: sat config -e # edit the product section : - : {tag : "my_tag", dev : "yes", debug : "yes"} + # : {tag : "my_tag", dev : "yes", debug : "yes"} -The first time you will execute the *sat prepare* command, your module will be downloaded in *checkout* mode (inside the SOURCES directory of the application. -Then, you can develop in this repository. And push them in the base when they are ready. -If you type during the development process by mistake a *sat prepare* command, the sources in dev mode will not be altered/removed (Unless you use -f option) +The first time you will execute the *sat prepare* command, +your module will be downloaded in *checkout* mode +(inside the SOURCES directory of the application. +Then, you can develop in this repository, and finally push +them in the base when they are ready. +If you type during the development process by mistake +a *sat prepare* command, the sources in dev mode will +not be altered/removed (Unless you use -f option) Usage @@ -51,11 +65,13 @@ Usage sat prepare --products , ... -* Use --force to force to prepare the products in development mode (this will remove the sources and do a new clone/checkout): :: +* Use --force to force to prepare the products in development mode + (this will remove the sources and do a new clone/checkout): :: sat prepare --force -* Use --force_patch to force to apply patch to the products in development mode (otherwise they are not applied): :: +* Use --force_patch to force to apply patch to the products + in development mode (otherwise they are not applied): :: sat prepare --force_patch @@ -63,11 +79,11 @@ Usage Some useful configuration pathes ================================= -* sat prepare uses the pyconf configuration of each product to know how to get the sources. +Command *sat prepare* uses the file pyconf configuration of each product to know how to get the sources. - * **get_method**: the method to use to prepare the module, possible values are cvs, git, archive, dir. - * **git_info**: (used if get_method = git) information to prepare sources from git. - * **svn_info**: (used if get_method = svn) information to prepare sources from cvs. - * **cvs_info**: (used if get_method = cvs) information to prepare sources from cvs. - * **archive_info**: (used if get_method = archive) the path to the archive. - * **dir_info**: (used if get_method = dir) the directory with the sources. +* **get_method**: the method to use to prepare the module, possible values are cvs, git, archive, dir. +* **git_info**: (used if get_method = git) information to prepare sources from git. +* **svn_info**: (used if get_method = svn) information to prepare sources from cvs. +* **cvs_info**: (used if get_method = cvs) information to prepare sources from cvs. +* **archive_info**: (used if get_method = archive) the path to the archive. +* **dir_info**: (used if get_method = dir) the directory with the sources. diff --git a/doc/src/conf.py b/doc/src/conf.py index 14da019..320a7a5 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# salomeTools documentation build configuration file, created by -# sphinx-quickstart on Wed Sep 14 11:55:14 2011. +# sat documentation build configuration file, created by +# sphinx-quickstart on Fri Apr 13 10:08:59 2018. # # This file is execfile()d with the current directory set to its containing dir. # @@ -26,7 +26,7 @@ import os # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.mathjax', 'sphinx.ext.viewcode'] # do not use rst_prolog please use doc/rst_prolog.rst and '.. include:: ../rst_prolog.rst' # https://github.com/sphinx-doc/sphinx/issues/2445 @@ -45,7 +45,7 @@ master_doc = 'index' # General information about the project. project = u'salomeTools' -copyright = u'2010-2018, CEA' +copyright = u'2018, CEA' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -96,7 +96,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # default sphinxdoc scrolls agogo traditional nature haiku -html_theme = 'alabaster' +html_theme = 'alabaster' #added in _theme dir # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -174,8 +174,20 @@ htmlhelp_basename = 'salomeToolsdoc' # -- Options for LaTeX output -------------------------------------------------- +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + 'papersize': 'a4paper', + + # The font size ('10pt', '11pt' or '12pt'). + 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + #'preamble': '', +} + + # The paper size ('letter' or 'a4'). -latex_paper_size = 'a4' +#latex_paper_size = 'a4' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' @@ -184,7 +196,7 @@ latex_paper_size = 'a4' # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'salomeTools.tex', u'salomeTools Documentation', - u'CEA', 'manual'), + u'CEA DEN/DANS/DM2S/STMF/LGLS', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -199,7 +211,7 @@ latex_documents = [ #latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +latex_show_urls = True # Additional stuff for the LaTeX preamble. #latex_preamble = '' @@ -217,8 +229,10 @@ latex_documents = [ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'salometools', u'salomeTools Documentation', - [u'CEA'], 1) + [u'CEA DEN/DANS/DM2S/STMF/LGLS'], 1) ] # Append source folder to path in order to enable autodoc -sys.path.append(os.path.join('..')) +currentPath = os.path.dirname(__file__) +print "file conf.py currentPath", currentPath +sys.path.append(os.path.join(currentPath, '..', '..')) diff --git a/doc/src/write_command.rst b/doc/src/write_command.rst index adad305..652fbbe 100644 --- a/doc/src/write_command.rst +++ b/doc/src/write_command.rst @@ -65,85 +65,86 @@ But there are some useful services provided by salomeTools : (options, args) = parser.parse_args(args) # algorithm -How to access to salomeTools config and other commands ? +HowTo access salomeTools config and other commands ======================================================== -The runner variable is an instance of the Sat class. It gives access to cfg : the data model that is read from all configuration files of salomeTools (*.pyconf) For example, runner.cfg.APPLICATION.out_dir will contain the root directory of the application on which you are working. +The *runner* variable is an python instance of *Sat* class. +It gives access to *runner.cfg* : the data model that is read from all +configuration files of salomeTools (*.pyconf) +For example, *runner.cfg.APPLICATION.workdir* will +contain the root directory of the application on which you are working. -It gives also access to all other commands of salomeTools : +The *runner* variable gives also access to other commands of salomeTools: .. code-block:: python runner.prepare(runner.cfg.VARS.application) -How to log ? -============ +HowTo logger +============== -The logger variable is an instance of the Logger class. It gives access to the write method. +The logger variable is an instance of the Logger class. +It gives access to the write method. -When this method is called, the message passed as parameter will be displayed in the termnial and written in an xml log file. +When this method is called, the message passed as parameter +will be displayed in the terminal and written in an xml log file. .. code-block:: python logger.write("My message", 3) -The second argument defines the level of verbosity that is wanted for this message. It has to be between 1 and 5 (the most verbose level). +The second argument defines the level of verbosity +that is wanted for this message. +It has to be between 1 and 5 (the most verbose level). -HELLO WORLD ! -============= +HELLO example +============== -Here is a hello world command : +Here is a 'hello' command, file *commands/hello.py*: .. code-block:: python import src - # Define all possible option for mycommand command : sat mycommand + """ + hello.py + Define all possible options for hello command: + sat hello + """ parser = src.options.Options() - parser.add_option('m', 'myoption', 'boolean', 'myoption', "My option changes the behavior of my command.") + parser.add_option('f', 'french', 'boolean', 'french', "french set hello message in french.") def description(): - return _("The help of mycommand.") + return _("The help of hello.") def run(args, runner, logger): # Parse the options (options, args) = parser.parse_args(args) # algorithm - if options.myoption: - logger.write('HELLO, WORLD !\n') + if not options.french: + logger.write('HELLO! WORLD!\n') else: - logger.write('WORLD, HELLO !\n') + logger.write('Bonjour tout le monde!\n') -A first call of mycommand: +A first call of hello: .. code-block:: bash - >./sat mycommand --myoption - HELLO, WORLD ! - - Tap the following command to get the log : - /path/to/salomeTools/sat log - -Another call of mycommand: - -.. code-block:: bash + # Get the help of hello: + ./sat --help hello - >./sat mycommand - WORLD, HELLO ! + # To get bonjour + ./sat hello -f + Bonjour tout le monde! + + # To get hello + ./sat hello + HELLO! WORLD! - Tap the following command to get the log : - /path/to/salomeTools/sat log - -Get the help of mycommand: + # To get the log + ./sat log -.. code-block:: bash - >./sat --help mycommand - Version: 5.0.0dev - Description: - The help of mycommand. + - Available options are: - -m, --myoption (boolean) - My option changes the behavior of my command. diff --git a/src/__init__.py b/src/__init__.py index 13e8a18..bd224be 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -16,6 +16,11 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +"""\ +initial imports and utilities methods for salomeTools +""" + import os import shutil import errno @@ -49,23 +54,22 @@ TIMEOUT_STATUS = "TIMEOUT" CONFIG_FILENAME = "sat-config.pyconf" class SatException(Exception): - '''rename Exception Class - ''' + """rename Exception Class""" pass def ensure_path_exists(p): - '''Create a path if not existing + """Create a path if not existing :param p str: The path. - ''' + """ if not os.path.exists(p): os.makedirs(p) def check_config_has_application( config, details = None ): - '''check that the config has the key APPLICATION. Else raise an exception. + """check that the config has the key APPLICATION. Else raise an exception. :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") @@ -74,11 +78,12 @@ def check_config_has_application( config, details = None ): raise SatException( message ) def check_config_has_profile( config, details = None ): - '''check that the config has the key APPLICATION.profile. - Else, raise an exception. + """\ + check that the config has the key APPLICATION.profile. + else, raise an exception. :param config class 'common.pyconf.Config': The config. - ''' + """ check_config_has_application(config) if 'profile' not in config.APPLICATION: message = _("A profile section is required in your application.\n") @@ -90,26 +95,29 @@ def config_has_application( config ): return 'APPLICATION' in config def get_cfg_param(config, param_name, default): - '''Search for param_name value in config. - If param_name is not in config, then return default, - else, return the found value + """\ + eearch for param_name value in config. + if param_name is not in config + then return default, + else return the found value :param config class 'common.pyconf.Config': The config. :param param_name str: the name of the parameter to get the value :param default str: The value to return if param_name is not in config :return: see initial description of the function :rtype: str - ''' + """ if param_name in config: return config[param_name] return default def print_info(logger, info): - '''Prints the tuples that are in info variable in a formatted way. + """\ + Prints the tuples that are in info variable in a formatted way. :param logger Logger: The logging instance to use for the prints. :param info list: The list of tuples to display - ''' + """ # find the maximum length of the first value of the tuples in info smax = max(map(lambda l: len(l[0]), info)) # Print each item of info with good indentation @@ -119,12 +127,13 @@ def print_info(logger, info): logger.write("\n", 2) def get_base_path(config): - '''Returns the path of the products base. + """\ + Returns the path of the products base. :param config Config: The global Config instance. :return: The path of the products base. :rtype: str - ''' + """ if "base" not in config.LOCAL: local_file_path = os.path.join(config.VARS.salometoolsway, "data", @@ -137,12 +146,13 @@ def get_base_path(config): return base_path def get_launcher_name(config): - '''Returns the name of salome launcher. + """\ + Returns the name of salome launcher. :param config Config: The global Config instance. :return: The name of salome launcher. :rtype: str - ''' + """ check_config_has_application(config) if 'profile' in config.APPLICATION and 'launcher_name' in config.APPLICATION.profile: launcher_name = config.APPLICATION.profile.launcher_name @@ -152,12 +162,13 @@ def get_launcher_name(config): return launcher_name def get_log_path(config): - '''Returns the path of the logs. + """\ + Returns the path of the logs. :param config Config: The global Config instance. :return: The path of the logs. :rtype: str - ''' + """ if "log_dir" not in config.LOCAL: local_file_path = os.path.join(config.VARS.salometoolsway, "data", @@ -320,11 +331,15 @@ class Path: return False def find_file_in_lpath(file_name, lpath, additional_dir = ""): - """Find in all the directories in lpath list the file that has the same name - as file_name. If it is found, return the full path of the file, else, - return False. - The additional_dir (optional) is the name of the directory to add to all - paths in lpath. + """\ + Find in all the directories in lpath list the file that has the same name + as file_name. + If it is found + then return the full path of the file + else return False. + + The additional_dir (optional) is the name of the directory to add to all + paths in lpath. :param file_name str: The file name to search :param lpath List: The list of directories where to search @@ -351,7 +366,8 @@ def handleRemoveReadonly(func, path, exc): raise def deepcopy_list(input_list): - """ Do a deep copy of a list + """\ + Do a deep copy of a list :param input_list List: The list to copy :return: The copy of the list @@ -363,7 +379,8 @@ def deepcopy_list(input_list): return res def remove_item_from_list(input_list, item): - """ Remove all occurences of item from input_list + """\ + Remove all occurences of item from input_list :param input_list List: The list to modify :return: The without any item @@ -377,7 +394,8 @@ def remove_item_from_list(input_list, item): return res def parse_date(date): - """Transform YYYYMMDD_hhmmss into YYYY-MM-DD hh:mm:ss. + """\ + Transform YYYYMMDD_hhmmss into YYYY-MM-DD hh:mm:ss. :param date str: The date to transform :return: The date in the new format @@ -394,18 +412,17 @@ def parse_date(date): return res def merge_dicts(*dict_args): - ''' + """\ Given any number of dicts, shallow copy and merge into a new dict, precedence goes to key value pairs in latter dicts. - ''' + """ result = {} for dictionary in dict_args: result.update(dictionary) return result def replace_in_file(filein, strin, strout): - '''Replace by in file - ''' + """Replace by in file """ shutil.move(filein, filein + "_old") fileout= filein filein = filein + "_old" diff --git a/src/debug.py b/src/debug.py index e1ab251..e2cb47f 100644 --- a/src/debug.py +++ b/src/debug.py @@ -17,8 +17,9 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -""" +"""\ This file assume DEBUG functionalities use + - print debug messages in sys.stderr for salomeTools - show pretty print debug representation from instances of SAT classes (pretty print src.pyconf.Config), and python dict/list etc. (as 'aVariable') @@ -71,7 +72,7 @@ def write(title, var="", force=None, fmt="\n#### DEBUG: %s:\n%s\n"): return def tofix(title, var="", force=None): - """ + """\ write sys.stderr a message if _debug[-1]==True or optionaly force=True use this only if no logger accessible for classic logger.warning(message) or logger.debug(message) @@ -122,15 +123,16 @@ def saveConfigStd(config, aStream): config.__save__(aStream, indent) def getStrConfigStd(config): - """set string as saveConfigStd, - as file .pyconf""" + """set string as saveConfigStd, as file .pyconf""" outStream = OutStream() saveConfigStd(config, outStream) return outStream.value def getStrConfigDbg(config): - """set string as saveConfigDbg, - as (path expression evaluation) for debug""" + """\ + set string as saveConfigDbg, + as (path expression evaluation) for debug + """ outStream = OutStream() saveConfigDbg(config, outStream) return outStream.value diff --git a/src/environment.py b/src/environment.py index 650efe5..2198e27 100644 --- a/src/environment.py +++ b/src/environment.py @@ -26,31 +26,32 @@ import src.debug as DBG import pprint as PP class Environ: - '''Class to manage the environment context - ''' + """\ + Class to manage the environment context + """ def __init__(self, environ=None): - '''Initialization. If the environ argument is passed, the environment + """Initialization. If the environ argument is passed, the environment will be add to it, else it is the external environment. :param environ dict: - ''' + """ if environ is not None: self.environ = environ else: self.environ = os.environ def __repr__(self): - """easy non exhaustive quick resume for debug print - """ + """easy non exhaustive quick resume for debug print""" return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(self.environ)) def _expandvars(self, value): - '''replace some $VARIABLE into its actual value in the environment + """\ + replace some $VARIABLE into its actual value in the environment :param value str: the string to be replaced :return: the replaced variable :rtype: str - ''' + """ if "$" in value: # The string.Template class is a string class # for supporting $-substitutions @@ -63,12 +64,13 @@ class Environ: return value def append_value(self, key, value, sep=os.pathsep): - '''append value to key using sep + """\ + append value to key using sep :param key str: the environment variable to append :param value str: the value to append to key :param sep str: the separator string - ''' + """ # check if the key is already in the environment if key in self.environ: value_list = self.environ[key].split(sep) @@ -82,12 +84,13 @@ class Environ: self.set(key, value) def append(self, key, value, sep=os.pathsep): - '''Same as append_value but the value argument can be a list + """\ + Same as append_value but the value argument can be a list :param key str: the environment variable to append :param value str or list: the value(s) to append to key :param sep str: the separator string - ''' + """ if isinstance(value, list): for v in value: self.append_value(key, v, sep) @@ -95,12 +98,13 @@ class Environ: self.append_value(key, value, sep) def prepend_value(self, key, value, sep=os.pathsep): - '''prepend value to key using sep + """\ + prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key :param sep str: the separator string - ''' + """ if key in self.environ: value_list = self.environ[key].split(sep) if not value in value_list: @@ -112,12 +116,13 @@ class Environ: self.set(key, value) def prepend(self, key, value, sep=os.pathsep): - '''Same as prepend_value but the value argument can be a list + """\ + Same as prepend_value but the value argument can be a list :param key str: the environment variable to prepend :param value str or list: the value(s) to prepend to key :param sep str: the separator string - ''' + """ if isinstance(value, list): for v in value: self.prepend_value(key, v, sep) @@ -125,37 +130,41 @@ class Environ: self.prepend_value(key, value, sep) def is_defined(self, key): - '''Check if the key exists in the environment + """\ + Check if the key exists in the environment :param key str: the environment variable to check - ''' + """ return key in self.environ.keys() def set(self, key, value): - '''Set the environment variable "key" to value "value" + """\ + Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ self.environ[key] = self._expandvars(value) def get(self, key): - '''Get the value of the environment variable "key" + """\ + Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ if key in self.environ: return self.environ[key] else: return "" def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key + """\ + Get the value given by the system command "command" + and put it in the environment variable key :param key str: the environment variable :param command str: the command to execute - ''' + """ value = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, @@ -164,16 +173,17 @@ class Environ: class SalomeEnviron: - """Class to manage the environment of SALOME. + """\ + Class to manage the environment of SALOME. """ - def __init__(self, cfg, environ, forBuild=False, for_package=None, enable_simple_env_script = True): - '''Initialization. + """\ + Initialization. :param cfg Config: the global config :param environ Environ: the Environ instance where @@ -182,7 +192,7 @@ class SalomeEnviron: else a build one :param for_package str: If not None, produce a relative environment designed for a package. - ''' + """ self.environ = environ self.cfg = cfg self.forBuild = forBuild @@ -200,43 +210,48 @@ class SalomeEnviron: return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res)) def append(self, key, value, sep=os.pathsep): - '''append value to key using sep + """\ + append value to key using sep :param key str: the environment variable to append :param value str: the value to append to key :param sep str: the separator string - ''' + """ return self.environ.append(key, value, sep) def prepend(self, key, value, sep=os.pathsep): - '''prepend value to key using sep + """\ + prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key :param sep str: the separator string - ''' + """ return self.environ.prepend(key, value, sep) def is_defined(self, key): - '''Check if the key exists in the environment + """\ + Check if the key exists in the environment :param key str: the environment variable to check - ''' + """ return self.environ.is_defined(key) def get(self, key): - '''Get the value of the environment variable "key" + """\ + Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ return self.environ.get(key) def set(self, key, value): - '''Set the environment variable "key" to value "value" + """\ + Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ # check if value needs to be evaluated if value is not None and value.startswith("`") and value.endswith("`"): res = subprocess.Popen("echo %s" % value, @@ -247,7 +262,8 @@ class SalomeEnviron: return self.environ.set(key, value) def dump(self, out): - """Write the environment to out + """\ + Write the environment to out :param out file: the stream where to write the environment """ @@ -259,7 +275,8 @@ class SalomeEnviron: out.write("%s=%s\n" % (k, value)) def add_line(self, nb_line): - """Add empty lines to the out stream (in case of file generation) + """\ + Add empty lines to the out stream (in case of file generation) :param nb_line int: the number of empty lines to add """ @@ -267,7 +284,8 @@ class SalomeEnviron: self.environ.add_line(nb_line) def add_comment(self, comment): - """Add a commentary to the out stream (in case of file generation) + """\ + Add a commentary to the out stream (in case of file generation) :param comment str: the commentary to add """ @@ -275,7 +293,8 @@ class SalomeEnviron: self.environ.add_comment(comment) def add_warning(self, warning): - """Add a warning to the out stream (in case of file generation) + """\ + Add a warning to the out stream (in case of file generation) :param warning str: the warning to add """ @@ -283,7 +302,8 @@ class SalomeEnviron: self.environ.add_warning(warning) def finish(self, required): - """Add a final instruction in the out file (in case of file generation) + """\ + Add a final instruction in the out file (in case of file generation) :param required bool: Do nothing if required is False """ @@ -293,8 +313,7 @@ class SalomeEnviron: self.environ.finish(required) def set_python_libdirs(self): - """Set some generic variables for python library paths - """ + """Set some generic variables for python library paths""" ver = self.get('PYTHON_VERSION') self.set('PYTHON_LIBDIR0', os.path.join('lib', 'python' + ver, @@ -307,10 +326,11 @@ class SalomeEnviron: self.python_lib1 = self.get('PYTHON_LIBDIR1') def get_names(self, lProducts): - """Get the products name to add in SALOME_MODULES environment variable - It is the name of the product, except in the case where the is a - component name. And it has to be in SALOME_MODULES variable only - if the product has the property has_salome_hui = "yes" + """\ + Get the products name to add in SALOME_MODULES environment variable + It is the name of the product, except in the case where the is a + component name. And it has to be in SALOME_MODULES variable only + if the product has the property has_salome_hui = "yes" :param lProducts list: List of products to potentially add """ @@ -330,7 +350,8 @@ class SalomeEnviron: return lProdName def set_application_env(self, logger): - """Sets the environment defined in the APPLICATION file. + """\ + Sets the environment defined in the APPLICATION file. :param logger Logger: The logger instance to display messages """ @@ -365,8 +386,9 @@ class SalomeEnviron: self.add_line(1) def set_salome_minimal_product_env(self, product_info, logger): - """Sets the minimal environment for a SALOME product. - xxx_ROOT_DIR and xxx_SRC_DIR + """\ + Sets the minimal environment for a SALOME product. + xxx_ROOT_DIR and xxx_SRC_DIR :param product_info Config: The product description :param logger Logger: The logger instance to display messages @@ -396,7 +418,8 @@ class SalomeEnviron: product_info.name)) def set_salome_generic_product_env(self, pi): - """Sets the generic environment for a SALOME product. + """\ + Sets the generic environment for a SALOME product. :param pi Config: The product description """ @@ -443,7 +466,8 @@ class SalomeEnviron: self.prepend('PYTHONPATH', l) def set_cpp_env(self, product_info): - """Sets the generic environment for a SALOME cpp product. + """\ + Sets the generic environment for a SALOME cpp product. :param product_info Config: The product description """ @@ -472,7 +496,8 @@ class SalomeEnviron: self.prepend('PYTHONPATH', l) def load_cfg_environment(self, cfg_env): - """Loads environment defined in cfg_env + """\ + Loads environment defined in cfg_env :param cfg_env Config: A config containing an environment """ @@ -513,7 +538,8 @@ class SalomeEnviron: self.set(env_def, val) def set_a_product(self, product, logger): - """Sets the environment of a product. + """\ + Sets the environment of a product. :param product str: The product name :param logger Logger: The logger instance to display messages @@ -591,7 +617,8 @@ class SalomeEnviron: def run_env_script(self, product_info, logger=None, native=False): - """Runs an environment script. + """\ + Runs an environment script. :param product_info Config: The product description :param logger Logger: The logger instance to display messages @@ -626,8 +653,9 @@ class SalomeEnviron: traceback.print_exc() def run_simple_env_script(self, script_path, logger=None): - """Runs an environment script. Same as run_env_script, but with a - script path as parameter. + """\ + Runs an environment script. Same as run_env_script, but with a + script path as parameter. :param script_path str: a path to an environment script :param logger Logger: The logger instance to display messages @@ -660,7 +688,8 @@ class SalomeEnviron: traceback.print_exc() def set_products(self, logger, src_root=None): - """Sets the environment for all the products. + """\ + Sets the environment for all the products. :param logger Logger: The logger instance to display messages :param src_root src: the application working directory @@ -681,8 +710,9 @@ class SalomeEnviron: self.finish(False) def set_full_environ(self, logger, env_info): - """Sets the full environment for products - specified in env_info dictionary. + """\ + Sets the full environment for products + specified in env_info dictionary. :param logger Logger: The logger instance to display messages :param env_info list: the list of products @@ -699,17 +729,19 @@ class SalomeEnviron: self.set_a_product(product, logger) class FileEnvWriter: - """Class to dump the environment to a file. + """\ + Class to dump the environment to a file. """ def __init__(self, config, logger, out_dir, src_root, env_info=None): - '''Initialization. + """\ + Initialization. :param cfg Config: the global config :param logger Logger: The logger instance to display messages :param out_dir str: The directory path where t put the output files :param src_root str: The application working directory :param env_info str: The list of products to add in the files. - ''' + """ self.config = config self.logger = logger self.out_dir = out_dir @@ -718,7 +750,8 @@ class FileEnvWriter: self.env_info = env_info def write_env_file(self, filename, forBuild, shell, for_package = None): - """Create an environment file. + """\ + Create an environment file. :param filename str: the file path :param forBuild bool: if true, the build environment @@ -764,8 +797,9 @@ class FileEnvWriter: additional_env = {}, for_package = None, with_commercial = True): - """Append to current opened aFile a cfgForPy - environment (SALOME python launcher). + """\ + Append to current opened aFile a cfgForPy + environment (SALOME python launcher). :param filename str: the file path :param additional_env dict: a dictionary of additional variables @@ -812,19 +846,22 @@ class FileEnvWriter: env.finish(True) class Shell: - """Definition of a Shell. + """\ + Definition of a Shell. """ def __init__(self, name, extension): - '''Initialization. + """\ + Initialization. :param name str: the shell name :param extension str: the shell extension - ''' + """ self.name = name self.extension = extension def load_environment(config, build, logger): - """Loads the environment (used to run the tests, for example). + """\ + Loads the environment (used to run the tests, for example). :param config Config: the global config :param build bool: build environement if True diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 8ff7a2f..44963f5 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -20,7 +20,8 @@ import os import pprint as PP import src.debug as DBG -bat_header="""@echo off +bat_header="""\ +@echo off rem The following variables are used only in case of a sat package set out_dir_Path=%~dp0 @@ -30,7 +31,8 @@ set prereq_build_Path=%out_dir_Path%\PREREQUISITES\BUILD """ -bash_header="""#!/bin/bash +bash_header="""\ +#!/bin/bash ########################################################################## # #### cleandup ### @@ -76,11 +78,13 @@ export PRODUCT_ROOT_DIR=${PRODUCT_OUT_DIR} ########################################################################### """ -cfg_header='''[SALOME Configuration] -''' +cfg_header="""\ +[SALOME Configuration] +""" -Launcher_header='''# a generated SALOME Configuration file using python syntax -''' +Launcher_header="""\ +# a generated SALOME Configuration file using python syntax +""" def get_file_environ(output, shell, environ=None): """Instantiate correct FileEnvironment sub-class. @@ -100,10 +104,12 @@ def get_file_environ(output, shell, environ=None): raise Exception("FileEnviron: Unknown shell = %s" % shell) class FileEnviron(object): - """Base class for shell environment + """\ + Base class for shell environment """ def __init__(self, output, environ=None): - """Initialization + """\ + Initialization :param output file: the output file stream. :param environ dict: a potential additional environment. @@ -111,7 +117,8 @@ class FileEnviron(object): self._do_init(output, environ) def __repr__(self): - """easy non exhaustive quick resume for debug print""" + """\ + easy non exhaustive quick resume for debug print""" res = { "output" : self.output, "environ" : self.environ, @@ -120,7 +127,8 @@ class FileEnviron(object): def _do_init(self, output, environ=None): - """Initialization + """\ + Initialization :param output file: the output file stream. :param environ dict: a potential additional environment. @@ -137,110 +145,122 @@ class FileEnviron(object): self.environ = dict(os.environ) #make a copy cvw 180320 def add_line(self, number): - """Add some empty lines in the shell file + """\ + Add some empty lines in the shell file :param number int: the number of lines to add """ self.output.write("\n" * number) def add_comment(self, comment): - """Add a comment in the shell file + """\ + Add a comment in the shell file :param comment str: the comment to add """ self.output.write("# %s\n" % comment) def add_echo(self, text): - """Add a "echo" in the shell file + """\ + Add a "echo" in the shell file :param text str: the text to echo """ self.output.write('echo %s"\n' % text) def add_warning(self, warning): - """Add a warning "echo" in the shell file + """\ + Add a warning "echo" in the shell file :param warning str: the text to echo """ self.output.write('echo "WARNING %s"\n' % warning) def append_value(self, key, value, sep=os.pathsep): - '''append value to key using sep + """\ + append value to key using sep :param key str: the environment variable to append :param value str: the value to append to key :param sep str: the separator string - ''' + """ self.set(key, self.get(key) + sep + value) if (key, sep) not in self.toclean: self.toclean.append((key, sep)) def append(self, key, value, sep=os.pathsep): - '''Same as append_value but the value argument can be a list + """\ + Same as append_value but the value argument can be a list :param key str: the environment variable to append :param value str or list: the value(s) to append to key :param sep str: the separator string - ''' + """ if isinstance(value, list): self.append_value(key, sep.join(value), sep) else: self.append_value(key, value, sep) def prepend_value(self, key, value, sep=os.pathsep): - '''prepend value to key using sep + """\ + prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key :param sep str: the separator string - ''' + """ self.set(key, value + sep + self.get(key)) if (key, sep) not in self.toclean: self.toclean.append((key, sep)) def prepend(self, key, value, sep=os.pathsep): - '''Same as prepend_value but the value argument can be a list + """\ + Same as prepend_value but the value argument can be a list :param key str: the environment variable to prepend :param value str or list: the value(s) to prepend to key :param sep str: the separator string - ''' + """ if isinstance(value, list): self.prepend_value(key, sep.join(value), sep) else: self.prepend_value(key, value, sep) def is_defined(self, key): - '''Check if the key exists in the environment + """\ + Check if the key exists in the environment :param key str: the environment variable to check - ''' + """ return (key in self.environ) def set(self, key, value): - '''Set the environment variable "key" to value "value" + """\ + Set the environment variable 'key' to value 'value' :param key str: the environment variable to set :param value str: the value - ''' + """ raise NotImplementedError("set is not implement for this shell!") def get(self, key): - '''Get the value of the environment variable "key" + """\ + Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ return '${%s}' % key def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key. - Has to be overwritten in the derived classes - This can be seen as a virtual method + """\ + Get the value given by the system command "command" + and put it in the environment variable key. + Has to be overwritten in the derived classes + This can be seen as a virtual method :param key str: the environment variable :param command str: the command to execute - ''' + """ raise NotImplementedError("command_value is not implement " "for this shell!") @@ -254,7 +274,8 @@ class FileEnviron(object): self.output.write('clean %s "%s"\n' % (key, sep)) class BashFileEnviron(FileEnviron): - """Class for bash shell. + """\ + Class for bash shell. """ def __init__(self, output, environ=None): """Initialization @@ -266,23 +287,24 @@ class BashFileEnviron(FileEnviron): self.output.write(bash_header) def set(self, key, value): - '''Set the environment variable "key" to value "value" + """Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ self.output.write('export %s="%s"\n' % (key, value)) self.environ[key] = value def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key. - Has to be overwritten in the derived classes - This can be seen as a virtual method + """\ + Get the value given by the system command "command" + and put it in the environment variable key. + Has to be overwritten in the derived classes + This can be seen as a virtual method :param key str: the environment variable :param command str: the command to execute - ''' + """ self.output.write('export %s=$(%s)\n' % (key, command)) def finish(self, required=True): @@ -295,7 +317,8 @@ class BashFileEnviron(FileEnviron): FileEnviron.finish(self, required) class BatFileEnviron(FileEnviron): - """for Windows batch shell. + """\ + for Windows batch shell. """ def __init__(self, output, environ=None): """Initialization @@ -314,36 +337,38 @@ class BatFileEnviron(FileEnviron): self.output.write("rem %s\n" % comment) def get(self, key): - '''Get the value of the environment variable "key" + """Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ return '%%%s%%' % key def set(self, key, value): - '''Set the environment variable "key" to value "value" + """Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ self.output.write('set %s=%s\n' % (key, value)) self.environ[key] = value def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key. - Has to be overwritten in the derived classes - This can be seen as a virtual method + """\ + Get the value given by the system command "command" + and put it in the environment variable key. + Has to be overwritten in the derived classes + This can be seen as a virtual method :param key str: the environment variable :param command str: the command to execute - ''' + """ self.output.write('%s > tmp.txt\n' % (command)) self.output.write('set /p %s =< tmp.txt\n' % (key)) def finish(self, required=True): - """Add a final instruction in the out file (in case of file generation) - In the particular windows case, do nothing + """\ + Add a final instruction in the out file (in case of file generation) + In the particular windows case, do nothing :param required bool: Do nothing if required is False """ @@ -362,30 +387,31 @@ class ContextFileEnviron(FileEnviron): self.output.write(cfg_header) def set(self, key, value): - '''Set the environment variable "key" to value "value" + """Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ self.output.write('%s="%s"\n' % (key, value)) self.environ[key] = value def get(self, key): - '''Get the value of the environment variable "key" + """Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ return '%({0})s'.format(key) def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key. - Has to be overwritten in the derived classes - This can be seen as a virtual method + """\ + Get the value given by the system command "command" + and put it in the environment variable key. + Has to be overwritten in the derived classes + This can be seen as a virtual method :param key str: the environment variable :param command str: the command to execute - ''' + """ raise NotImplementedError("command_value is not implement " "for salome context files!") @@ -404,21 +430,21 @@ class ContextFileEnviron(FileEnviron): self.add_comment("WARNING %s" % warning) def prepend_value(self, key, value, sep=os.pathsep): - '''prepend value to key using sep + """prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key :param sep str: the separator string - ''' + """ self.output.write('ADD_TO_%s: %s\n' % (key, value)) def append_value(self, key, value, sep=os.pathsep): - '''append value to key using sep + """append value to key using sep :param key str: the environment variable to append :param value str: the value to append to key :param sep str: the separator string - ''' + """ self.prepend_value(key, value) def finish(self, required=True): @@ -429,10 +455,11 @@ class ContextFileEnviron(FileEnviron): return def special_path_separator(name): - """TCLLIBPATH, TKLIBPATH, PV_PLUGIN_PATH environments variables need - some exotic path separator. - This function gives the separator regarding the name of the variable - to append or prepend. + """\ + TCLLIBPATH, TKLIBPATH, PV_PLUGIN_PATH environments variables need + some exotic path separator. + This function gives the separator regarding the name of the variable + to append or prepend. :param name str: The name of the variable to find the separator """ @@ -444,8 +471,9 @@ def special_path_separator(name): return res class LauncherFileEnviron: - """Class to generate a launcher file script - (in python syntax) SalomeContext API + """\ + Class to generate a launcher file script + (in python syntax) SalomeContext API """ def __init__(self, output, environ=None): """Initialization @@ -483,8 +511,6 @@ class LauncherFileEnviron: "PYTHONPATH": "PythonPath"} def change_to_launcher(self, value): - """ - """ res=value return res @@ -510,84 +536,84 @@ class LauncherFileEnviron: self.output.write('# "WARNING %s"\n' % warning) def append_value(self, key, value, sep=":"): - '''append value to key using sep + """append value to key using sep :param key str: the environment variable to append :param value str: the value to append to key :param sep str: the separator string - ''' + """ if self.is_defined(key) : self.add(key, value) else : self.set(key, value) def append(self, key, value, sep=":"): - '''Same as append_value but the value argument can be a list + """Same as append_value but the value argument can be a list :param key str: the environment variable to append :param value str or list: the value(s) to append to key :param sep str: the separator string - ''' + """ if isinstance(value, list): self.append_value(key, sep.join(value), sep) else: self.append_value(key, value, sep) def prepend_value(self, key, value, sep=":"): - '''prepend value to key using sep + """prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key :param sep str: the separator string - ''' + """ if self.is_defined(key) : self.add(key, value) else : self.set(key, value) def prepend(self, key, value, sep=":"): - '''Same as prepend_value but the value argument can be a list + """Same as prepend_value but the value argument can be a list :param key str: the environment variable to prepend :param value str or list: the value(s) to prepend to key :param sep str: the separator string - ''' + """ if isinstance(value, list): self.prepend_value(key, sep.join(value), sep) else: self.prepend_value(key, value, sep) def is_defined(self, key): - '''Check if the key exists in the environment + """Check if the key exists in the environment :param key str: the environment variable to check - ''' + """ return key in self.environ.keys() def get(self, key): - '''Get the value of the environment variable "key" + """Get the value of the environment variable "key" :param key str: the environment variable - ''' + """ return '${%s}' % key def set(self, key, value): - '''Set the environment variable "key" to value "value" + """Set the environment variable "key" to value "value" :param key str: the environment variable to set :param value str: the value - ''' + """ self.output.write(self.begin+self.setVarEnv+ '(r"%s", r"%s", overwrite=True)\n' % (key, self.change_to_launcher(value))) self.environ[key] = value def add(self, key, value): - '''prepend value to key using sep + """prepend value to key using sep :param key str: the environment variable to prepend :param value str: the value to prepend to key - ''' + """ if key in self.specialKeys.keys(): self.output.write(self.begin+'addTo%s(r"%s")\n' % (self.specialKeys[key], @@ -605,12 +631,13 @@ class LauncherFileEnviron: self.environ[key]+=sep+value #here yes we know os for current execution def command_value(self, key, command): - '''Get the value given by the system command "command" - and put it in the environment variable key. + """\ + Get the value given by the system command "command" + and put it in the environment variable key. :param key str: the environment variable :param command str: the command to execute - ''' + """ self.output.write(self.indent+'#`%s`\n' % command) import shlex, subprocess @@ -649,8 +676,9 @@ class LauncherFileEnviron: self.output.write(self.indent+"# %s\n" % comment) def finish(self, required=True): - """Add a final instruction in the out file (in case of file generation) - In the particular launcher case, do nothing + """\ + Add a final instruction in the out file (in case of file generation) + In the particular launcher case, do nothing :param required bool: Do nothing if required is False """ @@ -709,7 +737,8 @@ class ScreenEnviron(FileEnviron): self.write("load", script, "", sign="") # The SALOME launcher template -withProfile = """#! /usr/bin/env python +withProfile = """\ + #! /usr/bin/env python ################################################################ # WARNING: this file is automatically generated by SalomeTools # @@ -785,9 +814,9 @@ def main(args): sys.exit(1) # def addToSpecial(self, name, value, pathSep=None): - "add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc..." - #http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm - #TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows. + # add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc... + # http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm + # TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows. if value == '': return diff --git a/src/logger.py b/src/logger.py index 48c6633..d1aa350 100644 --- a/src/logger.py +++ b/src/logger.py @@ -15,8 +15,10 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -'''In this file are implemented the classes and method relative to the logging -''' + +"""\ +Implements the classes and method relative to the logging +""" import sys import os @@ -32,19 +34,20 @@ log_macro_command_file_expression = "^[0-9]{8}_+[0-9]{6}_+.*\.xml$" log_all_command_file_expression = "^.*[0-9]{8}_+[0-9]{6}_+.*\.xml$" class Logger(object): - '''Class to handle log mechanism. - ''' + """\ + Class to handle log mechanism. + """ def __init__(self, config, silent_sysstd=False, all_in_terminal=False, micro_command = False): - '''Initialization + """Initialization :param config pyconf.Config: The global configuration. :param silent_sysstd boolean: if True, do not write anything in terminal. - ''' + """ self.config = config self.default_level = 3 self.silentSysStd = silent_sysstd @@ -101,9 +104,10 @@ class Logger(object): self.logTxtFile = sys.__stdout__ def put_initial_xml_fields(self): - '''Method called at class initialization : Put all fields - corresponding to the command context (user, time, ...) - ''' + """\ + Called at class initialization: Put all fields + corresponding to the command context (user, time, ...) + """ # command name self.xmlFile.add_simple_node("Site", attrib={"command" : self.config.VARS.command}) @@ -143,14 +147,14 @@ class Logger(object): command_name, command_res, full_launched_command): - '''Add a link to another log file. + """Add a link to another log file. :param log_file_name str: The file name of the link. :param command_name str: The name of the command linked. :param command_res str: The result of the command linked. "0" or "1" :parma full_launched_command str: The full lanch command ("sat command ...") - ''' + """ xmlLinks = self.xmlFile.xmlroot.find("Links") src.xmlManager.add_simple_node(xmlLinks, "link", @@ -160,14 +164,15 @@ class Logger(object): "launchedCommand" : full_launched_command}) def write(self, message, level=None, screenOnly=False): - '''the function used in the commands - that will print in the terminal and the log file. + """\ + function used in the commands + to print in the terminal and the log file. :param message str: The message to print. :param level int: The output level corresponding to the message 0 < level < 6. :param screenOnly boolean: if True, do not write in log file. - ''' + """ # do not write message starting with \r to log file if not message.startswith("\r") and not screenOnly: self.xmlFile.append_node_text("Log", @@ -190,10 +195,10 @@ class Logger(object): self.flush() def error(self, message): - '''Print an error. + """Print an error. :param message str: The message to print. - ''' + """ # Print in the log file self.xmlFile.append_node_text("traces", _('ERROR:') + message) @@ -205,19 +210,19 @@ class Logger(object): sys.stderr.write(_('ERROR:') + message) def flush(self): - '''Flush terminal - ''' + """Flush terminal""" sys.stdout.flush() self.logTxtFile.flush() def end_write(self, attribute): - '''Method called just after command end : Put all fields - corresponding to the command end context (time). - Write the log xml file on the hard drive. - And display the command to launch to get the log + """\ + Called just after command end: Put all fields + corresponding to the command end context (time). + Write the log xml file on the hard drive. + And display the command to launch to get the log :param attribute dict: the attribute to add to the node "Site". - ''' + """ # Get current time (end of command) and format it dt = datetime.datetime.now() Y, m, dd, H, M, S = date_to_datetime(self.config.VARS.datehour) @@ -256,13 +261,14 @@ class Logger(object): pass def date_to_datetime(date): - '''Little method that gets year, mon, day, hour , - minutes and seconds from a str in format YYYYMMDD_HHMMSS + """\ + From a string date in format YYYYMMDD_HHMMSS + returns list year, mon, day, hour, minutes, seconds :param date str: The date in format YYYYMMDD_HHMMSS :return: the same date and time in separate variables. :rtype: (str,str,str,str,str,str) - ''' + """ Y = date[:4] m = date[4:6] dd = date[6:8] @@ -272,20 +278,23 @@ def date_to_datetime(date): return Y, m, dd, H, M, S def timedelta_total_seconds(timedelta): - '''Little method to replace total_seconds from - datetime module in order to be compatible with old python versions + """\ + Replace total_seconds from datetime module + in order to be compatible with old python versions :param timedelta datetime.timedelta: The delta between two dates :return: The number of seconds corresponding to timedelta. :rtype: float - ''' + """ return ( timedelta.microseconds + 0.0 + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6 def show_command_log(logFilePath, cmd, application, notShownCommands): - '''Used in updateHatXml. Determine if the log xml file logFilePath - has to be shown or not in the hat log. + """\ + Used in updateHatXml. + Determine if the log xml file logFilePath + has to be shown or not in the hat log. :param logFilePath str: the path to the command xml log file :param cmd str: the command of the log file @@ -297,7 +306,7 @@ def show_command_log(logFilePath, cmd, application, notShownCommands): :return: True if cmd is not in notShownCommands and the application in the log file corresponds to application :rtype: boolean - ''' + """ # When the command is not in notShownCommands, no need to go further : # Do not show if cmd in notShownCommands: @@ -328,13 +337,13 @@ def show_command_log(logFilePath, cmd, application, notShownCommands): return False, None, None def list_log_file(dirPath, expression): - '''Find all files corresponding to expression in dirPath + """Find all files corresponding to expression in dirPath :param dirPath str: the directory where to search the files :param expression str: the regular expression of files to find :return: the list of files path and informations about it :rtype: list - ''' + """ lRes = [] for fileName in os.listdir(dirPath): # YYYYMMDD_HHMMSS_namecmd.xml @@ -370,12 +379,13 @@ def list_log_file(dirPath, expression): return lRes def update_hat_xml(logDir, application=None, notShownCommands = []): - '''Create the xml file in logDir that contain all the xml file - and have a name like YYYYMMDD_HHMMSS_namecmd.xml + """\ + Create the xml file in logDir that contain all the xml file + and have a name like YYYYMMDD_HHMMSS_namecmd.xml :param logDir str: the directory to parse :param application str: the name of the application if there is any - ''' + """ # Create an instance of XmlLogFile class to create hat.xml file xmlHatFilePath = os.path.join(logDir, 'hat.xml') xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath, diff --git a/src/product.py b/src/product.py index 3591f25..6a9a8d4 100644 --- a/src/product.py +++ b/src/product.py @@ -15,9 +15,11 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -'''In this file are implemented the methods - relative to the product notion of salomeTools -''' + +"""\ +In this file are implemented the methods +relative to the product notion of salomeTools +""" import os import re @@ -30,7 +32,7 @@ config_expression = "^config-\d+$" VERSION_DELIMITER = "_to_" def get_product_config(config, product_name, with_install_dir=True): - '''Get the specific configuration of a product from the global configuration + """Get the specific configuration of a product from the global configuration :param config Config: The global configuration :param product_name str: The name of the product @@ -39,7 +41,7 @@ def get_product_config(config, product_name, with_install_dir=True): of the function check_config_exists) :return: the specific configuration of the product :rtype: Config - ''' + """ # Get the version of the product from the application definition version = config.APPLICATION.products[product_name] @@ -290,7 +292,7 @@ Please provide a 'compil_script' key in its definition.""") % product_name return prod_info def get_product_section(config, product_name, version, section=None): - '''Get the product description from the configuration + """Get the product description from the configuration :param config Config: The global configuration :param product_name str: The product name @@ -299,7 +301,7 @@ def get_product_section(config, product_name, version, section=None): explicitly given :return: The product description :rtype: Config - ''' + """ # if section is not None, try to get the corresponding section if section: @@ -345,20 +347,20 @@ def get_product_section(config, product_name, version, section=None): return None def get_install_dir(config, base, version, prod_info): - '''Compute the installation directory of a given product + """Compute the installation directory of a given product :param config Config: The global configuration :param base str: This corresponds to the value given by user in its application.pyconf for the specific product. If "yes", the - user wants the product to be in base. If "no", he wants the - product to be in the application workdir + user wants the product to be in base. If "no", he wants the + product to be in the application workdir :param version str: The version of the product :param product_info Config: The configuration specific to the product :return: The path of the product installation :rtype: str - ''' + """ install_dir = "" in_base = False if (("install_dir" in prod_info and prod_info.install_dir == "base") @@ -382,7 +384,7 @@ def get_install_dir(config, base, version, prod_info): return install_dir def get_base_install_dir(config, prod_info, version): - '''Compute the installation directory of a product in base + """Compute the installation directory of a product in base :param config Config: The global configuration :param product_info Config: The configuration specific to @@ -390,7 +392,7 @@ def get_base_install_dir(config, prod_info, version): :param version str: The version of the product :return: The path of the product installation :rtype: str - ''' + """ base_path = src.get_base_path(config) prod_dir = os.path.join(base_path, prod_info.name + "-" + version) if not os.path.exists(prod_dir): @@ -414,9 +416,10 @@ def get_base_install_dir(config, prod_info, version): return install_dir def check_config_exists(config, prod_dir, prod_info): - '''Verify that the installation directory of a product in a base exists - Check all the config- directory and verify the sat-config.pyconf file - that is in it + """\ + Verify that the installation directory of a product in a base exists + Check all the config- directory and verify the sat-config.pyconf file + that is in it :param config Config: The global configuration :param prod_dir str: The product installation directory path @@ -426,7 +429,7 @@ def check_config_exists(config, prod_dir, prod_info): :return: True or false is the installation is found or not and if it is found, the path of the found installation :rtype: (boolean, str) - ''' + """ # check if the directories or files of the directory corresponds to the # directory installation of the product l_dir_and_files = os.listdir(prod_dir) @@ -479,14 +482,14 @@ def check_config_exists(config, prod_dir, prod_info): def get_products_infos(lproducts, config): - '''Get the specific configuration of a list of products + """Get the specific configuration of a list of products :param lproducts List: The list of product names :param config Config: The global configuration :return: the list of tuples (product name, specific configuration of the product) :rtype: [(str, Config)] - ''' + """ products_infos = [] # Loop on product names for prod in lproducts: @@ -501,15 +504,16 @@ def get_products_infos(lproducts, config): return products_infos def get_product_dependencies(config, product_info): - '''Get recursively the list of products that are - in the product_info dependencies + """\ + Get recursively the list of products that are + in the product_info dependencies :param config Config: The global configuration :param product_info Config: The configuration specific to the product :return: the list of products in dependence :rtype: list - ''' + """ if "depend" not in product_info or product_info.depend == []: return [] res = [] @@ -526,14 +530,15 @@ def get_product_dependencies(config, product_info): return res def check_installation(product_info): - '''Verify if a product is well installed. Checks install directory presence - and some additional files if it is defined in the config + """\ + Verify if a product is well installed. Checks install directory presence + and some additional files if it is defined in the config :param product_info Config: The configuration specific to the product :return: True if it is well installed :rtype: boolean - ''' + """ if not product_compiles(product_info): return True install_dir = product_info.install_dir @@ -548,13 +553,13 @@ def check_installation(product_info): return True def check_source(product_info): - '''Verify if a sources of product is preset. Checks source directory presence + """Verify if a sources of product is preset. Checks source directory presence :param product_info Config: The configuration specific to the product :return: True if it is well installed :rtype: boolean - ''' + """ DBG.write("check_source product_info", product_info) source_dir = product_info.source_dir if not os.path.exists(source_dir): @@ -568,13 +573,13 @@ def check_source(product_info): return True def product_is_sample(product_info): - '''Know if a product has the sample type + """Know if a product has the sample type :param product_info Config: The configuration specific to the product :return: True if the product has the sample type, else False :rtype: boolean - ''' + """ if 'type' in product_info: ptype = product_info.type return ptype.lower() == 'sample' @@ -582,47 +587,47 @@ def product_is_sample(product_info): return False def product_is_salome(product_info): - '''Know if a product is a SALOME module + """Know if a product is a SALOME module :param product_info Config: The configuration specific to the product :return: True if the product is a SALOME module, else False :rtype: boolean - ''' + """ return ("properties" in product_info and "is_SALOME_module" in product_info.properties and product_info.properties.is_SALOME_module == "yes") def product_is_fixed(product_info): - '''Know if a product is fixed + """Know if a product is fixed :param product_info Config: The configuration specific to the product :return: True if the product is fixed, else False :rtype: boolean - ''' + """ get_src = product_info.get_source return get_src.lower() == 'fixed' def product_is_native(product_info): - '''Know if a product is native + """Know if a product is native :param product_info Config: The configuration specific to the product :return: True if the product is native, else False :rtype: boolean - ''' + """ get_src = product_info.get_source return get_src.lower() == 'native' def product_is_dev(product_info): - '''Know if a product is in dev mode + """Know if a product is in dev mode :param product_info Config: The configuration specific to the product :return: True if the product is in dev mode, else False :rtype: boolean - ''' + """ dev = product_info.dev res = (dev.lower() == 'yes') DBG.write('product_is_dev %s' % product_info.name, res) @@ -630,93 +635,94 @@ def product_is_dev(product_info): return res def product_is_debug(product_info): - '''Know if a product is in debug mode + """Know if a product is in debug mode :param product_info Config: The configuration specific to the product :return: True if the product is in debug mode, else False :rtype: boolean - ''' + """ debug = product_info.debug return debug.lower() == 'yes' def product_is_autotools(product_info): - '''Know if a product is compiled using the autotools + """Know if a product is compiled using the autotools :param product_info Config: The configuration specific to the product :return: True if the product is autotools, else False :rtype: boolean - ''' + """ build_src = product_info.build_source return build_src.lower() == 'autotools' def product_is_cmake(product_info): - '''Know if a product is compiled using the cmake + """Know if a product is compiled using the cmake :param product_info Config: The configuration specific to the product :return: True if the product is cmake, else False :rtype: boolean - ''' + """ build_src = product_info.build_source return build_src.lower() == 'cmake' def product_is_vcs(product_info): - '''Know if a product is download using git, svn or cvs (not archive) + """Know if a product is download using git, svn or cvs (not archive) :param product_info Config: The configuration specific to the product :return: True if the product is vcs, else False :rtype: boolean - ''' + """ return product_info.get_source in AVAILABLE_VCS def product_is_smesh_plugin(product_info): - '''Know if a product is a SMESH plugin + """Know if a product is a SMESH plugin :param product_info Config: The configuration specific to the product :return: True if the product is a SMESH plugin, else False :rtype: boolean - ''' + """ return ("properties" in product_info and "smesh_plugin" in product_info.properties and product_info.properties.smesh_plugin == "yes") def product_is_cpp(product_info): - '''Know if a product is cpp + """Know if a product is cpp :param product_info Config: The configuration specific to the product :return: True if the product is a cpp, else False :rtype: boolean - ''' + """ return ("properties" in product_info and "cpp" in product_info.properties and product_info.properties.cpp == "yes") def product_compiles(product_info): - '''Know if a product compiles or not (some products do not have a - compilation procedure) + """\ + Know if a product compiles or not + (some products do not have a compilation procedure) :param product_info Config: The configuration specific to the product :return: True if the product compiles, else False :rtype: boolean - ''' + """ return not("properties" in product_info and "compilation" in product_info.properties and product_info.properties.compilation == "no") def product_has_script(product_info): - '''Know if a product has a compilation script + """Know if a product has a compilation script :param product_info Config: The configuration specific to the product :return: True if the product it has a compilation script, else False :rtype: boolean - ''' + """ if "build_source" not in product_info: # Native case return False @@ -724,36 +730,36 @@ def product_has_script(product_info): return build_src.lower() == 'script' def product_has_env_script(product_info): - '''Know if a product has an environment script + """Know if a product has an environment script :param product_info Config: The configuration specific to the product :return: True if the product it has an environment script, else False :rtype: boolean - ''' + """ return "environ" in product_info and "env_script" in product_info.environ def product_has_patches(product_info): - '''Know if a product has one or more patches + """Know if a product has one or more patches :param product_info Config: The configuration specific to the product :return: True if the product has one or more patches :rtype: boolean - ''' + """ res = ( "patches" in product_info and len(product_info.patches) > 0 ) DBG.write('product_has_patches %s' % product_info.name, res) # if product_info.name == "XDATA": return True #test #10569 return res def product_has_logo(product_info): - '''Know if a product has a logo (YACSGEN generate) + """Know if a product has a logo (YACSGEN generate) :param product_info Config: The configuration specific to the product :return: The path of the logo if the product has a logo, else False :rtype: Str - ''' + """ if ("properties" in product_info and "logo" in product_info.properties): return product_info.properties.logo @@ -761,48 +767,48 @@ def product_has_logo(product_info): return False def product_has_salome_gui(product_info): - '''Know if a product has a SALOME gui + """Know if a product has a SALOME gui :param product_info Config: The configuration specific to the product :return: True if the product has a SALOME gui, else False :rtype: Boolean - ''' + """ return ("properties" in product_info and "has_salome_gui" in product_info.properties and product_info.properties.has_salome_gui == "yes") def product_is_mpi(product_info): - '''Know if a product has openmpi in its dependencies + """Know if a product has openmpi in its dependencies :param product_info Config: The configuration specific to the product :return: True if the product has openmpi inits dependencies :rtype: boolean - ''' + """ return "openmpi" in product_info.depend def product_is_generated(product_info): - '''Know if a product is generated (YACSGEN) + """Know if a product is generated (YACSGEN) :param product_info Config: The configuration specific to the product :return: True if the product is generated :rtype: boolean - ''' + """ return ("properties" in product_info and "generate" in product_info.properties and product_info.properties.generate == "yes") def get_product_components(product_info): - '''Get the component list to generate with the product + """Get the component list to generate with the product :param product_info Config: The configuration specific to the product :return: The list of names of the components :rtype: List - ''' + """ if not product_is_generated(product_info): return [] diff --git a/src/pyconf.py b/src/pyconf.py index de9af0c..68b9174 100644 --- a/src/pyconf.py +++ b/src/pyconf.py @@ -276,7 +276,7 @@ class ConfigOutputStream(object): self.stream.close() def defaultStreamOpener(name): - """ + """\ This function returns a read-only stream, given its name. The name passed in should correspond to an existing stream, otherwise an exception will be raised. @@ -343,25 +343,20 @@ def isWord(s): return s.isalnum() def makePath(prefix, suffix): - """ + """\ Make a path from a prefix and suffix. - Examples:: - - makePath('', 'suffix') -> 'suffix' - makePath('prefix', 'suffix') -> 'prefix.suffix' - makePath('prefix', '[1]') -> 'prefix[1]' - - @param prefix: The prefix to use. If it evaluates as false, the suffix - is returned. - @type prefix: str - @param suffix: The suffix to use. It is either an identifier or an - index in brackets. - @type suffix: str - @return: The path concatenation of prefix and suffix, with a - dot if the suffix is not a bracketed index. - @rtype: str + Examples: + makePath('', 'suffix') -> 'suffix' + makePath('prefix', 'suffix') -> 'prefix.suffix' + makePath('prefix', '[1]') -> 'prefix[1]' + @param prefix: The prefix to use. If it evaluates as false, the suffix is returned. + @type prefix: str + @param suffix: The suffix to use. It is either an identifier or an index in brackets. + @type suffix: str + @return: The path concatenation of prefix and suffix, with adot if the suffix is not a bracketed index. + @rtype: str """ if not prefix: rv = suffix @@ -1526,9 +1521,9 @@ RCURLY, COMMA, found %r" ref.addElement(LBRACK, tv) def defaultMergeResolve(map1, map2, key): - """ - A default resolver for merge conflicts. Returns a string - indicating what action to take to resolve the conflict. + """\ + A default resolver for merge conflicts. + Returns a string indicating what action to take to resolve the conflict. @param map1: The map being merged into. @type map1: L{Mapping}. @@ -1536,11 +1531,13 @@ def defaultMergeResolve(map1, map2, key): @type map2: L{Mapping}. @param key: The key in map2 (which also exists in map1). @type key: str + @return: One of "merge", "append", "mismatch" or "overwrite" indicating what action should be taken. This should be appropriate to the objects being merged - e.g. there is no point returning "merge" if the two objects are instances of L{Sequence}. + @rtype: str """ obj1 = map1[key]