def stage_repository(self, url):
local = os.path.join(self._updater_path,"update_staging")
error = None
# make/clear the staging folder
# ensure the folder is always "clean"
if self._verbose: print("Preparing staging folder for download:\n",local)
if os.path.isdir(local) == True:
try:
shutil.rmtree(local)
os.makedirs(local)
except:
error = "failed to remove existing staging directory"
else:
try:
os.makedirs(local)
except:
error = "failed to create staging directory"
if error != None:
if self._verbose: print("Error: Aborting update, "+error)
self._error = "Update aborted, staging path error"
self._error_msg = "Error: {}".format(error)
return False
if self._backup_current==True:
self.create_backup()
if self._verbose: print("Now retrieving the new source zip")
self._source_zip = os.path.join(local,"source.zip")
if self._verbose: print("Starting download update zip")
try:
request = urllib.request.Request(url)
# setup private token if appropriate
if self._engine.token != None:
if self._engine.name == "gitlab":
request.add_header('PRIVATE-TOKEN',self._engine.token)
else:
if self._verbose: print("Tokens not setup for selected engine yet")
self.urlretrieve(urllib.request.urlopen(request), self._source_zip)
# add additional checks on file size being non-zero
if self._verbose: print("Successfully downloaded update zip")
return True
except Exception as e:
self._error = "Error retrieving download, bad link?"
self._error_msg = "Error: {}".format(e)
if self._verbose:
print("Error retrieving download, bad link?")
print("Error: {}".format(e))
return False
评论列表
文章目录