Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edkrepo: Logger functionality without ui_functions #105

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions edkrepo/command_completion_edkrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
from edkrepo.common.edkrepo_exception import EdkrepoManifestNotFoundException
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo
from edkrepo.common.logger import get_logger
from edkrepo.config import config_factory
from edkrepo.config.config_factory import get_workspace_manifest
logger = get_logger()

def checkout(parsed_args, config):
manifest = get_workspace_manifest()
print(' '.join(combinations_in_manifest(manifest)))
logger.info(' '.join(combinations_in_manifest(manifest)))

def current_combo(parsed_args, config):
manifest = get_workspace_manifest()
print(" [{}]".format(manifest.general_config.current_combo))
logger.info(" [{}]".format(manifest.general_config.current_combo))

def checkout_pin(parsed_args, config):
pins = []
Expand Down Expand Up @@ -56,11 +58,11 @@ def checkout_pin(parsed_args, config):
pin = ManifestXml(pin_file)
parse_output = sys.stdout.getvalue()
sys.stdout = stdout
if parsed_args.verbose and parse_output.strip() != '':
print('Pin {} Parsing Errors: {}\n'.format(file, parse_output.strip()))
if parse_output.strip() != '':
logger.info('Pin {} Parsing Errors: {}\n'.format(file, parse_output.strip()), extra={'verbose': parsed_args.verbose})
if pin.project_info.codename == manifest.project_info.codename:
pins.append(file)
print(' '.join(pins))
logger.info(' '.join(pins), extra={'verbose': parsed_args.verbose})

