Salome HOME
Merge branch 'V8_0_BR'
[modules/homard.git] / doc / files / tutorial_util.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015  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-R&D 2014
23 """
24 __revision__ = "V1.3"
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 #========================================================================
38 def gzip_gunzip(data_dir, num_tuto, option) :
39   """
40 Compression/Uncompression of the med files of a directory such as tutorial_x.nn.med
41 data_dir: directory
42 num_tuto: number of the tutorial
43 option  : 1: compression, -1: uncompression
44 Copyright EDF-R&D 2014
45   """
46 #
47   ficloc_basis = "tutorial_%d" % num_tuto
48 #
49   erreur = 0
50   num = -1
51 #
52 # Uncompression
53 #
54   if ( option == -1 ) :
55 #
56     while not erreur :
57       num += 1
58       ficloc = ficloc_basis + ".%02d.med" % num
59       nomfic = os.path.join(data_dir, ficloc)
60       if not os.path.isfile(nomfic) :
61         ficloc += ".gz"
62         nomfic = os.path.join(data_dir, ficloc)
63         if os.path.isfile(nomfic) :
64           os.system("gunzip "+nomfic)
65         else :
66           erreur = 1
67           break
68 #
69     ficloc = ficloc_basis + ".fr.med"
70     nomfic = os.path.join(data_dir, ficloc)
71     if not os.path.isfile(nomfic) :
72       ficloc += ".gz"
73       nomfic = os.path.join(data_dir, ficloc)
74       if os.path.isfile(nomfic) :
75         os.system("gunzip "+nomfic)
76 #
77 # Compression
78 #
79   elif ( option == 1 ) :
80 #
81     while not erreur :
82       num += 1
83       ficloc = ficloc_basis + ".%02d.med.gz" % num
84       nomfic = os.path.join(data_dir, ficloc)
85       if not os.path.isfile(nomfic) :
86         ficloc = ficloc_basis + ".%02d.med" % num
87         nomfic = os.path.join(data_dir, ficloc)
88         if os.path.isfile(nomfic) :
89           os.system("gzip "+nomfic)
90         else :
91           erreur = 2
92           break
93 #
94     ficloc = ficloc_basis + ".fr.med.gz"
95     nomfic = os.path.join(data_dir, ficloc)
96     if not os.path.isfile(nomfic) :
97       ficloc = ficloc_basis + ".fr.med"
98       nomfic = os.path.join(data_dir, ficloc)
99       if os.path.isfile(nomfic) :
100         os.system("gzip "+nomfic)
101 #
102   return
103 #
104 #========================================================================
105 #========================================================================
106 def creation_dircase(num_tuto) :
107   """
108 Creation of a directory for the results of tutorial_x
109 num_tuto: number of the tutorial
110 Copyright EDF-R&D 2014
111   """
112 #
113   if os.environ.has_key("LOGNAME") :
114     user = os.environ ["LOGNAME"]
115   else :
116     user = "anonymous"
117   dircase = os.path.join( os.sep, "tmp", "HOMARD_"+user)
118   if not os.path.isdir(dircase) :
119     os.mkdir (dircase)
120   dirtuto_basis = "tutorial_%d" % num_tuto
121   dircase = os.path.join( dircase, dirtuto_basis )
122   if os.path.isdir(dircase) :
123     remove_dir(dircase)
124   os.mkdir (dircase)
125 #
126   return dircase
127 #========================================================================
128 #========================================================================
129 #