aptly_deb_usage: Add quiet mode for list_local/list_remote

list_local/list_remote always outputs "info" level messages for
interactive usage. While those messages seems verbose in other
use cases. Add a "quiet" parameter to make it.

Story: 2008846
Task: 43692

Change-Id: If492e40d74d2433d5809b6628deaf0bd20fc1186
Signed-off-by: Zhang Xiao <xiao.zhang@windriver.com>
This commit is contained in:
Zhang Xiao 2021-10-17 20:16:07 -07:00 committed by ZhangXiao
parent 3f204f860f
commit 5d35fe941f
2 changed files with 20 additions and 15 deletions

View File

@ -251,17 +251,20 @@ class Deb_aptly():
return None
# info all remote repositories through logger
def list_remotes(self):
def list_remotes(self, quiet=False):
'''List all remote repositories/mirrors.'''
r_list = []
remote_list = self.aptly.mirrors.list()
if not len(remote_list):
self.logger.info('No remote repo')
if not quiet:
self.logger.info('No remote repo')
return r_list
self.logger.info('%d remotes:', len(remote_list))
if not quiet:
self.logger.info('%d remotes:', len(remote_list))
for remote in remote_list:
r_list.append(remote.name)
self.logger.info('%s : %s : %s', remote.name, remote.archive_root, remote.distribution)
if not quiet:
self.logger.info('%s : %s : %s', remote.name, remote.archive_root, remote.distribution)
return r_list
# find and remove a remote
@ -305,18 +308,20 @@ class Deb_aptly():
return True
# info all local repositories through logger
def list_local(self):
def list_local(self, quiet=False):
'''List all local repository.'''
local_list = []
repo_list = self.aptly.repos.list()
if not len(repo_list):
self.logger.info('No local repo')
return local_list
self.logger.info('%d local repos:', len(repo_list))
if not quiet:
self.logger.info('%d local repos:', len(repo_list))
for repo in repo_list:
# rpo.name, repo.url, repo.distributions, repo.components
local_list.append(repo.name)
self.logger.info('%s : %s : %s', repo.name, repo.default_distribution, repo.default_component)
if not quiet:
self.logger.info('%s : %s : %s', repo.name, repo.default_distribution, repo.default_component)
return local_list
# Create a local repository

View File

@ -347,8 +347,8 @@ class RepoMgr():
if not deb_list and not dsc_list:
raise Exception('deb_list and dsc_list, at least one is required.')
# construct repo list will be checkd
local_list = self.repo.list_local()
remote_list = self.repo.list_remotes()
local_list = self.repo.list_local(quiet=True)
remote_list = self.repo.list_remotes(quiet=True)
# Specified local repo must exist, or failed
if repo_name not in local_list:
raise Exception('Sync failed, local repo not exist, create it firstly')
@ -426,8 +426,8 @@ class RepoMgr():
# Output: Ture is all works in order
def remove_repo(self, repo_name):
'''Remove a specified repository.'''
local_list = self.repo.list_local()
remote_list = self.repo.list_remotes()
local_list = self.repo.list_local(quiet=True)
remote_list = self.repo.list_remotes(quiet=True)
for repo in local_list:
if repo == repo_name:
self.logger.info('Remove a local repo')
@ -448,7 +448,7 @@ class RepoMgr():
def upload_pkg(self, repo_name, package):
'''Upload a Debian package into a specified repository.'''
repo_exist = False
local_list = self.repo.list_local(True)
local_list = self.repo.list_local(quiet=True)
for repo in local_list:
if repo == repo_name:
repo_exist = True
@ -487,11 +487,11 @@ class RepoMgr():
'''Find a package from a specified repo.'''
repo_find = False
repo = None
r_list = self.repo.list_local(True)
r_list = self.repo.list_local(quiet=True)
for repo in r_list:
if repo == repo_name:
repo_find = True
r_list = self.repo.list_remotes(True)
r_list = self.repo.list_remotes(quiet=True)
for repo in r_list:
if repo == repo_name:
repo_find = True
@ -517,7 +517,7 @@ class RepoMgr():
'''Find and delete a binary package from a specified local repo.'''
repo_find = False
repo = None
local_list = self.repo.list_local()
local_list = self.repo.list_local(quiet=True)
for repo in local_list:
if repo == repo_name:
repo_find = True