Salome HOME
Update copyrights
[modules/homard.git] / doc / files / tutorial_util.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2019  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21 Python script for HOMARD
22 Copyright EDF 2014, 2018
23 """
24 __revision__ = "V2.02"
25
26 import os
27 import sys
28
29 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
30 # Repertoire des scripts utilitaires
31 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
32 REP_PYTHON = os.path.normpath(REP_PYTHON)
33 sys.path.append(REP_PYTHON)
34 from test_util import remove_dir
35
36 #
37 #========================= Debut de la fonction ==================================
38 #
39 def gzip_gunzip(data_dir, num_tuto, option) :
40   """
41 Compression/Uncompression of the med(or xao) files of a directory such as tutorial_x.nn.med (or tutorial_x.nn.xao)
42 data_dir: directory
43 num_tuto: number of the tutorial
44 option  : 1: compression, -1: uncompression
45 Copyright EDF-R&D 2014
46   """
47 #
48   ficloc_basis = "tutorial_%d" % num_tuto
49 #
50   erreur = 0
51   num = -1
52 #
53 # Uncompression
54 #
55   if ( option == -1 ) :
56 #
57     while not erreur :
58       num += 1
59       ficloc = ficloc_basis + ".%02d.med" % num
60       nomfic = os.path.join(data_dir, ficloc)
61       if not os.path.isfile(nomfic) :
62         ficloc += ".gz"
63         nomfic = os.path.join(data_dir, ficloc)
64         if os.path.isfile(nomfic) :
65           os.system("gunzip "+nomfic)
66         else :
67           erreur = 1
68           break
69 #
70     for suffixe in ( "xao", "fr.med" ) :
71       ficloc = ficloc_basis + "." + suffixe
72       nomfic = os.path.join(data_dir, ficloc)
73       if not os.path.isfile(nomfic) :
74         ficloc += ".gz"
75         nomfic = os.path.join(data_dir, ficloc)
76         if os.path.isfile(nomfic) :
77           os.system("gunzip "+nomfic)
78 #
79 # Compression
80 #
81   elif ( option == 1 ) :
82 #
83     while not erreur :
84       num += 1
85       ficloc = ficloc_basis + ".%02d.med.gz" % num
86       nomfic = os.path.join(data_dir, ficloc)
87       if not os.path.isfile(nomfic) :
88         ficloc = ficloc_basis + ".%02d.med" % num
89         nomfic = os.path.join(data_dir, ficloc)
90         if os.path.isfile(nomfic) :
91           os.system("gzip "+nomfic)
92         else :
93           erreur = 2
94           break
95 #
96     for suffixe in ( "xao", "fr.med" ) :
97       ficloc = ficloc_basis + "." + suffixe + ".gz"
98       nomfic = os.path.join(data_dir, ficloc)
99       if not os.path.isfile(nomfic) :
100         ficloc = ficloc_basis + ".fr.med"
101         nomfic = os.path.join(data_dir, ficloc)
102         if os.path.isfile(nomfic) :
103           os.system("gzip "+nomfic)
104 #
105   return
106 #
107 #==========================  Fin de la fonction ==================================
108 #
109 #========================= Debut de la fonction ==================================
110 #
111 def creation_dircase(num_tuto) :
112   """
113 Creation of a directory for the results of tutorial_x
114 num_tuto: number of the tutorial
115 Copyright EDF-R&D 2014
116   """
117 #
118   if "LOGNAME" in os.environ :
119     user = os.environ ["LOGNAME"]
120   else :
121     user = "anonymous"
122   dircase = os.path.join( os.sep, "tmp", "HOMARD_"+user)
123   if not os.path.isdir(dircase) :
124     os.mkdir (dircase)
125   dirtuto_basis = "tutorial_%d" % num_tuto
126   dircase = os.path.join( dircase, dirtuto_basis )
127   if os.path.isdir(dircase) :
128     remove_dir(dircase)
129   os.mkdir (dircase)
130 #
131   return dircase
132 #
133 #==========================  Fin de la fonction ==================================
134 #