4 rep=os.path.dirname(os.path.abspath(__file__))
5 installDir=os.path.join(rep,'..')
6 sys.path.insert(0,installDir)
8 from PyQt4 import QtGui,QtCore,QtSql
9 from Base.dataBase import Base
11 def completeDatabase(fichier,table,enregistrement):
14 nomTable="ma"+str(table)
15 matable=getattr(maBase,nomTable)
16 model= QtSql.QSqlTableModel()
17 model.setTable(matable.nom)
18 nbCols=model.columnCount() -1
19 if table == "TableGroupesRef" : nbCols==nbCols+1
20 if len(enregistrement) != nbCols :
21 print "mauvais nb de valeurs"
22 print "Attention, ne pas renter d'Id"
23 if table == "TableGroupesRef" : matable.insereLigne(enregistrement)
24 else : matable.insereLigneAutoId(enregistrement)
29 if __name__ == "__main__":
30 from optparse import OptionParser
32 p.add_option('-d',dest='database',default="myMesh.db",help='nom de la database')
33 p.add_option('-t',dest='table',help='nom de la table a completer')
34 options, args = p.parse_args()
35 if options.table==None :
36 print "table obligatoire"
38 if options.table not in ("TableMaillages","TableMailleurs","TableGroupesRef","TableVersions") :
39 print "la table doit etre : TableMaillages ou TableMailleurs ou TableGroupesRef ou TableVersions"
41 enregistrement=tuple(args)
42 completeDatabase(options.database,options.table,enregistrement)