Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.__resumedownload and \
self.__compare_size(self.__current_file_size, self.__remote_json) == 2:
if self.__resumedl_revertcount < 0:
if self.__current_file_size:
offset = self.__current_file_size
else:
# revert back at least self.__resumedl_revertcount download chunk(s), default: one
pieces = self.__current_file_size // self.__dl_chunk_size
if pieces > self.__resumedl_revertcount:
offset = (pieces - self.__resumedl_revertcount) * self.__dl_chunk_size
elif os.path.isdir(localfile):
if not self.shalloverwrite("Same-name directory '{}' exists, "
"do you want to remove it? [y/N]".format(localfile)):
pinfo("Same-name directory '{}' exists, skip downloading".format(localfile))
#return const.ENoError
return const.ESkipped
self.pv("Directory with the same name '{}' exists, removing ...".format(localfile))
result = removedir(localfile, self.verbose)
if result == const.ENoError:
self.pv("Removed")
else:
perr("Error removing the directory '{}'".format(localfile))
return result
ldir, file = os.path.split(localfile)
if ldir and not os.path.exists(ldir):
result = makedir(ldir, verbose = self.verbose)
if result != const.ENoError:
perr("Fail to make directory '{}'".format(ldir))
return result
def __downfile(self, remotefile, localfile):
# TODO: this is a quick patch
if not self.__shallinclude(localfile, remotefile, False):
# since we are not going to download it, there is no error
#return const.ENoError
return const.ESkipped
result = const.ENoError
rfile = remotefile
self.__remote_json = {}
self.pd("Downloading '{}' as '{}'".format(rfile, localfile))
self.__current_file = localfile
#if self.__verify or self.__resumedownload:
self.pd("Getting info of remote file '{}' for later verification".format(rfile))
result = self.__get_file_info(rfile)
if result != const.ENoError:
return result
offset = 0
self.pd("Checking if we already have the copy locally")
if os.path.isfile(localfile):
def __upload_file(self, localpath, remotepath, ondup = 'overwrite'):
# TODO: this is a quick patch
if not self.__shallinclude(localpath, remotepath, True):
# since we are not going to upload it, there is no error
#return const.ENoError
return const.ESkipped
self.__current_file = localpath
self.__current_file_size = getfilesize(localpath)
result = const.ENoError
if self.__current_file_size > const.MinRapidUploadFileSize:
self.pd("'{}' is being RapidUploaded.".format(self.__current_file))
result = self.__rapidupload_file(localpath, remotepath, ondup)
if result == const.ENoError:
self.pv("RapidUpload: '{}' =R=> '{}' OK.".format(localpath, remotepath))
self.__rapiduploaded = True
else:
self.__rapiduploaded = False
if not self.__rapiduploadonly:
self.pd("'{}' can't be RapidUploaded, now trying normal uploading.".format(
self.__current_file))
result = self.__upload_one_file(localpath, remotepath, ondup)
elif self.__current_file_size <= const.MaxSliceSize * const.MaxSlicePieces:
# slice them using slice size
self.pd("'{}' is being slicing uploaded.".format(self.__current_file))
result = self.__upload_file_slices(localpath, remotepath, ondup)
else:
result = const.EFileTooBig
perr("Error: size of file '{}' - {} is too big".format(
self.__current_file,
self.__current_file_size))
else:
self.pv("'{}' can't be rapidly uploaded, so it's skipped since we are in the rapid-upload-only mode.".format(localpath))
result = const.ESkipped
elif self.__rapiduploadonly:
self.pv("'{}' is too small to be rapidly uploaded, so it's skipped since we are in the rapid-upload-only mode.".format(localpath))
result = const.ESkipped
else:
# very small file, must be uploaded manually and no slicing is needed
self.pd("'{}' is small and being non-slicing uploaded.".format(self.__current_file))
result = self.__upload_one_file(localpath, remotepath, ondup)
if result == const.ENoError:
self.__remove_local_on_success(localpath)
return result
def __mkdir(self, rpath, **kwargs):
# TODO: this is a quick patch
# the code still works because Baidu Yun doesn't require
# parent directory to exist remotely to upload / create a file
if not self.__shallinclude('.', rpath, True):
#return const.ENoError
return const.ESkipped
self.pd("Making remote directory '{}'".format(rpath))
pars = {
'method' : 'mkdir',
'path' : rpath }
return self.__post(pcsurl + 'file', pars, self.__mkdir_act, **kwargs)