Ejegg has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/344057 )
Change subject: Comments and cleanup for config
......................................................................
Comments and cleanup for config
Change-Id: Ia1afe7fe3770866d33781a4cd4626a46a5aae09a
---
M processcontrol/config.py
1 file changed, 17 insertions(+), 7 deletions(-)
Approvals:
jenkins-bot: Verified
Awight: Looks good to me, approved
diff --git a/processcontrol/config.py b/processcontrol/config.py
index d58cd8f..79117f7 100644
--- a/processcontrol/config.py
+++ b/processcontrol/config.py
@@ -1,4 +1,4 @@
-import glob
+import copy
import os
import yaml
@@ -9,6 +9,13 @@
self.values = defaults
def get(self, path, default=None):
+ """Get a value from configuration.
+ You can get a nested property by using a path delimited by
+ forward slashes (/).
+ If you provide a default value, it will be used when the
+ desired property does not exist. If there is no default,
+ trying to get a missing property raises a MissingKeyException.
+ """
parts = path.split("/")
current = self.values
@@ -21,6 +28,9 @@
return current
def has(self, path):
+ """Test for existance of a property.
+ As with get(), use forward slashes to represent nested properties.
+ """
try:
self.get(path)
except MissingKeyException:
@@ -50,11 +60,11 @@
]
def load_global_config(self):
- # load configuration from global config paths
- # later entries override earlier entries
- for search_path in self.global_config_paths():
- file_paths = glob.glob(search_path)
- for file_path in file_paths:
+ """Load configuration from global config paths.
+ Later entries override earlier entries.
+ """
+ for file_path in self.global_config_paths():
+ if os.access(file_path, os.R_OK):
config = yaml.safe_load(open(file_path, "r"))
self.values.update(config)
@@ -63,7 +73,7 @@
def __init__(self, global_config, config_path):
if global_config.has("default_job_config"):
- defaults = global_config.get("default_job_config").copy()
+ defaults = copy.deepcopy(global_config.get("default_job_config"))
else:
defaults = {}
Configuration.__init__(self, defaults)
--
To view, visit https://gerrit.wikimedia.org/r/344057
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia1afe7fe3770866d33781a4cd4626a46a5aae09a
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/process-control
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits