コード例 #1
0
ファイル: apiUtils.py プロジェクト: Python3pkg/DevToolsLib
def backup(path, suffix='.bak'):
    """
    Rename a file or directory safely without overwriting an existing
    backup of the same name.

    :param path: The path object to the file or directory to make a backup of.
    :param suffix: The suffix to rename files with.
    :returns: The new path of backed up file/directory
    :rtype: str

    """
    count = -1
    new_path = None
    while True:
        if path.exists() :
            if count == -1:
                new_path = Path("{0}{1}".format(path, suffix))
            else:
                new_path = Path("{0}{1}.{2}".format(path, suffix, count))
            if new_path.exists():
                count += 1
                continue
            else:
                path.copy(new_path)
        else:
            break
    return new_path
コード例 #2
0
ファイル: apiUtils.py プロジェクト: rocktavious/DevToolsLib
def backup(path, suffix='.bak'):
    """
    Rename a file or directory safely without overwriting an existing
    backup of the same name.

    :param path: The path object to the file or directory to make a backup of.
    :param suffix: The suffix to rename files with.
    :returns: The new path of backed up file/directory
    :rtype: str

    """
    count = -1
    new_path = None
    while True:
        if path.exists() :
            if count == -1:
                new_path = Path("{0}{1}".format(path, suffix))
            else:
                new_path = Path("{0}{1}.{2}".format(path, suffix, count))
            if new_path.exists():
                count += 1
                continue
            else:
                path.copy(new_path)
        else:
            break
    return new_path
コード例 #3
0
ファイル: core.py プロジェクト: rocktavious/DevToolsLib
 def uploadFile(self, srcPath, destPath):
     db = self.getClient()
     srcPath = Path(srcPath)
     destPath = Path(destPath)
     destPath.makedirs()
     if srcPath.exists():
         result = db.put_file(destPath, open(srcPath,'rb'))
         return result
     return None
コード例 #4
0
 def uploadFile(self, srcPath, destPath):
     db = self.getClient()
     srcPath = Path(srcPath)
     destPath = Path(destPath)
     destPath.makedirs()
     if srcPath.exists():
         result = db.put_file(destPath, open(srcPath, 'rb'))
         return result
     return None