edkrepo/config/config_factory.py | 14 ++++++++------ edkrepo/config/config_humble.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 edkrepo/config/config_humble.py
Define and store config_config factory informational
and error strings in config/config_humble.py
Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
---
edkrepo/config/config_factory.py | 14 ++++++++------
edkrepo/config/config_humble.py | 14 ++++++++++++++
2 files changed, 22 insertions(+), 6 deletions(-)
create mode 100644 edkrepo/config/config_humble.py
diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py
index b86e0b8..d9eec87 100644
--- a/edkrepo/config/config_factory.py
+++ b/edkrepo/config/config_factory.py
@@ -11,12 +11,14 @@ import os
import sys
import configparser
import collections
+from ctypes import *
+
+import edkrepo.config.config_humble as humble
from edkrepo.common.edkrepo_exception import EdkrepoGlobalConfigNotFoundException, EdkrepoConfigFileInvalidException
from edkrepo.common.edkrepo_exception import EdkrepoWorkspaceInvalidException, EdkrepoGlobalDataDirectoryNotFoundException
from edkrepo.common.edkrepo_exception import EdkrepoConfigFileReadOnlyException
from edkrepo.common.humble import MIRROR_PRIMARY_REPOS_MISSING, MIRROR_DECODE_WARNING, MAX_PATCH_SET_INVALID
from edkrepo_manifest_parser import edk_manifest
-from ctypes import *
def get_edkrepo_global_data_directory():
global_data_dir = None
@@ -34,7 +36,7 @@ def get_edkrepo_global_data_directory():
global_data_dir = os.path.expanduser("~/.edkrepo")
if not os.path.isdir(global_data_dir):
if not os.path.exists(os.path.dirname(global_data_dir)):
- raise EdkrepoGlobalDataDirectoryNotFoundException("{} does not exist".format(os.path.dirname(global_data_dir)))
+ raise EdkrepoGlobalDataDirectoryNotFoundException(humble.GLOBAL_DATA_DIR_NOT_FOUND.format(os.path.dirname(global_data_dir)))
os.mkdir(global_data_dir)
return global_data_dir
@@ -63,7 +65,7 @@ def cfg_property(filename, cfg, read_only, section, key):
return cfg[section][key]
def _set(self, value):
if read_only:
- raise EdkrepoConfigFileReadOnlyException('The configuration file is read only: {}'.format(filename))
+ raise EdkrepoConfigFileReadOnlyException(humble.READ_ONLY_CFG.format(filename))
cfg[section][key] = value
with open(filename, 'w') as cfg_stream:
cfg.write(cfg_stream)
@@ -90,7 +92,7 @@ class BaseConfig():
if prop.section not in self.cfg or prop.key not in self.cfg[prop.section]:
if prop.required or self.read_only:
# Required property is missing
- raise EdkrepoConfigFileInvalidException('{} is not present in {} section of {}'.format(prop.key, prop.section, os.path.basename(self.filename)))
+ raise EdkrepoConfigFileInvalidException(humble.REQ_PROP_MISSING.format(prop.key, prop.section, os.path.basename(self.filename)))
if not self.read_only:
# Create the missing property
if prop.section not in self.cfg:
@@ -126,7 +128,7 @@ class GlobalConfig(BaseConfig):
CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True),
CfgProp('preferred-entry-point', 'entry-point', 'pref_entry_point', None, True)]
if not os.path.isfile(self.filename):
- raise EdkrepoGlobalConfigNotFoundException("edkrepo global config file {} does not exist".format(self.filename))
+ raise EdkrepoGlobalConfigNotFoundException(humble.GLOBAL_CFG_NOT_FOUND.format(self.filename))
super().__init__(self.filename, True)
@property
@@ -189,7 +191,7 @@ def get_workspace_path():
if os.path.dirname(path) == path:
break
path = os.path.dirname(path)
- raise EdkrepoWorkspaceInvalidException("The current directory does not appear to be a valid workspace")
+ raise EdkrepoWorkspaceInvalidException(humble.INVALID_WKSPC)
def get_workspace_manifest_file():
path = get_workspace_path()
diff --git a/edkrepo/config/config_humble.py b/edkrepo/config/config_humble.py
new file mode 100644
index 0000000..3b8335f
--- /dev/null
+++ b/edkrepo/config/config_humble.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+#
+## @file
+# config_humble.py
+#
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+GLOBAL_DATA_DIR_NOT_FOUND = '{} does not exist.'
+READ_ONLY_CFG = 'The configuration file is read only: {}'
+REQ_PROP_MISSING = '{} is not present in {} section of {}'
+GLOBAL_CFG_NOT_FOUND = 'The edkrepo global configuration file {} was not found.'
+INVALID_WKSPC = 'The current directory does not appear to be a valid workspace.'
\ No newline at end of file
--
2.16.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#57160): https://edk2.groups.io/g/devel/message/57160
Mute This Topic: https://groups.io/mt/72908964/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
I would prefer we match the pattern found in the commands directory. Something like import edkrepo.config.humble.config_factory as humble Thanks, Nate -----Original Message----- From: Desimone, Ashley E <ashley.e.desimone@intel.com> Sent: Thursday, April 9, 2020 3:33 PM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>; Bjorge, Erik C <erik.c.bjorge@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>; Agyeman, Prince <prince.agyeman@intel.com> Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Config_factory string clean up Define and store config_config factory informational and error strings in config/config_humble.py Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> Cc: Puja Pandya <puja.pandya@intel.com> Cc: Erik Bjorge <erik.c.bjorge@intel.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Prince Agyeman <prince.agyeman@intel.com> --- edkrepo/config/config_factory.py | 14 ++++++++------ edkrepo/config/config_humble.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 edkrepo/config/config_humble.py diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py index b86e0b8..d9eec87 100644 --- a/edkrepo/config/config_factory.py +++ b/edkrepo/config/config_factory.py @@ -11,12 +11,14 @@ import os import sys import configparser import collections +from ctypes import * + +import edkrepo.config.config_humble as humble from edkrepo.common.edkrepo_exception import EdkrepoGlobalConfigNotFoundException, EdkrepoConfigFileInvalidException from edkrepo.common.edkrepo_exception import EdkrepoWorkspaceInvalidException, EdkrepoGlobalDataDirectoryNotFoundException from edkrepo.common.edkrepo_exception import EdkrepoConfigFileReadOnlyException from edkrepo.common.humble import MIRROR_PRIMARY_REPOS_MISSING, MIRROR_DECODE_WARNING, MAX_PATCH_SET_INVALID from edkrepo_manifest_parser import edk_manifest -from ctypes import * def get_edkrepo_global_data_directory(): global_data_dir = None @@ -34,7 +36,7 @@ def get_edkrepo_global_data_directory(): global_data_dir = os.path.expanduser("~/.edkrepo") if not os.path.isdir(global_data_dir): if not os.path.exists(os.path.dirname(global_data_dir)): - raise EdkrepoGlobalDataDirectoryNotFoundException("{} does not exist".format(os.path.dirname(global_data_dir))) + raise + EdkrepoGlobalDataDirectoryNotFoundException(humble.GLOBAL_DATA_DIR_NOT + _FOUND.format(os.path.dirname(global_data_dir))) os.mkdir(global_data_dir) return global_data_dir @@ -63,7 +65,7 @@ def cfg_property(filename, cfg, read_only, section, key): return cfg[section][key] def _set(self, value): if read_only: - raise EdkrepoConfigFileReadOnlyException('The configuration file is read only: {}'.format(filename)) + raise + EdkrepoConfigFileReadOnlyException(humble.READ_ONLY_CFG.format(filenam + e)) cfg[section][key] = value with open(filename, 'w') as cfg_stream: cfg.write(cfg_stream) @@ -90,7 +92,7 @@ class BaseConfig(): if prop.section not in self.cfg or prop.key not in self.cfg[prop.section]: if prop.required or self.read_only: # Required property is missing - raise EdkrepoConfigFileInvalidException('{} is not present in {} section of {}'.format(prop.key, prop.section, os.path.basename(self.filename))) + raise + EdkrepoConfigFileInvalidException(humble.REQ_PROP_MISSING.format(prop. + key, prop.section, os.path.basename(self.filename))) if not self.read_only: # Create the missing property if prop.section not in self.cfg: @@ -126,7 +128,7 @@ class GlobalConfig(BaseConfig): CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True), CfgProp('preferred-entry-point', 'entry-point', 'pref_entry_point', None, True)] if not os.path.isfile(self.filename): - raise EdkrepoGlobalConfigNotFoundException("edkrepo global config file {} does not exist".format(self.filename)) + raise + EdkrepoGlobalConfigNotFoundException(humble.GLOBAL_CFG_NOT_FOUND.forma + t(self.filename)) super().__init__(self.filename, True) @property @@ -189,7 +191,7 @@ def get_workspace_path(): if os.path.dirname(path) == path: break path = os.path.dirname(path) - raise EdkrepoWorkspaceInvalidException("The current directory does not appear to be a valid workspace") + raise EdkrepoWorkspaceInvalidException(humble.INVALID_WKSPC) def get_workspace_manifest_file(): path = get_workspace_path() diff --git a/edkrepo/config/config_humble.py b/edkrepo/config/config_humble.py new file mode 100644 index 0000000..3b8335f --- /dev/null +++ b/edkrepo/config/config_humble.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# +## @file +# config_humble.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> # +SPDX-License-Identifier: BSD-2-Clause-Patent # + +GLOBAL_DATA_DIR_NOT_FOUND = '{} does not exist.' +READ_ONLY_CFG = 'The configuration file is read only: {}' +REQ_PROP_MISSING = '{} is not present in {} section of {}' +GLOBAL_CFG_NOT_FOUND = 'The edkrepo global configuration file {} was not found.' +INVALID_WKSPC = 'The current directory does not appear to be a valid workspace.' \ No newline at end of file -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#57216): https://edk2.groups.io/g/devel/message/57216 Mute This Topic: https://groups.io/mt/72908964/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.