Exemple #1
0
    def findDestPathNoSource(self, suffix, prefix=u""):
        """
        Find a path to a destination.
        """
        self._ensureStorage()

        if prefix:
            fname = prefix + suffix

            destPath = os.path.join(self.storagePath, fname)
            if not os.path.exists(pathEnc(destPath)):
                return destPath
        else:
            prefix = u""


#         mat = _FILESPLITPAT.match(fname)
#         if mat is None:
#             raise FSException("Internal error: Bad source file name")
# 
#         coreName = mat.group("name")
#         suffix = mat.group("suffix")

        for t in xrange(20):  # Number of tries
            newName = u"%s_%s%s" % (prefix, createRandomString(20), suffix)

            destPath = os.path.join(self.storagePath, newName)
            if not os.path.exists(pathEnc(destPath)):
                return destPath

        # Give up
        return None
Exemple #2
0
    def findDestPathNoSource(self, suffix, prefix=""):
        """
        Find a path to a destination.
        """
        self._ensureStorage()

        if prefix:
            fname = prefix + suffix

            destPath = os.path.join(self.storagePath, fname)
            if not os.path.exists(pathEnc(destPath)):
                return destPath
        else:
            prefix = ""


#         mat = _FILESPLITPAT.match(fname)
#         if mat is None:
#             raise FSException("Internal error: Bad source file name")
# 
#         coreName = mat.group("name")
#         suffix = mat.group("suffix")

        for t in range(20):  # Number of tries
            newName = "%s_%s%s" % (prefix, createRandomString(20), suffix)

            destPath = os.path.join(self.storagePath, newName)
            if not os.path.exists(pathEnc(destPath)):
                return destPath

        # Give up
        return None
Exemple #3
0
    def findDestPath(self, srcPath):
        """
        Find a path to a new destination
        of the source file denoted by srcPath. Some settings of
        the object determine how this is done exactly.
        Returns a tuple (path, exists) where path is the destination
        path and exists is True if an identical file exists already
        at the destination.
        If path is None, a new filename couldn't be found.
        """

        if not (os.path.isfile(srcPath) or os.path.isdir(srcPath)):
            raise FSException(_(u"Path '%s' must point to an existing file") %
                    srcPath)

        self._ensureStorage()
        
        for c in self._getCandidates(srcPath):
            if self._isIdentical(srcPath, c):
                return (c, True)

        # No identical file found, so find a not yet used name for the new file.
        fname = os.path.basename(srcPath)

        if not os.path.exists(pathEnc(os.path.join(self.storagePath, fname))):
            return (os.path.join(self.storagePath, fname), False)

        mat = _FILESPLITPAT.match(fname)
        if mat is None:
            raise FSException(_(u"Internal error: Bad source file name"))

        coreName = mat.group("name")
        suffix = mat.group("suffix")

        for t in xrange(10):  # Number of tries
            newName = u"%s_%s%s" % (coreName, createRandomString(10), suffix)
            
            if not os.path.exists(pathEnc(os.path.join(
                    self.storagePath, newName))):
                return (os.path.join(self.storagePath, newName), False)

        # Give up
        return (None, False)
Exemple #4
0
    def findDestPath(self, srcPath):
        """
        Find a path to a new destination
        of the source file denoted by srcPath. Some settings of
        the object determine how this is done exactly.
        Returns a tuple (path, exists) where path is the destination
        path and exists is True if an identical file exists already
        at the destination.
        If path is None, a new filename couldn't be found.
        """

        if not (os.path.isfile(srcPath) or os.path.isdir(srcPath)):
            raise FSException(_("Path '%s' must point to an existing file") %
                    srcPath)

        self._ensureStorage()
        
        for c in self._getCandidates(srcPath):
            if self._isIdentical(srcPath, c):
                return (c, True)

        # No identical file found, so find a not yet used name for the new file.
        fname = os.path.basename(srcPath)

        if not os.path.exists(pathEnc(os.path.join(self.storagePath, fname))):
            return (os.path.join(self.storagePath, fname), False)

        mat = _FILESPLITPAT.match(fname)
        if mat is None:
            raise FSException(_("Internal error: Bad source file name"))

        coreName = mat.group("name")
        suffix = mat.group("suffix")

        for t in range(10):  # Number of tries
            newName = "%s_%s%s" % (coreName, createRandomString(10), suffix)
            
            if not os.path.exists(pathEnc(os.path.join(
                    self.storagePath, newName))):
                return (os.path.join(self.storagePath, newName), False)

        # Give up
        return (None, False)
Exemple #5
0
    def _findNewWordForFile(self, path):
        wikiWord = guessBaseNameByFilename(path, self.pagefileSuffix)
        try:
            if self.connWrap.execSqlQuerySingleItem(
                    "select word from wikiwords where word = ?", (wikiWord,)):
                for i in range(20):    # "while True" is too dangerous
                    rand = createRandomString(10)
                    
                    if self.connWrap.execSqlQuerySingleItem(
                            "select word from wikiwords where word = ?",
                            (wikiWord + u"~" + rand,)):
                        continue
                    
                    return wikiWord + u"~" + rand

                return None

            else:
                return wikiWord

        except (IOError, OSError, ValueError), e:
            traceback.print_exc()
            raise DbWriteAccessError(e)