X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=functions.py;h=f2579f120e6ea638f15ee5460f8a9d8e56c64b58;hp=d697f1623eaa9fb46e3bee34213491b8b6347d27;hb=ae0a736d9598a3483ccf2b35e3b61d365cf77db4;hpb=f6e6d1cea58fe1e16aee1c8630367a890df82cea diff --git a/functions.py b/functions.py index d697f16..f2579f1 100644 --- a/functions.py +++ b/functions.py @@ -30,6 +30,15 @@ log = logging.getLogger('iramuteq') indices_simi = [u'cooccurrence' ,'pourcentage de cooccurrence',u'Russel',u'Jaccard', 'Kulczynski1', 'Kulczynski2', 'Mountford', 'Fager', 'simple matching', 'Hamman', 'Faith', 'Tanimoto', 'Dice', 'Phi', 'Stiles', 'Michael', 'Mozley', 'Yule', 'Yule2', 'Ochiai', 'Simpson', 'Braun-Blanquet','Chi-squared', 'Phi-squared', 'Tschuprow', 'Cramer', 'Pearson', 'binomial'] +def normpath_win32(path) : + if not sys.platform == 'win32' : + return path + while '\\\\' in path : + path = path.replace('\\\\', '\\') + if sys.platform == 'win32' and path.startswith('\\') and not path.startswith('\\\\') : + path = '\\' + path + return path + class TGen : def __init__(self, path = None, encoding = 'utf8'): self.path = path @@ -55,6 +64,7 @@ class TGen : def writetable(self, pathout, tgens, totocc): etoiles = totocc.keys() + etoiles.sort() with open(pathout, 'w') as f : line = '\t'.join([u'tgens'] + etoiles) + '\n' f.write(line.encode(self.encoding)) @@ -66,7 +76,7 @@ class TGen : while totname + `i` in tgens : i += 1 totname = totname + `i` - line = '\t'.join([totname] + [`totocc[et]` for et in etoiles]) + line = '\t'.join([totname] + [`totocc[et]` for et in etoiles]) + '\n' f.write(line.encode(self.encoding)) class History : @@ -196,7 +206,9 @@ class DoConf : def __init__(self, configfile=None, diff = None, parametres = None) : self.configfile = configfile self.conf = ConfigParser() + if configfile is not None : + configfile = normpath_win32(configfile) self.conf.readfp(codecs.open(configfile, 'r', 'utf8')) self.parametres = {} if parametres is not None : @@ -252,8 +264,9 @@ class DoConf : txt += '%s = %s\n' % (option, `parametres[i][option]`) if outfile is None : outfile = self.configfile - with codecs.open(outfile, 'w', 'utf8') as f : - f.write(txt) + outfile = normpath_win32(outfile) + with open(outfile, 'w') as f : + f.write(txt.encode('utf8')) #self.conf.write(f) def totext(self, parametres) : @@ -480,6 +493,7 @@ exceptions = {'paragrapheOT' : u"Un problème de formatage (présence d'un marqu 'EmptyText' : u"Texte vide (probablement un problème de formatage du corpus). Le problème est apparu à la ligne ", 'CorpusEncoding' : u"Problème d'encodage.", 'TextBeforeTextMark' : u"Problème de formatage : du texte avant le premier marqueur de texte (****). Le problème est survenu à la ligne ", + 'MissingAnalyse' : u'Aucun fichier à cet emplacement :\n', } def BugReport(parent, error = None): @@ -506,7 +520,7 @@ def BugReport(parent, error = None): txt += u'*************************************\n' txt += '\n'.join(excTb).replace(' ', ' ') txt += excName + '\n' - txt += exc + txt += `exc` title = "Bug" dial = BugDialog(parent, **{'title' : title}) @@ -543,7 +557,10 @@ def ReadLexique(parent, lang = 'french', filein = None): else : parent.lexique = ReadDicoAsDico(filein) else : - parent.lexique = {} + if filein is None : + parent.lexique = {} + else : + parent.lexique = ReadDicoAsDico(filein) def ReadList(filein, encoding = sys.getdefaultencoding(), sep = ';'): #file = open(filein) @@ -674,6 +691,11 @@ def progressbar(self, maxi) : parent = self.parent else : parent = self + try : + print '###horrible hack progressbar' + maxi = int(maxi) + except : + maxi = 1 return wx.ProgressDialog("Traitements", "Veuillez patienter...", maximum=maxi,