from copy import copy
import re
import html.entities
-import shelve
+#import shelve
+import json
from uuid import uuid4
import logging
self.parametres['type'] = 'matrix'
self.parametres['matrix_name'] = os.path.basename(filename)
self.parametres['uuid'] = str(uuid4())
- self.parametres['shelves'] = os.path.join(self.parametres['pathout'], 'shelve.db')
+ self.parametres['shelves'] = os.path.join(self.parametres['pathout'], 'shelve')
self.parametres['ira'] = os.path.join(self.parametres['pathout'], 'Matrix.ira')
else :
self.parametres = parametres
#self.parametres = self.parametre
def read_tableau(self, fileout) :
- d=shelve.open(fileout)
- #self.parametres = d['parametres']
- #if 'syscoding' not in self.parametres :
- # self.parametres['syscoding'] = sys.getdefaultencoding()
+ with open(fileout, 'r', encoding='utf8') as f :
+ d = json.load(f)
self.actives = d['actives']
self.sups = d['sups']
self.classes = d['classes']
self.lchi = d['lchi']
if 'content' in d :
self.content = d['content']
- d.close()
def open(self):
print('open matrix')
self.colnb = len(self.linecontent[0])
def save_tableau(self, fileout) :
- d=shelve.open(fileout)
+ d = {}
d['parametres'] = self.parametres
d['actives'] = self.actives
d['sups'] = self.sups
if 'lchi' in dir(self) :
d['lchi'] = self.lchi
d['content'] = self.content
- d.close()
+ with open(fileout, 'w', encoding='utf8') as f :
+ json.dump(d, f)
def make_content(self) :
self.pathout.createdir(self.parametres['pathout'])
self.linecontent = [[val.replace('"','').replace(';',' ').replace('\t', ' ').strip() for val in line] for line in self.linecontent]
def write_csvfile(self) :
- with open(self.parametres['csvfile'], 'w') as f :
+ with open(self.parametres['csvfile'], 'w', encoding='utf8') as f :
f.write('\n'.join(['\t'.join(line) for line in self.csvtable]))
def make_tmpfile(self) :
self.write_csvfile()
def read_csvfile(self):
- with codecs.open(self.parametres['csvfile'], 'r', self.parametres['syscoding']) as f:
+ with open(self.parametres['csvfile'], 'r', encoding='utf8') as f:
self.csvtable = [line.split('\t') for line in f.read().splitlines()]
self.linecontent = [line[1:] for line in self.csvtable]
self.linecontent.pop(0)
#out = [[self.rownames[i]] + out[i] for i in range(len(linecontent))]
#out.insert(0,[self.idname] + self.listactives)
out.insert(0, self.listactives)
- with open(fileout, 'w') as f :
+ with open(fileout, 'w', encoding='utf8') as f :
f.write('\n'.join([';'.join(line) for line in out]))
def make_01_from_selection(self, listact, listsup = None, dowrite = True) :
#table = [[self.rownames[i]] + table[i] for i in range(len(self.rownames))]
#table.insert(0, [self.idname] + self.listactives)
table.insert(0, self.listactives)
- with open(fileout, 'w') as f:
+ with open(fileout, 'w', encoding='utf8') as f:
f.write('\n'.join([';'.join(line) for line in table]))
def printtable(self, filename, Table, sep = ';'):
- with open(filename, 'w') as f :
+ with open(filename, 'w', encoding='utf8') as f :
f.write('\n'.join([sep.join(line) for line in Table]))
def buildprofil(self) :
- with open(self.pathout['uce'], 'r') as filein :
+ with open(self.pathout['uce'], 'r', encoding='utf8') as filein :
content = filein.readlines()
content.pop(0)
lsucecl = []