def uploadNewFile(self, localPath, tempFilePath, parentFolderId, description = None): if os.path.exists(localPath): if localPath != tempFilePath: self.logger.debug('[Adapter] Copy local file (%s) to temp file (%s)', localPath, tempFilePath) shutil.copyfile(localPath, tempFilePath) else: raise WaitingOtherResourceException sha1 = Utils.sha1ForFile(localPath) checkExistResponse = self.autoRepeatQuery(self.getFangCloudHttpClient().checkFileExistsOnServerAtTheSameDirWithTheSameName, [localPath, parentFolderId, sha1, description]) if checkExistResponse['success'] == False or not checkExistResponse['is_file_existed']: presignResponse = self.autoRepeatQuery(self.getFangCloudHttpClient().uploadNewFilePresign, [parentFolderId, localPath, description]) if presignResponse.get('success', False): uploadURL = presignResponse['upload_url'] response = self.autoRepeatQuery(self.getFangCloudHttpClient().uploadNewFile, [uploadURL, localPath, tempFilePath]) else: response = presignResponse if response['success'] == False: result = response else: result = self.__formatUploadNewFileResponse(response) return result else: self.logger.debug('[Adapter] File (%s) exist on server', localPath) checkExistResponse['file_info']['success'] = checkExistResponse['success'] checkExistResponse['file_info']['is_synced'] = checkExistResponse['is_synced'] checkExistResponse['file_info']['unencrypted_sha1'] = Utils.sha1ForFile(localPath) response = checkExistResponse['file_info'] return self.__formatUploadNewFileResponse(response)
def uploadNewFileV2(self, localPath, tempFilePath, parentFolderId, description = None): """ \xe8\xaf\xb4\xe6\x98\x8e: \xe5\x8a\xa0\xe4\xb8\x8a\xe4\xba\x86\xe6\x96\x87\xe4\xbb\xb6\xe5\x88\x86\xe5\x9d\x97\xe4\xb8\x8a\xe4\xbc\xa0\xe5\xa4\x84\xe7\x90\x86,\xe7\xbb\xbc\xe5\x90\x88\xe4\xba\x86\xe6\x96\x87\xe4\xbb\xb6\xe5\x88\x86\xe5\x9d\x97\xe4\xb8\x8a\xe4\xbc\xa0\xe5\x92\x8c\xe6\x96\x87\xe4\xbb\xb6\xe6\x99\xae\xe9\x80\x9a\xe4\xbc\xa0\xe8\xbe\x93\xe5\x8a\x9f\xe8\x83\xbd @param localPath: @param tempFilePath: @param parentFolderId: @param description: @return: """ try: self.logger.debug('[Adapter] enter multiupload new file main process, file (%s)', localPath) if os.path.exists(localPath): if localPath != tempFilePath: self.logger.debug('[Adapter] Copy local file (%s) to temp file (%s)', localPath, tempFilePath) shutil.copyfile(localPath, tempFilePath) else: raise WaitingOtherResourceException sha1 = Utils.sha1ForFile(localPath) checkExistResponse = self.autoRepeatQuery(self.getFangCloudHttpClient().checkFileExistsOnServerAtTheSameDirWithTheSameName, [localPath, parentFolderId, sha1, description]) if checkExistResponse['success'] == False or not checkExistResponse['is_file_existed']: localId1, localId2 = self.localFileSystem.getResourceIndex(localPath) self.__checkFileSha1(localId1, localId2, sha1) isInterruptUpload, uploadGetResponse = self.__isInterruptUpload(localId1, localId2) if isInterruptUpload: if uploadGetResponse.get('success', False): return self.__multiInterruptUploadNewFile(localPath, tempFilePath, localId1, localId2, uploadGetResponse, sha1) else: return uploadGetResponse else: isMultiUpLoadNewFile, response = self.__isMultiUploadNewFile(localPath, parentFolderId, sha1) if response.get('success', False) and isMultiUpLoadNewFile: return self.__multiUploadNewFile(localPath, tempFilePath, response, sha1) elif response.get('success', False) and not isMultiUpLoadNewFile: self.logger.debug('[Adapter] upload file in original way file (%s)', localPath) return self.__uploadNewFileWithoutPresign(localPath, tempFilePath, response) else: return response else: self.logger.debug('[Adapter] File (%s) exist on server', localPath) fileId = -checkExistResponse['file_info']['id'] checkExistResponse['file_info']['success'] = checkExistResponse['success'] checkExistResponse['file_info']['exist'] = True checkExistResponse['file_info']['is_synced'] = checkExistResponse['is_synced'] checkExistResponse['file_info']['unencrypted_sha1'] = Utils.sha1ForFile(localPath) ServerResourceAttribute.CreateTime[fileId] = checkExistResponse.get('created_at', time()) ServerResourceAttribute.ModifyTime[fileId] = checkExistResponse.get('modified_at', time()) response = checkExistResponse['file_info'] return self.__formatUploadNewFileResponse(response) except CheckSumExpiredException: self.__checkSumExpiredRecovery(localId1, localId2) raise OperationRetryException
def uploadNewFileVersionV2(self, localPath, tempFilePath, resourceId, sequenceId, description = 'UpdateNewVersion'): """ \xe8\xaf\xb4\xe6\x98\x8e: \xe4\xb8\x8a\xe4\xbc\xa0\xe6\x96\x87\xe4\xbb\xb6\xe6\x96\xb0\xe7\x89\x88\xe6\x9c\xac\xe6\x8e\xa5\xe5\x8f\xa3,\xe7\xbb\xbc\xe5\x90\x88\xe4\xba\x86\xe6\x96\x87\xe4\xbb\xb6\xe5\x88\x86\xe5\x9d\x97\xe4\xb8\x8a\xe4\xbc\xa0\xe5\x92\x8c\xe6\x96\x87\xe4\xbb\xb6\xe6\x99\xae\xe9\x80\x9a\xe4\xb8\x8a\xe4\xbc\xa0 @param localPath: @param tempFilePath: @param resourceId: @param sequenceId: @param description: @return: """ try: self.logger.debug('[Adapter] enter multiupload new version main process, file (%s)', localPath) self.treeDatabase.getResourceByServerId(resourceId) if os.path.exists(localPath): if localPath != tempFilePath: self.logger.debug('[Adapter] Copy local file (%s) to temp file (%s)', localPath, tempFilePath) shutil.copyfile(localPath, tempFilePath) else: raise WaitingOtherResourceException sha1 = Utils.sha1ForFile(localPath) treeResource = self.treeDatabase.getResourceByServerId(resourceId) localId1 = treeResource.local_id1 localId2 = treeResource.local_id2 self.__checkFileSha1(localId1, localId2, sha1) isInterruptUploadOrNot, uploadGetResponse = self.__isInterruptUpload(localId1, localId2) if isInterruptUploadOrNot: if uploadGetResponse.get('success', False): return self.__multiInterruptUploadNewFile(localPath, tempFilePath, localId1, localId2, uploadGetResponse, sha1) else: return uploadGetResponse else: isMultiUpLoadNewFileOrNot, response = self.__isMultiUploadNewVersionOrNot(localPath, -resourceId, sequenceId, sha1) if response.get('success', False) and isMultiUpLoadNewFileOrNot: return self.__multiUploadNewFileVersion(localPath, tempFilePath, resourceId, sequenceId, response, sha1) if response.get('success', False) and not isMultiUpLoadNewFileOrNot: self.logger.debug('[Adapter] upload new version in original way file (%s)', localPath) return self.__uploadNewFileVersionWithoutPresign(localPath, tempFilePath, response, description) return response except CheckSumExpiredException: self.__checkSumExpiredRecovery(localId1, localId2) raise OperationRetryException