Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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
if self.__downloader[:5] == const.DownloaderAria2:
result = self.__down_aria2c(rfile, localfile)
else:
result = self.__downchunks(rfile, offset)
if result == const.ENoError:
self.__remove_remote_on_success(remotefile)
return result
def __prepare_local_dir(self, localdir):
result = const.ENoError
if os.path.isfile(localdir):
result = removefile(localdir, self.verbose)
if result == const.ENoError:
if localdir and not os.path.exists(localdir):
result = makedir(localdir, verbose = self.verbose)
return result
def __syncdown_diff_one(self, rpath, localdir, d):
result = const.ENoError
t = d[0]
p = d[1]
#lcpath = os.path.join(localdir, p) # local complete path
lcpath = joinpath(localdir, p) # local complete path
rcpath = rpath + '/' + p # remote complete path
if t == 'DF':
result = removedir(lcpath, self.verbose)
subresult = self.__downfile(rcpath, lcpath)
if subresult != const.ENoError:
result = subresult
elif t == 'FD':
result = removefile(lcpath, self.verbose)
subresult = makedir(lcpath, verbose = self.verbose)
if subresult != const.ENoError:
result = subresult
else: # " t == 'F' " must be true
result = self.__downfile(rcpath, lcpath)
return result
def __syncdown_remote_one(self, rpath, localdir, r):
result = const.ENoError
t = r[0]
p = r[1]
#lcpath = os.path.join(localdir, p) # local complete path
lcpath = joinpath(localdir, p) # local complete path
rcpath = rpath + '/' + p # remote complete path
if t == 'F':
subresult = self.__downfile(rcpath, lcpath)
if subresult != const.ENoError:
result = subresult
else: # " t == 'D' " must be true
subresult = makedir(lcpath, verbose = self.verbose)
if subresult != const.ENoError:
result = subresult
return result
def migratesettings():
result = const.ENoError
if os.path.exists(const.OldByPyCertsPath):
removefile(const.OldByPyCertsPath)
filesToMove = [
[const.OldTokenFilePath, const.TokenFilePath],
[const.OldPicklePath, const.PicklePath]
]
result = makedir(const.ConfigDir, 0o700) and result # make it secretive
# this directory must exist
if result != const.ENoError:
perr("Fail to create config directory '{}'".format(const.ConfigDir))
return result
for tomove in filesToMove:
oldfile = tomove[0]
newfile = tomove[1]
if os.path.exists(oldfile):
dst = newfile
if os.path.exists(newfile):
dst = dst + '.old'
result = movefile(oldfile, dst) and result
# we move to JSON for hash caching for better portability
# http://www.benfrederickson.com/dont-pickle-your-data/