# To add command completions for a new command, add an entry to this dictionary.
command_completions = {
Expand Down Expand Up @@ -91,7 +93,7 @@ def main():
except Exception as e:
if parsed_args.verbose:
traceback.print_exc()
print("Error: {}".format(str(e)))
logger.error("Error: {}".format(str(e)), extra={'verbose':parsed_args.verbose})
return 1
return 0

Expand Down
9 changes: 5 additions & 4 deletions edkrepo/commands/cache_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from edkrepo.commands.humble.cache_humble import UNABLE_TO_LOAD_MANIFEST, UNABLE_TO_PARSE_MANIFEST
from edkrepo.common.common_cache_functions import add_missing_cache_repos
from edkrepo.common.common_cache_functions import get_repo_cache_obj
from edkrepo.common.logger import get_logger
from edkrepo.common.edkrepo_exception import EdkrepoCacheException
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_project_in_all_indices
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import pull_all_manifest_repos
Expand Down Expand Up @@ -70,6 +71,7 @@ def get_metadata(self):
return metadata

def run_command(self, args, config):
logger = get_logger()
if not args.info:
# Process enable disable requests
if args.disable:
Expand All @@ -85,8 +87,7 @@ def run_command(self, args, config):

# Get the current state now that we have processed enable/disable
cache_state = config['user_cfg_file'].caching_state

ui_functions.print_info_msg(CACHE_ENABLED.format(cache_state))
logger.info(CACHE_ENABLED.format(cache_state))
if not cache_state:
return
# State is enabled so make sure cache directory exists
Expand All @@ -110,7 +111,7 @@ def run_command(self, args, config):

# Display all the cache information
if args.info:
ui_functions.print_info_msg(CACHE_INFO)
logger.info(CACHE_INFO)
info = cache_obj.get_cache_info(args.verbose)
if args.format == 'json':
cache_json_out = _create_cache_json_object(info)
Expand All @@ -121,7 +122,7 @@ def run_command(self, args, config):

# Do an update if requested
if args.update:
ui_functions.print_info_msg(CACHE_FETCH)
logger.info(CACHE_FETCH)
cache_obj.update_cache(verbose=True)

# Close the cache repos
Expand Down
15 changes: 8 additions & 7 deletions edkrepo/commands/checkout_pin_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from edkrepo.commands.edkrepo_command import EdkrepoCommand, OverrideArgument, SourceManifestRepoArgument
import edkrepo.commands.arguments.checkout_pin_args as arguments
import edkrepo.commands.humble.checkout_pin_humble as humble
from edkrepo.common.logger import get_logger
from edkrepo.common.common_cache_functions import get_repo_cache_obj
from edkrepo.common.common_repo_functions import sparse_checkout_enabled, reset_sparse_checkout, sparse_checkout
from edkrepo.common.common_repo_functions import check_dirty_repos, checkout_repos, combinations_in_manifest
Expand Down Expand Up @@ -50,6 +51,7 @@ def get_metadata(self):
return metadata

def run_command(self, args, config):
logger = get_logger()
workspace_path = get_workspace_path()
manifest = get_workspace_manifest()

Expand All @@ -74,15 +76,14 @@ def run_command(self, args, config):
self.__pin_matches_project(pin, manifest, workspace_path)
sparse_enabled = sparse_checkout_enabled(workspace_path, manifest_sources)
if sparse_enabled:
ui_functions.print_info_msg(SPARSE_RESET, header = False)
logger.info(SPARSE_RESET)
reset_sparse_checkout(workspace_path, manifest_sources)
submodule_combo = pin.general_config.current_combo
try:
deinit_full(workspace_path, manifest, args.verbose)
except Exception as e:
ui_functions.print_error_msg(SUBMODULE_DEINIT_FAILED, header = False)
if args.verbose:
ui_functions.print_error_msg(e, header = False)
logger.error(SUBMODULE_DEINIT_FAILED)
logger.error(e, extra={'verbose':args.verbose})
pin_repo_sources = pin.get_repo_sources(pin.general_config.current_combo)
try:
checkout_repos(args.verbose, args.override, pin_repo_sources, workspace_path, manifest)
Expand All @@ -94,7 +95,7 @@ def run_command(self, args, config):
cache_path = cache_obj.get_cache_path(SUBMODULE_CACHE_REPO_NAME)
maintain_submodules(workspace_path, pin, submodule_combo, args.verbose, cache_path)
if sparse_enabled:
ui_functions.print_info_msg(SPARSE_CHECKOUT, header = False)
logger.info(SPARSE_CHECKOUT, header = False)
sparse_checkout(workspace_path, pin_repo_sources, manifest)

def __get_pin_path(self, args, workspace_path, manifest_repo_path, manifest):
Expand All @@ -115,13 +116,13 @@ def __get_pin_path(self, args, workspace_path, manifest_repo_path, manifest):
else:
raise EdkrepoInvalidParametersException(humble.NOT_FOUND)

def __pin_matches_project(self, pin, manifest, workspace_path):
def __pin_matches_project(self, logger, pin, manifest, workspace_path):
if pin.project_info.codename != manifest.project_info.codename:
raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH)
elif not set(pin.remotes).issubset(set(manifest.remotes)):
raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH)
elif pin.general_config.current_combo not in combinations_in_manifest(manifest):
ui_functions.print_warning_msg(humble.COMBO_NOT_FOUND.format(pin.general_config.current_combo), header = False)
logger.warning(humble.COMBO_NOT_FOUND.format(pin.general_config.current_combo))
combo_name = pin.general_config.current_combo
pin_sources = pin.get_repo_sources(combo_name)
pin_root_remote = {source.root:source.remote_name for source in pin_sources}
Expand Down
4 changes: 3 additions & 1 deletion edkrepo/commands/clean_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import edkrepo.commands.arguments.clean_args as arguments
from edkrepo.config.config_factory import get_workspace_path, get_workspace_manifest
import edkrepo.common.ui_functions as ui_functions
from edkrepo.common.logger import get_logger

class CleanCommand(EdkrepoCommand):
def __init__(self):
Expand Down Expand Up @@ -45,6 +46,7 @@ def get_metadata(self):
return metadata

def run_command(self, args, config):
logger = get_logger()
workspace_path = get_workspace_path()
manifest = get_workspace_manifest()
manifest_config = manifest.general_config
Expand All @@ -57,4 +59,4 @@ def run_command(self, args, config):
n=(not args.force),
q=(args.quiet and args.force))
if result:
ui_functions.print_info_msg(result, header = False)
logger.info(result)
4 changes: 3 additions & 1 deletion edkrepo/commands/clone_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo, get_manifest_repo_path
from edkrepo.common.workspace_maintenance.humble.manifest_repos_maintenance_humble import PROJ_NOT_IN_REPO, SOURCE_MANIFEST_REPO_NOT_FOUND
from edkrepo.common.logger import get_logger
import edkrepo.common.ui_functions as ui_functions
from edkrepo_manifest_parser.edk_manifest import ManifestXml
from project_utils.submodule import maintain_submodules
Expand Down Expand Up @@ -74,6 +75,7 @@ def get_metadata(self):


def run_command(self, args, config):
logger = get_logger()
pull_all_manifest_repos(config['cfg_file'], config['user_cfg_file'], False)

