Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / Tools / Verima / ajoutEnreg.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2013-2022  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 import sys, os
22 rep=os.path.dirname(os.path.abspath(__file__))
23 installDir=os.path.join(rep,'..')
24 sys.path.insert(0,installDir)
25
26 from qtsalome import *
27 from Base.dataBase import Base
28
29 def completeDatabase(fichier,table,enregistrement):
30       maBase=Base(fichier)
31       maBase.initialise()
32       nomTable="ma"+str(table)
33       matable=getattr(maBase,nomTable)
34       model= QSqlTableModel()
35       model.setTable(matable.nom)
36       nbCols=model.columnCount() -1
37       if table == "TableGroupesRef" : nbCols==nbCols+1
38       if len(enregistrement) != nbCols  :
39          print("mauvais nb de valeurs")
40          print("Attention, ne pas renter d'Id")
41       if table == "TableGroupesRef" : matable.insereLigne(enregistrement)
42       else : matable.insereLigneAutoId(enregistrement)
43       maBase.close()
44
45
46
47 if __name__ == "__main__":
48      from argparse import ArgumentParser
49      p=ArgumentParser()
50      p.add_argument('-d',dest='database',default="myMesh.db",help='nom de la database')
51      p.add_argument('table',help='nom de la table a completer')
52      p.add_argument('enregistrement', nargs="+")
53      args = p.parse_args()
54      if args.table is None : 
55          print("table obligatoire")
56          exit()
57      good_tables = ("TableMaillages","TableMailleurs","TableGroupesRef","TableVersions")
58      if args.table not in good_tables:
59          print("la table doit etre : %s" % ' ou '.join(good_tables))
60          exit()
61      completeDatabase(args.database,args.table,args.enregistrement)
62