Skip to content

Commit 5b23a8e

Browse files
author
Harsh Vora
committed
Edkrepo: Logger functionality without ui_functions
Signed-off-by: Harsh Vora [email protected]
1 parent 1f3fbeb commit 5b23a8e

31 files changed

+589
-358
lines changed

edkrepo/command_completion_edkrepo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
from edkrepo.common.edkrepo_exception import EdkrepoManifestNotFoundException
1919
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
2020
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo
21+
from edkrepo.common.logger import get_logger
2122
from edkrepo.config import config_factory
2223
from edkrepo.config.config_factory import get_workspace_manifest
24+
logger = get_logger()
2325

2426
def checkout(parsed_args, config):
2527
manifest = get_workspace_manifest()
26-
print(' '.join(combinations_in_manifest(manifest)))
28+
logger.info(' '.join(combinations_in_manifest(manifest)))
2729

2830
def current_combo(parsed_args, config):
2931
manifest = get_workspace_manifest()
30-
print(" [{}]".format(manifest.general_config.current_combo))
32+
logger.info(" [{}]".format(manifest.general_config.current_combo))
3133

3234
def checkout_pin(parsed_args, config):
3335
pins = []
@@ -56,11 +58,11 @@ def checkout_pin(parsed_args, config):
5658
pin = ManifestXml(pin_file)
5759
parse_output = sys.stdout.getvalue()
5860
sys.stdout = stdout
59-
if parsed_args.verbose and parse_output.strip() != '':
60-
print('Pin {} Parsing Errors: {}\n'.format(file, parse_output.strip()))
61+
if parse_output.strip() != '':
62+
logger.info('Pin {} Parsing Errors: {}\n'.format(file, parse_output.strip()), extra={'verbose': parsed_args.verbose})
6163
if pin.project_info.codename == manifest.project_info.codename:
6264
pins.append(file)
63-
print(' '.join(pins))
65+
logger.info(' '.join(pins), extra={'verbose': parsed_args.verbose})
6466

