Salome HOME
Adding documentation and warning check for user file names
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Tue, 19 Mar 2019 22:12:55 +0000 (23:12 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Tue, 19 Mar 2019 22:12:55 +0000 (23:12 +0100)
doc/en/index.rst
doc/en/notations.rst [new file with mode: 0644]
doc/fr/index.rst
doc/fr/notations.rst [new file with mode: 0644]
src/daComposant/daCore/Interfaces.py
src/daComposant/daCore/PlatformInfo.py

index 36d88e7d5f10d24557dec4844aa921272b6f3fc0..fd80289507219ad0ac444ddb8a95044bcae379cf 100644 (file)
@@ -60,16 +60,11 @@ before reading the rest, but a valuable use of the module requires to read and
 come back regularly to these parts. The following parts describe
 :ref:`section_gui_in_salome` and :ref:`section_tui`. The last main part gives a
 detailed :ref:`section_reference`, with three essential main sub-parts
-describing the details of commands and options of the algorithms. And, to
-comply with the module requirements, be sure to read the part
-:ref:`section_license`.
-
-In all this documentation, we use standard notations of linear algebra, data
-assimilation (as described in [Ide97]_) and optimization. In particular, vectors
-are written horizontally or vertically without making difference. Matrices are
-written either normally, or with a condensed notation, consisting in the use of
-a space to separate values and a "``;``" to separate the rows, in a continuous
-line.
+describing the details of commands and options of the algorithms. A
+:ref:`section_glossary`, some :ref:`section_notations`, a
+:ref:`section_bibliography` and an extensive :ref:`genindex` are included in
+the document. And, to comply with the module requirements, be sure to read the
+part :ref:`section_license`.
 
 **Table of contents**
 
@@ -87,6 +82,7 @@ line.
    reference
    license
    glossary
+   notations
    bibliography
 
 **Indices and tables**
diff --git a/doc/en/notations.rst b/doc/en/notations.rst
new file mode 100644 (file)
index 0000000..a85b1d5
--- /dev/null
@@ -0,0 +1,55 @@
+..
+   Copyright (C) 2008-2019 EDF R&D
+
+   This file is part of SALOME ADAO module.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   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
+
+   See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+   Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+.. _section_notations:
+
+Notations and conventions
+=========================
+
+In all this documentation, we use standard notations of linear algebra, data
+assimilation (as described in [Ide97]_) and optimization.
+
+For algebraic formulations, vectors are written horizontally or vertically
+without making a difference. Matrices are written either normally, or with a
+condensed notation, consisting in the use of a space to separate the values,
+and a "``;``" to separate the rows of the matrix, in a continuous line.
+
+Files can be indicated by an absolute or relative path. For some old or shared
+file systems, the full name with the path must not contain more than 256
+characters. In the case of Python files, it is advisable not to use dots in the
+name apart for the extension, to prevent difficulties in using it that are
+complicated to diagnose.
+
+File type and naming conventions rely heavily on the extensions of the files
+themselves. Some of them are briefly specified here, without being exhaustive:
+
+- extension ``.py``   : data or commands text file of Python source type
+- extension ``.comm`` : commands text file of EFICAS type
+- extension ``.xml``  : data text file of XML type or commands (for YACS, not exclusive)
+- extension ``.txt``  : data text file with space separator
+- extension ``.dat``  : data text file with space separator
+- extension ``.csv``  : data text file with comma or semicolon separator
+- extension ``.tsv``  : data text file with tab separator
+- extension ``.npy``  : data binary file of type Numpy mono-variable
+- extension ``.npz``  : data binary file of type Numpy multi-variables
+- extension ``.sdf``  : data binary file of type Scientific Data Format
index d8b33db340150cd1ba9a0f7da61a4f6a4255da20..a74f45c897280c3608f9f29da8c8e308a3608731 100644 (file)
@@ -64,17 +64,11 @@ de lire et de revenir régulièrement à ces parties. Les parties qui suivent
 expliquent comment utiliser une :ref:`section_gui_in_salome` ou une
 :ref:`section_tui`. La dernière grande partie détaille la
 :ref:`section_reference`, avec trois sous-parties essentielles qui la composent
-et qui décrivent les commandes et des options d'algorithmes. Enfin, pour
-respecter les exigences de licence du module, n'oubliez pas de lire la partie
-:ref:`section_license`.
-
-Dans cette documentation, on utilise les notations standards de l'algèbre
-linéaire, de l'assimilation de données (comme décrit dans [Ide97]_) et de
-l'optimisation. En particulier, les vecteurs sont écrits horizontalement ou
-verticalement sans faire la différence. Les matrices sont écrites soit
-normalement, ou avec une notation condensée, consistant à utiliser un espace
-pour séparer les valeurs, et un "``;``" pour séparer les lignes de la matrice,
-de façon continue sur une ligne.
+et qui décrivent les commandes et des options d'algorithmes. Un
+:ref:`section_glossary`, des :ref:`section_notations`, une
+:ref:`section_bibliography` et un :ref:`genindex` développés complètent le
+document. Enfin, pour respecter les exigences de licence du module, n'oubliez
+pas de lire la partie :ref:`section_license`.
 
 **Table des matières**
 
@@ -92,6 +86,7 @@ de façon continue sur une ligne.
    reference
    license
    glossary
+   notations
    bibliography
 
 **Index et tables**
diff --git a/doc/fr/notations.rst b/doc/fr/notations.rst
new file mode 100644 (file)
index 0000000..96e4565
--- /dev/null
@@ -0,0 +1,59 @@
+..
+   Copyright (C) 2008-2019 EDF R&D
+
+   This file is part of SALOME ADAO module.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   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
+
+   See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+   Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+.. _section_notations:
+
+Notations et conventions
+========================
+
+Dans cette documentation, on utilise les notations standards de l'algèbre
+linéaire, de l'assimilation de données (comme décrit dans [Ide97]_) et de
+l'optimisation.
+
+Pour les formulations algébriques, les vecteurs sont écrits horizontalement ou
+verticalement sans faire la différence. Les matrices sont écrites soit
+normalement, ou avec une notation condensée, consistant à utiliser un espace
+pour séparer les valeurs, et un "``;``" pour séparer les lignes de la matrice,
+de façon continue sur une ligne.
+
+Les fichiers peuvent être indiqués grâce à un chemin absolu ou relatif. Pour
+certains systèmes de fichiers anciens ou partagés, le nom complet avec le
+chemin ne doit pas contenir plus de 256 caractères. Dans le cas où ce sont des
+fichiers de type Python, il est judicieux de ne pas utiliser de points dans le
+nom à part pour l'extension, pour éviter des difficultés d'utilisation
+compliquées à diagnostiquer.
+
+Les conventions de type et de nommage des fichiers s'appuient fortement sur les
+extensions des fichiers eux-mêmes. On en précise brièvement certaines ici, sans
+être exhaustifs :
+
+- extension ``.py``   : fichier texte de données ou commandes de type source Python
+- extension ``.comm`` : fichier texte de données de commandes EFICAS
+- extension ``.xml``  : fichier texte de données de type XML (pour YACS, non exclusif)
+- extension ``.txt``  : fichier texte de données à séparateur espace
+- extension ``.dat``  : fichier texte de données à séparateur espace
+- extension ``.csv``  : fichier texte de données à séparateur virgule ou point-virgule
+- extension ``.tsv``  : fichier texte de données à séparateur tabulation
+- extension ``.npy``  : fichier binaire de données de type Numpy mono-variable
+- extension ``.npz``  : fichier binaire de données de type Numpy multi-variables
+- extension ``.sdf``  : fichier binaire de données de type Scientific Data Format
index 796ccb8ee35cddc201a148c3fe5b142faee2bc2a..29a342a0c9e40cb80d31d3a31249c36ecf5db4c6 100644 (file)
@@ -516,6 +516,7 @@ class ImportFromScript(object):
             __basename = os.path.basename(__filename).rstrip(".py")
         else:
             __basename = __filename.rstrip(".py")
+        PlatformInfo.checkFileNameImportability( __basename+".py" )
         self.__basename = __basename
         self.__filenspace = __import__(__basename, globals(), locals(), [])
         self.__filestring = open(__filename,'r').read()
@@ -567,7 +568,7 @@ class ImportDetector(object):
             mimetypes.add_type('text/csv', '.csv')
             mimetypes.add_type('text/tab-separated-values', '.tsv')
     #
-    # File related f
+    # File related tests
     # ------------------
     def is_local_file(self):
         if os.path.isfile(os.path.realpath(self.__url)):
@@ -671,6 +672,7 @@ class ImportFromFile(object):
         self.__url = ImportDetector( Filename, Format)
         self.__url.raise_error_if_not_local_file()
         self._filename = self.__url.get_absolute_name()
+        PlatformInfo.checkFileNameConformity( self._filename )
         #
         self._format = self.__url.get_comprehensive_mime()
         #
index 4c2f854c9d7c7eae8feae77983c86ce2e3ca36eb..6133bbd2eaa23794e92317d893be3a7221eb0150 100644 (file)
@@ -48,6 +48,7 @@ import os
 import sys
 import platform
 import locale
+import logging
 
 # ==============================================================================
 class PlatformInfo(object):
@@ -283,6 +284,39 @@ def date2int( __date, __lang="FR" ):
         raise ValueError("Cannot convert \"%s\" as a D/M/Y H:M date"%d)
     return __number
 
+def checkFileNameConformity( __filename, __warnInsteadOfPrint=True ):
+    if sys.platform.startswith("win") and len(__filename) > 256:
+        __conform = False
+        __msg = (" For some shared or older file systems on Windows, a file "+\
+            "name longer than 256 characters can lead to access problems."+\
+            "\n  The name of the file in question is the following:"+\
+            "\n  %s")%(__filename,)
+        if __warnInsteadOfPrint: logging.warning(__msg)
+        else:                    print(__msg)
+    else:
+        __conform = True
+    #
+    return __conform
+
+def checkFileNameImportability( __filename, __warnInsteadOfPrint=True ):
+    if str(__filename).count(".") > 1:
+        __conform = False
+        __msg = (" The file name contains %i point(s) before the extension "+\
+            "separator, which can potentially lead to problems when "+\
+            "importing this file into Python, as it can then be recognized "+\
+            "as a sub-module (generating a \"ModuleNotFoundError\"). If it "+\
+            "is intentional, make sure that there is no module with the "+\
+            "same name as the part before the first point, and that there is "+\
+            "no \"__init__.py\" file in the same directory."+\
+            "\n  The name of the file in question is the following:"+\
+            "\n  %s")%(int(str(__filename).count(".")-1), __filename)
+        if __warnInsteadOfPrint: logging.warning(__msg)
+        else:                    print(__msg)
+    else:
+        __conform = True
+    #
+    return __conform
+
 # ==============================================================================
 class PathManagement(object):
     """