X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=chemins.py;h=b88093561b1693fcae183977979daa1bc93ffe6f;hp=24a76debbed7920f74e162bcf5b709efa696c1cf;hb=5064efb501867baf6736aad84a3bb0571669a41a;hpb=4dc1de2e438378f357bcbb2fd8cf0075e0bdcd55 diff --git a/chemins.py b/chemins.py index 24a76de..b880935 100644 --- a/chemins.py +++ b/chemins.py @@ -5,12 +5,22 @@ #License: GNU/GPL import os +import sys import tempfile import logging log = logging.getLogger('iramuteq.chemins') +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 PathOut : def __init__(self, filename = None, analyse_type = '', dirout = None) : if filename is not None : @@ -20,11 +30,11 @@ 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 + '_') @@ -36,6 +46,14 @@ class PathOut : 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) @@ -48,9 +66,13 @@ class PathOut : self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\') return self.temp elif key not in self.d : - return os.path.join(self.dirout, key).replace('\\', '\\\\') + f = os.path.join(self.dirout, key).replace('\\', '\\\\') + return normpath_win32(f) + #return os.path.join(self.dirout, key).replace('\\', '\\\\') else : - return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\') + 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('\\', '/') @@ -145,6 +167,7 @@ def ConstructGlobalPath(AppliPath): ConfigPath = os.path.join(AppliPath, 'configuration') DictConfigPath = { 'global': os.path.join(ConfigPath, 'global.cfg'), + 'preferences': os.path.join(ConfigPath, 'iramuteq.cfg'), } return DictConfigPath