6567
# To add command completions for a new command, add an entry to this dictionary.
6668
command_completions = {
@@ -91,7 +93,7 @@ def main():
9193
except Exception as e:
9294
if parsed_args.verbose:
9395
traceback.print_exc()
94-
print("Error: {}".format(str(e)))
96+
logger.error("Error: {}".format(str(e)), extra={'verbose':parsed_args.verbose})
9597
return 1
9698
return 0
9799

edkrepo/commands/cache_command.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from edkrepo.commands.humble.cache_humble import UNABLE_TO_LOAD_MANIFEST, UNABLE_TO_PARSE_MANIFEST
1616
from edkrepo.common.common_cache_functions import add_missing_cache_repos
1717
from edkrepo.common.common_cache_functions import get_repo_cache_obj
18+
from edkrepo.common.logger import get_logger
1819
from edkrepo.common.edkrepo_exception import EdkrepoCacheException
1920
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_project_in_all_indices
2021
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import pull_all_manifest_repos
@@ -57,6 +58,7 @@ def get_metadata(self):
5758
return metadata
5859

5960
def run_command(self, args, config):
61+
logger = get_logger()
6062
# Process enable disable requests
6163
if args.disable:
6264
config['user_cfg_file'].set_caching_state(False)
@@ -65,7 +67,7 @@ def run_command(self, args, config):
6567

6668
# Get the current state now that we have processed enable/disable
6769
cache_state = config['user_cfg_file'].caching_state
68-
ui_functions.print_info_msg(CACHE_ENABLED.format(cache_state))
70+
logger.info(CACHE_ENABLED.format(cache_state))
6971
if not cache_state:
7072
return
7173

@@ -90,14 +92,14 @@ def run_command(self, args, config):
9092

9193
# Display all the cache information
9294
if args.info:
93-
ui_functions.print_info_msg(CACHE_INFO)
95+
logger.info(CACHE_INFO)
9496
info = cache_obj.get_cache_info(args.verbose)
9597
for item in info:
9698
ui_functions.print_info_msg(CACHE_INFO_LINE.format(item.path, item.remote, item.url))
9799

98100
# Do an update if requested
99101
if args.update:
100-
ui_functions.print_info_msg(CACHE_FETCH)
102+
logger.info(CACHE_FETCH)
101103
cache_obj.update_cache(verbose=True)
102104

103105
# Close the cache repos

edkrepo/commands/checkout_pin_command.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from edkrepo.commands.edkrepo_command import EdkrepoCommand, OverrideArgument, SourceManifestRepoArgument
1515
import edkrepo.commands.arguments.checkout_pin_args as arguments
1616
import edkrepo.commands.humble.checkout_pin_humble as humble
17+
from edkrepo.common.logger import get_logger
1718
from edkrepo.common.common_cache_functions import get_repo_cache_obj
1819
from edkrepo.common.common_repo_functions import sparse_checkout_enabled, reset_sparse_checkout, sparse_checkout
1920
from edkrepo.common.common_repo_functions import check_dirty_repos, checkout_repos, combinations_in_manifest
@@ -50,6 +51,7 @@ def get_metadata(self):
5051
return metadata
5152

5253
def run_command(self, args, config):
54+
logger = get_logger()
5355
workspace_path = get_workspace_path()
5456
manifest = get_workspace_manifest()
5557

@@ -74,15 +76,14 @@ def run_command(self, args, config):
7476
self.__pin_matches_project(pin, manifest, workspace_path)
7577
sparse_enabled = sparse_checkout_enabled(workspace_path, manifest_sources)
7678
if sparse_enabled:
77-
ui_functions.print_info_msg(SPARSE_RESET, header = False)
79+
logger.info(SPARSE_RESET)
7880
reset_sparse_checkout(workspace_path, manifest_sources)
7981
submodule_combo = pin.general_config.current_combo
8082
try:
8183
deinit_full(workspace_path, manifest, args.verbose)
8284
except Exception as e:
83-
ui_functions.print_error_msg(SUBMODULE_DEINIT_FAILED, header = False)
84-
if args.verbose:
85-
ui_functions.print_error_msg(e, header = False)
85+
logger.error(SUBMODULE_DEINIT_FAILED)
86+
logger.error(e, extra={'verbose':args.verbose})
8687
pin_repo_sources = pin.get_repo_sources(pin.general_config.current_combo)
8788
try:
8889
checkout_repos(args.verbose, args.override, pin_repo_sources, workspace_path, manifest)
@@ -94,7 +95,7 @@ def run_command(self, args, config):
9495
cache_path = cache_obj.get_cache_path(SUBMODULE_CACHE_REPO_NAME)
9596
maintain_submodules(workspace_path, pin, submodule_combo, args.verbose, cache_path)
9697
if sparse_enabled:
97-
ui_functions.print_info_msg(SPARSE_CHECKOUT, header = False)
98+
logger.info(SPARSE_CHECKOUT, header = False)
9899
sparse_checkout(workspace_path, pin_repo_sources, manifest)
99100

100101
def __get_pin_path(self, args, workspace_path, manifest_repo_path, manifest):
@@ -115,13 +116,13 @@ def __get_pin_path(self, args, workspace_path, manifest_repo_path, manifest):
115116
else:
116117
raise EdkrepoInvalidParametersException(humble.NOT_FOUND)
117118

118-
def __pin_matches_project(self, pin, manifest, workspace_path):
119+
def __pin_matches_project(self, logger, pin, manifest, workspace_path):
119120
if pin.project_info.codename != manifest.project_info.codename:
120121
raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH)
121122
elif not set(pin.remotes).issubset(set(manifest.remotes)):
122123
raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH)
123124
elif pin.general_config.current_combo not in combinations_in_manifest(manifest):
124-
ui_functions.print_warning_msg(humble.COMBO_NOT_FOUND.format(pin.general_config.current_combo), header = False)
125+
logger.warning(humble.COMBO_NOT_FOUND.format(pin.general_config.current_combo))
125126
combo_name = pin.general_config.current_combo
126127
pin_sources = pin.get_repo_sources(combo_name)
127128
pin_root_remote = {source.root:source.remote_name for source in pin_sources}

edkrepo/commands/clean_command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import edkrepo.commands.arguments.clean_args as arguments
1717
from edkrepo.config.config_factory import get_workspace_path, get_workspace_manifest
1818
import edkrepo.common.ui_functions as ui_functions
19+
from edkrepo.common.logger import get_logger
1920

2021
class CleanCommand(EdkrepoCommand):
2122
def __init__(self):
@@ -45,6 +46,7 @@ def get_metadata(self):
4546
return metadata
4647

4748
def run_command(self, args, config):
49+
logger = get_logger()
4850
workspace_path = get_workspace_path()
4951
manifest = get_workspace_manifest()
5052
manifest_config = manifest.general_config
@@ -57,4 +59,4 @@ def run_command(self, args, config):
5759
n=(not args.force),
5860
q=(args.quiet and args.force))
5961
if result:
60-
ui_functions.print_info_msg(result, header = False)
62+
logger.info(result)

edkrepo/commands/clone_command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
3030
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo
3131
from edkrepo.common.workspace_maintenance.humble.manifest_repos_maintenance_humble import PROJ_NOT_IN_REPO, SOURCE_MANIFEST_REPO_NOT_FOUND
32+
from edkrepo.common.logger import get_logger
3233
import edkrepo.common.ui_functions as ui_functions
3334
from edkrepo_manifest_parser.edk_manifest import CiIndexXml, ManifestXml
3435
from project_utils.submodule import maintain_submodules
@@ -74,6 +75,7 @@ def get_metadata(self):
7475

7576

7677
def run_command(self, args, config):
78+
logger = get_logger()
7779
pull_all_manifest_repos(config['cfg_file'], config['user_cfg_file'], False)
7880

