X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=chemins.py;h=b88093561b1693fcae183977979daa1bc93ffe6f;hp=6b124ef151d999313ea6fb7beebbfffc44db5d46;hb=878794bb47c9444f0acb1dbaf3afe4037ace7dcf;hpb=2ffa9388c45dce689bb45c1cf6c7ad81d2636409 diff --git a/chemins.py b/chemins.py index 6b124ef..b880935 100644 --- a/chemins.py +++ b/chemins.py @@ -2,15 +2,25 @@ # -*- coding: utf-8 -*- #Author: Pierre Ratinaud #Copyright (c) 2008 Pierre Ratinaud -#Lisense: GNU/GPL +#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: - self.dirout = dirout + if dirout is not None: + self.dirout = os.path.abspath(dirout) elif filename is not None and dirout is None: - self.dirout = self.directory - self.d = {} + self.dirout = os.path.abspath(self.directory) + 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('\\', '/') @@ -129,7 +151,7 @@ def ConstructConfigPath(AppliPath, user=True): else : ConfigPath = AppliPath DictConfigPath = { - 'alceste': os.path.join(ConfigPath, 'alceste.cfg'), + 'reinert': os.path.join(ConfigPath, 'reinert.cfg'), 'key': os.path.join(ConfigPath, 'key.cfg'), 'path': os.path.join(ConfigPath, 'path.cfg'), 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'), @@ -137,6 +159,7 @@ def ConstructConfigPath(AppliPath, user=True): 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'), 'stat' : os.path.join(ConfigPath, 'stat.cfg'), 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'), + 'matrix' : os.path.join(ConfigPath, 'matrix.cfg'), } return DictConfigPath @@ -144,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 @@ -166,6 +190,8 @@ def ConstructDicoPath(AppliPath): 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'), 'spanish' : os.path.join(BasePath, 'lexique_sp.txt'), 'spanish_exp' : os.path.join(BasePath, 'expression_sp.txt'), + 'galician' : os.path.join(BasePath, 'lexique_gl.txt'), + 'galician_exp' : os.path.join(BasePath, 'expression_gl.txt'), } return DictPath