workspace_dir = args.Workspace
Expand Down Expand Up @@ -199,5 +201,5 @@ def run_command(self, args, config):
# Command line disables sparse checkout
use_sparse = False
if use_sparse:
ui_functions.print_info_msg(SPARSE_CHECKOUT)
logger.info(SPARSE_CHECKOUT)
sparse_checkout(workspace_dir, repo_sources_to_clone, manifest)
12 changes: 7 additions & 5 deletions edkrepo/commands/combo_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edkrepo.commands.arguments.combo_args as arguments
import edkrepo.common.ui_functions as ui_functions
from edkrepo.config.config_factory import get_workspace_manifest
from edkrepo.common.logger import get_logger


class ComboCommand(EdkrepoCommand):
Expand All @@ -33,6 +34,7 @@ def get_metadata(self):
return metadata

def run_command(self, args, config):
logger = get_logger()
manifest = get_workspace_manifest()
combo_archive = []
combo_list = [c.name for c in manifest.combinations]
Expand All @@ -43,16 +45,16 @@ def run_command(self, args, config):
combo_list.append(manifest.general_config.current_combo)
for combo in sorted(combo_list):
if combo == manifest.general_config.current_combo:
print("* {}{}{}".format(Fore.GREEN, combo, Fore.RESET))
logger.info("* {}{}{}".format(Fore.GREEN, combo, Fore.RESET))
elif combo in combo_archive:
print(" {}{}{}{}".format(Fore.YELLOW, Style.BRIGHT, combo, Style.RESET_ALL))
logger.info(" {}{}{}{}".format(Fore.YELLOW, Style.BRIGHT, combo, Style.RESET_ALL))
else:
ui_functions.print_info_msg(" {}".format(combo), header=False)
logger.info(" {}".format(combo))
if args.verbose:
sources = manifest.get_repo_sources(combo)
length = len(max([source.root for source in sources], key=len))
for source in sources:
if source.branch:
ui_functions.print_info_msg(" {} : {}".format(source.root.ljust(length), source.branch), header=False)
logger.info(" {} : {}".format(source.root.ljust(length), source.branch))
elif source.patch_set:
ui_functions.print_info_msg(" {} : {}".format(source.root.ljust(length), source.patch_set), header=False)
logger.info(" {} : {}".format(source.root.ljust(length), source.patch_set))
14 changes: 7 additions & 7 deletions edkrepo/commands/create_pin_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import pull_workspace_manifest_repo
from edkrepo.common.logger import get_logger
from edkrepo.config.config_factory import get_workspace_manifest, get_workspace_path
from edkrepo_manifest_parser.edk_manifest import ManifestXml
import edkrepo.common.ui_functions as ui_functions
Expand Down Expand Up @@ -54,7 +55,7 @@ def get_metadata(self):
return metadata

def run_command(self, args, config):

logger = get_logger()
workspace_path = get_workspace_path()
manifest = get_workspace_manifest()

Expand All @@ -73,23 +74,22 @@ def run_command(self, args, config):
repo_sources = manifest.get_repo_sources(manifest.general_config.current_combo)

# get the repo sources and commit ids for the pin
ui_functions.print_info_msg(GENERATING_PIN_DATA.format(manifest.project_info.codename, manifest.general_config.current_combo), header = False)
logger.info(GENERATING_PIN_DATA.format(manifest.project_info.codename, manifest.general_config.current_combo))
updated_repo_sources = []
for repo_source in repo_sources:
local_repo_path = os.path.join(workspace_path, repo_source.root)
if not os.path.exists(local_repo_path):
raise EdkrepoWorkspaceCorruptException(MISSING_REPO.format(repo_source.root))
repo = Repo(local_repo_path)
commit_id = repo.head.commit.hexsha
if args.verbose:
ui_functions.print_info_msg(GENERATING_REPO_DATA.format(repo_source.root), header = False)
ui_functions.print_info_msg(BRANCH.format(repo_source.branch), header = False)
ui_functions.print_info_msg(COMMIT.format(commit_id), header = False)
logger.info(GENERATING_REPO_DATA.format(repo_source.root), extra={'verbose':args.verbose})
logger.info(BRANCH.format(repo_source.branch), extra={'verbose':args.verbose})
logger.info(COMMIT.format(commit_id), extra={'verbose':args.verbose})
updated_repo_source = repo_source._replace(commit=commit_id)
updated_repo_sources.append(updated_repo_source)

# create the pin
ui_functions.print_info_msg(WRITING_PIN_FILE.format(pin_file_name), header = False)
logger.info(WRITING_PIN_FILE.format(pin_file_name))
manifest.generate_pin_xml(args.Description, manifest.general_config.current_combo, updated_repo_sources,
filename=pin_file_name)

Loading