Esempio n. 1
0
 def _prepareUniqueFileSystemName(self, dirName, baseName, ext=None):
     if ext is None:
         ext = koToolbox2.TOOL_EXTENSION
     # "slugify"
     basePart = koToolbox2.truncateAtWordBreak(re.sub(r"[^\w\d\-=\+]+", "_", baseName))
     basePart = join(dirName, basePart)
     candidate = basePart + ext
     if not os.path.exists(candidate):
         return candidate
     for i in range(1, 1000):
         candidate = "%s-%d%s" % (basePart, i, ext)
         if not os.path.exists(candidate):
             # log.debug("Writing out file %s/%s as %s", os.getcwd(), basePart, candidate)
             return candidate
     else:
         raise Exception("File %s exists in directory %s, force is off" % (name, os.getcwd()))
Esempio n. 2
0
 def _prepareUniqueFileSystemName(self, dirName, baseName, ext=None):
     if ext is None:
         ext = koToolbox2.TOOL_EXTENSION
     # "slugify"
     basePart = koToolbox2.truncateAtWordBreak(re.sub(r'[^\w\d\-=\+]+', '_', baseName))
     basePart = join(dirName, basePart)
     candidate = basePart + ext
     if not os.path.exists(candidate):
         return candidate
     for i in range(1, 1000):
         candidate = "%s-%d%s" % (basePart, i, ext)
         if not os.path.exists(candidate):
             #log.debug("Writing out file %s/%s as %s", os.getcwd(), basePart, candidate)
             return candidate
     else:
         raise Exception("File %s exists in directory %s, force is off" %
                         (name, os.getcwd()))
Esempio n. 3
0
 def _prepareUniqueFileSystemName(self, node, addExt=True):
     name = node.elt.get("name")
     # "slugify"
     basePart = koToolbox2.truncateAtWordBreak(re.sub(r"[^\w\d\-=\+]+", "_", name))
     extPart = (addExt and koToolbox2.TOOL_EXTENSION) or ""
     # The purpose for the next test is because abbrevs with
     # names like "+" "++" and "++??" will all be mapped to
     # the name "_".  So insist on unique filenames, even if
     # we're in force mode.
     if nowrite or not os.path.exists(basePart + extPart) or (self._force and basePart == name):
         return basePart + extPart
     for i in range(1, 1000000):
         candidate = "%s-%d%s" % (basePart, i, extPart)
         if not os.path.exists(candidate):
             # log.debug("Writing out file %s/%s as %s", os.getcwd(), basePart, candidate)
             return candidate
     else:
         raise ExpandToolboxException("File %s exists in directory %s, force is off" % (name, os.getcwd()))
 def _prepareUniqueFileSystemName(self, node, addExt=True):
     name = node.elt.get('name')
     # "slugify"
     basePart = koToolbox2.truncateAtWordBreak(
         re.sub(r'[^\w\d\-=\+]+', '_', name))
     extPart = (addExt and koToolbox2.TOOL_EXTENSION) or ""
     # The purpose for the next test is because abbrevs with
     # names like "+" "++" and "++??" will all be mapped to
     # the name "_".  So insist on unique filenames, even if
     # we're in force mode.
     if (nowrite or not os.path.exists(basePart + extPart)
             or (self._force and basePart == name)):
         return basePart + extPart
     for i in range(1, 1000000):
         candidate = "%s-%d%s" % (basePart, i, extPart)
         if not os.path.exists(candidate):
             #log.debug("Writing out file %s/%s as %s", os.getcwd(), basePart, candidate)
             return candidate
     else:
         raise ExpandToolboxException(
             "File %s exists in directory %s, force is off" %
             (name, os.getcwd()))