X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=functions.py;h=e72ebd9fc7394fba885452c99778755d4a2ffa2d;hp=aee5d9bc77971fc856550e53ea54352f31589045;hb=4e4210c1d2693e0333371ea269c5967d736a9eae;hpb=5d8a0a0e99d9075adc28f2525fe0aba8e14c2b0a diff --git a/functions.py b/functions.py index aee5d9b..e72ebd9 100644 --- a/functions.py +++ b/functions.py @@ -45,14 +45,17 @@ class History : def read(self) : d = shelve.open(self.filein) self.history = d.get('history', []) + self.matrix = d.get('matrix', []) self.ordercorpus = dict([[corpus['uuid'], i] for i, corpus in enumerate(self.history)]) - self.corpus = dict([[corpus['uuid'], corpus] for i, corpus in enumerate(self.history)]) + self.corpus = dict([[corpus['uuid'], corpus] for corpus in self.history]) self.analyses = dict([[analyse['uuid'], analyse] for corpus in self.history for analyse in corpus.get('analyses', [])]) + self.matrixanalyse = dict([[mat['uuid'], mat] for mat in self.matrix]) d.close() def write(self) : d = shelve.open(self.filein) d['history'] = self.history + d['matrix'] = self.matrix d.close() def add(self, analyse) : @@ -64,7 +67,7 @@ class History : tosave['corpus'] = analyse['corpus'] tosave['name'] = analyse['name'] acorpus_uuid = analyse['corpus'] - if acorpus_uuid in self.ordercorpus : + if acorpus_uuid in self.corpus : if 'analyses' in self.history[self.ordercorpus[acorpus_uuid]] : self.history[self.ordercorpus[acorpus_uuid]]['analyses'].append(tosave) else : @@ -77,12 +80,37 @@ class History : self.write() self.read() + def addMatrix(self, analyse) : + tosave = {'uuid' : analyse['uuid'], 'ira': analyse['ira'], 'type' : analyse['type']} + tosave['name'] = analyse['name'] + self.matrix.append(tosave) + self.write() + self.read() + + def addmultiple(self, analyses) : + for analyse in analyses : + tosave = {'uuid' : analyse['uuid'], 'ira': analyse['ira'], 'type' : analyse['type']} + corpus = analyse['uuid'] + tosave['corpus'] = corpus + tosave['name'] = analyse['name'] + if corpus in self.corpus : + if 'analyses' in self.history[self.ordercorpus[corpus]] : + self.history[self.ordercorpus[corpus]]['analyses'].append(tosave) + else : + self.history[self.ordercorpus[corpus]]['analyses'] = [tosave] + self.write() + self.read() + def delete(self, analyse, corpus = False) : if corpus : self.history.pop(self.ordercorpus[analyse['uuid']]) - else : + if analyse['uuid'] in self.openedcorpus : + del self.openedcorpus[analyse['uuid']] + elif analyse['uuid'] in self.analyses : todel = [i for i, ana in enumerate(self.corpus[analyse['corpus']]['analyses']) if ana['uuid'] == analyse['uuid']][0] self.history[self.ordercorpus[analyse['corpus']]]['analyses'].pop(todel) + elif analyse['uuid'] in self.matrixanalyse : + self.matrix = [mat for mat in self.matrix if mat['uuid'] != analyse['uuid']] self.write() self.read() @@ -388,23 +416,14 @@ def BugReport(parent, error = None): txt += exc dial = BugDialog(parent) - #for line in formatExceptionInfo(): - # if type(line) == type([]): - # for don in line: - # txt += don.replace(' ', ' ') - # else: - # txt += line + '\n' if 'Rerror' in dir(parent) : txt += parent.Rerror parent.Rerror = '' - #if error is not None : - # txt += '\n%s\n' %error - print formatExceptionInfo() - log.error(txt) + log.info(txt) dial.text_ctrl_1.write(txt) dial.CenterOnParent() dial.ShowModal() - #raise Exception('Bug') + dial.Destroy() def PlaySound(parent): if parent.pref.getboolean('iramuteq', 'sound') : @@ -462,6 +481,12 @@ def ReadList(filein, encoding = sys.getdefaultencoding()): i += 1 return dict, first +def exec_RCMD(rpath, command) : + log.info('R CMD INSTALL %s' % command) + rpath = rpath.replace('\\','\\\\') + error = call(["%s" % rpath, 'CMD', 'INSTALL', "%s" % command]) + return error + def exec_rcode(rpath, rcode, wait = True, graph = False): log.info("R Script : %s" % rcode) needX11 = False @@ -514,20 +539,27 @@ def check_Rresult(parent, pid) : if isinstance(pid, Popen) : if pid.returncode != 0 : error = pid.communicate() + print error error = [str(error[0]), error[1]] if error[1] is None : error[1] = 'None' parent.Rerror = '\n'.join([str(pid.returncode), '\n'.join(error)]) - try : - raise Exception('\n'.join(u'Erreur R', '\n'.join(error[1:]))) - except : - BugReport(parent) + #try : + raise Exception('\n'.join([u'Erreur R', '\n'.join(error[1:])])) + return False + #except : + # BugReport(parent) + else : + return True else : if pid != 0 : - try : - raise Exception(u'Erreur R') - except : - BugReport(parent) + #try : + raise Exception(u'Erreur R') + return False + #except : + # BugReport(parent) + else : + return True def print_liste(filename,liste): with open(filename,'w') as f :