X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;f=chemins.py;h=44f092b202d0a74a606b830b3633bd533f983241;hb=585be25e4c896f0209c6f87c4ccf05cf395faec0;hp=f43969cc956ac828ecafe922ce79db68a0e00dda;hpb=e1096f8c3931cb999117c3a7eab4cee9f9224a1b;p=iramuteq diff --git a/chemins.py b/chemins.py index f43969c..44f092b 100644 --- a/chemins.py +++ b/chemins.py @@ -1,14 +1,18 @@ -#!/bin/env python # -*- coding: utf-8 -*- #Author: Pierre Ratinaud -#Copyright (c) 2008 Pierre Ratinaud +#Copyright (c) 2008-2020 Pierre Ratinaud +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 #License: GNU/GPL +#------------------------------------ +# import des modules python +#------------------------------------ import os import sys import tempfile import logging + log = logging.getLogger('iramuteq.chemins') @@ -20,7 +24,7 @@ def normpath_win32(path) : if sys.platform == 'win32' and path.startswith('\\') and not path.startswith('\\\\') : path = '\\' + path return path - + class PathOut : def __init__(self, filename = None, analyse_type = '', dirout = None) : if filename is not None : @@ -30,22 +34,30 @@ class PathOut : self.filename, self.fileext = os.path.splitext(self.filebasename) self.analyse = analyse_type #self.dirout = self.mkdirout(dirout) - if dirout is not None: + if dirout is not None: self.dirout = os.path.abspath(dirout) elif filename is not None and dirout is None: self.dirout = os.path.abspath(self.directory) - self.d = {} + self.d = {} def mkdirout(self) : dirout = os.path.join(self.dirout, self.filename + '_' + self.analyse + '_') nb = 1 - tdirout = dirout + `nb` + tdirout = dirout + repr(nb) while os.path.exists(tdirout) : nb += 1 - tdirout = dirout + `nb` + tdirout = dirout + repr(nb) self.name = os.path.splitext(tdirout)[1] return tdirout + def makenew(self, filename, ext): + nb = 1 + newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext + while os.path.exists(newfile) : + nb += 1 + newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext + return newfile + def createdir(self, tdirout) : if not os.path.exists(tdirout) : os.mkdir(tdirout) @@ -65,14 +77,13 @@ class PathOut : f = os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\') return normpath_win32(f) #return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\') - + def getF(self, key) : return self.__getitem__(key).replace('\\', '/') - def ffr(filename): return filename.replace('\\', '\\\\') - + def FFF(filename): return filename.replace('\\', '/') @@ -230,7 +241,7 @@ ChdTxtPathOut = {'TableUc1': 'TableUc1.csv', 'rapport': 'RAPPORT.txt', 'pre_rapport' : 'info.txt', 'uce': 'uce.csv', - 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]), + 'Rchdtxt': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'), 'arbre1': 'arbre_1.png', 'arbre2': 'arbre_2.png', 'dendro1': 'dendro1.png', @@ -254,13 +265,13 @@ ChdTxtPathOut = {'TableUc1': 'TableUc1.csv', 'AFC2DCoulSup': 'AFC2DCoulSup.png', 'AFC2DCoulEt': 'AFC2DCoulEt.png', 'AFC2DCoulCl': 'AFC2DCoulCl.png', - 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]), - 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]), + 'Rafc3d': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'), + 'R3DCoul': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'), 'RESULT_CHD': 'resultats-chd.html', 'RESULT_AFC': 'resultats-afc.html', 'Et01': 'Et01.csv', - 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]), - 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]), + 'Rchdquest':tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'), + 'RTxtProfGraph':tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'), 'typelist': 'typelist.csv', 'concord':'concordancier.csv', 'bduceforme':'bduceforme.csv', @@ -279,7 +290,7 @@ ChdTxtPathOut = {'TableUc1': 'TableUc1.csv', 'prof_type' : 'profil_type.csv', 'antiprof_type' : 'antiprof_type.csv', 'type_cl' : 'type_cl.csv', - 'db' : 'analyse.db', + 'db' : 'analyse'#.db, } def StatTxtPathOut(pathout): @@ -303,11 +314,12 @@ def StatTxtPathOut(pathout): 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')), 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')), 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')), - 'db' : os.path.join(pathout, 'analyse.db'), + 'db' : os.path.join(pathout, 'analyse'), 'zipf' : ffr(os.path.join(pathout, 'zipf.png')), } return d +# ??? #def construct_simipath(pathout): # d = {'mat01' : 'mat01.csv', # 'matsimi' : 'matsimi.csv', @@ -326,7 +338,7 @@ simipath = {'mat01' : 'mat01.csv', 'liste_graph' :'liste_graph.txt', 'ira' : 'Analyse.ira', 'film' : '', - 'db' : 'analyse.db', + 'db' : 'analyse', 'corpus' : 'corpus.db', }