def get_list() -> list: """ returns list of repositories Returns: list[Repo]: list of loaded repositories """ repos = [] files = [Env.repos_config()] for item in os.listdir(Env.repos_config_dir()): if os.path.isfile(Env.repos_config_dir('/' + item)): files.append(Env.repos_config_dir('/' + item)) for fl in files: f = open(fl, 'r') repos_content = f.read() f.close() lines = repos_content.split('\n') line_counter = 1 for line in lines: line = line.split('#')[0].strip() line = line.strip() if line != '': repo = Repo(line) repo.line_number = line_counter repo.loaded_from_file = fl repos.append(repo) line_counter += 1 # sort by priority sorted_repos = [] while len(repos): i = 0 while i < len(repos): is_less_than_all = True j = 0 while j < len(repos): if int(repos[i].priority) > int(repos[j].priority): is_less_than_all = False j += 1 if is_less_than_all: sorted_repos.append(repos[i]) repos.pop(i) i += 1 return sorted_repos
def run(self): """ Run command """ if self.has_option('--edit') or self.has_option('-e'): return os.system('vim "' + Env.repos_config() + '"') if self.has_option('--add') or self.has_option('-a'): RootRequired.require_root_permission() repo_string = '' for arg in self.arguments: repo_string += arg + ' ' repo_string = repo_string.strip() tmp_repo = Repo(repo_string) tmp_repo.loaded_from_file = 'argument' tmp_repo.line_number = 0 if not tmp_repo.successful_loaded: ReposListErrorShower.show([tmp_repo]) return 1 # write repo path = Env.repos_config_dir('/' + tmp_repo.name + '-' + tmp_repo.get_pkg_str() + '-' + tmp_repo.get_arch_str()) tmp = '' tmp_i = 1 while os.path.isfile(path + tmp): tmp = '-' + str(tmp_i) f = open(path, 'w') f.write('# added manually\n' + repo_string) f.close() return 0 if self.has_option('--scan'): for arg in self.arguments: if os.path.isdir(arg): Scanner.scan(arg) pr.p(ansi.green + 'directory ' + arg + ' scanned successfully' + ansi.reset) else: self.message('directory' + arg + ' not found', is_error=True) return 0 # show list of repos if not self.is_quiet(): pr.p('Loading repositories list...') repos = Repo.get_list() if not self.is_quiet(): pr.p('============================') ReposListErrorShower.show(repos) for repo in repos: if repo.successful_loaded: is_disable = '' if repo.is_disable: is_disable = ' (Disabled)' pr.p(repo.name + ': ' + repo.url + ' pkg=' + repo.get_pkg_str() + ' arch=' + repo.get_arch_str() + ' channel=' + repo.get_channel_str() + is_disable)