diff --git a/app/ota_updater.py b/app/ota_updater.py index cf7b9b7..c225946 100644 --- a/app/ota_updater.py +++ b/app/ota_updater.py @@ -9,7 +9,9 @@ class OTAUpdater: def __init__(self, github_repo, github_src_dir='', module='', main_dir='main', new_version_dir='next', secrets_file=None, headers={}): self.http_client = HttpClient(headers=headers) - self.github_repo = github_repo.rstrip('/').replace('https://github.com/', '') + self.github_repo = github_repo.rstrip('/').replace('https://git.msb-co.ir/', '') + print('repo',self.github_repo) + self.github_src_dir = '' if len(github_src_dir) < 1 else github_src_dir.rstrip('/') + '/' self.module = module.rstrip('/') self.main_dir = main_dir @@ -122,10 +124,12 @@ class OTAUpdater: return '0.0' def get_latest_version(self): - latest_release = self.http_client.get('https://api.github.com/repos/{}/releases/latest'.format(self.github_repo)) + print('https://git.msb-co.ir/api/v1/repos/{}/releases/latest'.format(self.github_repo)) + latest_release = self.http_client.get('https://git.msb-co.ir/api/v1/repos/{}/releases/'.format(self.github_repo)) gh_json = latest_release.json() + print(latest_release) try: - version = gh_json['tag_name'] + version = gh_json[0]['tag_name'] except KeyError as e: raise ValueError( "Release not found: \n", @@ -141,7 +145,8 @@ class OTAUpdater: print('Version {} downloaded to {}'.format(version, self.modulepath(self.new_version_dir))) def _download_all_files(self, version, sub_dir=''): - url = 'https://api.github.com/repos/{}/contents{}{}{}?ref=refs/tags/{}'.format(self.github_repo, self.github_src_dir, self.main_dir, sub_dir, version) + url = 'https://git.msb-co.ir/api/v1/repos/{}/contents/{}{}'.format(self.github_repo, self.github_src_dir, self.main_dir, sub_dir) + print(url) gc.collect() file_list = self.http_client.get(url) file_list_json = file_list.json() @@ -150,7 +155,7 @@ class OTAUpdater: if file['type'] == 'file': gitPath = file['path'] print('\tDownloading: ', gitPath, 'to', path) - self._download_file(version, gitPath, path) + self._download_file(version, file['download_url'], path) elif file['type'] == 'dir': print('Creating dir', path) self.mkdir(path) @@ -160,7 +165,7 @@ class OTAUpdater: file_list.close() def _download_file(self, version, gitPath, path): - self.http_client.get('https://raw.githubusercontent.com/{}/{}/{}'.format(self.github_repo, version, gitPath), saveToFile=path) + self.http_client.get(gitPath, saveToFile=path) def _copy_secrets_file(self): if self.secrets_file: @@ -247,4 +252,6 @@ class OTAUpdater: def modulepath(self, path): - return self.module + '/' + path if self.module else path \ No newline at end of file + return self.module + '/' + path if self.module else path + +