7981
name_or_manifest = args.ProjectNameOrManifestFile
@@ -192,5 +194,5 @@ def run_command(self, args, config):
192194
# Command line disables sparse checkout
193195
use_sparse = False
194196
if use_sparse:
195-
ui_functions.print_info_msg(SPARSE_CHECKOUT)
197+
logger.info(SPARSE_CHECKOUT)
196198
sparse_checkout(workspace_dir, repo_sources_to_clone, manifest)

edkrepo/commands/combo_command.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edkrepo.commands.arguments.combo_args as arguments
1414
import edkrepo.common.ui_functions as ui_functions
1515
from edkrepo.config.config_factory import get_workspace_manifest
16+
from edkrepo.common.logger import get_logger
1617

1718

1819
class ComboCommand(EdkrepoCommand):
@@ -33,6 +34,7 @@ def get_metadata(self):
3334
return metadata
3435

3536
def run_command(self, args, config):
37+
logger = get_logger()
3638
manifest = get_workspace_manifest()
3739
combo_archive = []
3840
combo_list = [c.name for c in manifest.combinations]
@@ -43,13 +45,13 @@ def run_command(self, args, config):
4345
combo_list.append(manifest.general_config.current_combo)
4446
for combo in sorted(combo_list):
4547
if combo == manifest.general_config.current_combo:
46-
print("* {}{}{}".format(Fore.GREEN, combo, Fore.RESET))
48+
logger.info("* {}{}{}".format(Fore.GREEN, combo, Fore.RESET))
4749
elif combo in combo_archive:
48-
print(" {}{}{}{}".format(Fore.YELLOW, Style.BRIGHT, combo, Style.RESET_ALL))
50+
logger.info(" {}{}{}{}".format(Fore.YELLOW, Style.BRIGHT, combo, Style.RESET_ALL))
4951
else:
50-
ui_functions.print_info_msg(" {}".format(combo), header=False)
52+
logger.info(" {}".format(combo))
5153
if args.verbose:
5254
sources = manifest.get_repo_sources(combo)
5355
length = len(max([source.root for source in sources], key=len))
5456
for source in sources:
55-
ui_functions.print_info_msg(" {} : {}".format(source.root.ljust(length), source.branch), header=False)
57+
logger.info(" {} : {}".format(source.root.ljust(length), source.branch))

edkrepo/commands/create_pin_command.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import find_source_manifest_repo
2424
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import list_available_manifest_repos
2525
from edkrepo.common.workspace_maintenance.manifest_repos_maintenance import pull_workspace_manifest_repo
26+
from edkrepo.common.logger import get_logger
2627
from edkrepo.config.config_factory import get_workspace_manifest, get_workspace_path
2728
from edkrepo_manifest_parser.edk_manifest import ManifestXml
2829
import edkrepo.common.ui_functions as ui_functions
@@ -54,7 +55,7 @@ def get_metadata(self):
5455
return metadata
5556

5657
def run_command(self, args, config):
57-
58+
logger = get_logger()
5859
workspace_path = get_workspace_path()
5960
manifest = get_workspace_manifest()
6061

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

7576
# get the repo sources and commit ids for the pin
76-
ui_functions.print_info_msg(GENERATING_PIN_DATA.format(manifest.project_info.codename, manifest.general_config.current_combo), header = False)
77+
logger.info(GENERATING_PIN_DATA.format(manifest.project_info.codename, manifest.general_config.current_combo))
7778
updated_repo_sources = []
7879
for repo_source in repo_sources:
7980
local_repo_path = os.path.join(workspace_path, repo_source.root)
8081
if not os.path.exists(local_repo_path):
8182
raise EdkrepoWorkspaceCorruptException(MISSING_REPO.format(repo_source.root))
8283
repo = Repo(local_repo_path)
8384
commit_id = repo.head.commit.hexsha
84-
if args.verbose:
85-
ui_functions.print_info_msg(GENERATING_REPO_DATA.format(repo_source.root), header = False)
86-
ui_functions.print_info_msg(BRANCH.format(repo_source.branch), header = False)
87-
ui_functions.print_info_msg(COMMIT.format(commit_id), header = False)
85+
logger.info(GENERATING_REPO_DATA.format(repo_source.root), extra={'verbose':args.verbose})
86+
logger.info(BRANCH.format(repo_source.branch), extra={'verbose':args.verbose})
87+
logger.info(COMMIT.format(commit_id), extra={'verbose':args.verbose})
8888
updated_repo_source = repo_source._replace(commit=commit_id)
8989
updated_repo_sources.append(updated_repo_source)
9090

9191
# create the pin
92-
ui_functions.print_info_msg(WRITING_PIN_FILE.format(pin_file_name), header = False)
92+
logger.info(WRITING_PIN_FILE.format(pin_file_name))
9393
manifest.generate_pin_xml(args.Description, manifest.general_config.current_combo, updated_repo_sources,
9494
filename=pin_file_name)
9595

0 commit comments

Comments
 (0)