| |
@@ -401,6 +401,13 @@
|
| |
return True
|
| |
|
| |
|
| |
+ class ScriptExecError(RuntimeError):
|
| |
+
|
| |
+ def __init__(self, *args, **kwargs):
|
| |
+ self.errorcode = kwargs.pop('errorcode', 1)
|
| |
+ super().__init__(*args, **kwargs)
|
| |
+
|
| |
+
|
| |
class DistgitBugzillaSync:
|
| |
|
| |
def notify_users(self, errors):
|
| |
@@ -479,6 +486,12 @@
|
| |
'--env', dest='env',
|
| |
help='Run the script for a specific environment, overrides the one '
|
| |
'set in the configuration file')
|
| |
+ parser.add_argument('--add-config-file', metavar='CONFIG_FILE',
|
| |
+ dest='addl_config_files', action='append',
|
| |
+ help="File(s) from which to read overriding configuration")
|
| |
+ parser.add_argument('--add-email-overrides-file', metavar='EMAIL_OVERRIDES_FILE',
|
| |
+ dest='addl_email_overrides_files', action='append',
|
| |
+ help="File(s) from which to read additional email overrides")
|
| |
|
| |
self.args = parser.parse_args()
|
| |
|
| |
@@ -587,8 +600,20 @@
|
| |
return override_yaml.get('bugzilla_contact', {})
|
| |
return {}
|
| |
|
| |
- def main(self):
|
| |
- """The entrypoint to the script."""
|
| |
+ @classmethod
|
| |
+ def main(cls):
|
| |
+ """The entrypoint for running the script."""
|
| |
+ dbs = cls()
|
| |
+ try:
|
| |
+ dbs.run()
|
| |
+ except ScriptExecError as e:
|
| |
+ print(str(e), file=sys.stderr)
|
| |
+ sys.exit(e.errorcode)
|
| |
+ else:
|
| |
+ sys.exit(0)
|
| |
+
|
| |
+ def run(self):
|
| |
+ """Run the script."""
|
| |
global envname, env, projects_dict
|
| |
times = {
|
| |
"start": time.time(),
|
| |
@@ -596,7 +621,8 @@
|
| |
|
| |
self.get_cli_arguments()
|
| |
|
| |
- load_configuration()
|
| |
+ load_configuration(addl_config_files=self.args.addl_config_files,
|
| |
+ addl_email_overrides_files=self.args.addl_email_overrides_files)
|
| |
self.config = config
|
| |
|
| |
envname = self.config['environment']
|
| |
@@ -604,8 +630,7 @@
|
| |
if self.args.env in self.config['environments']:
|
| |
envname = self.args.env
|
| |
else:
|
| |
- print(f"Invalid environment specified: {self.args.env}")
|
| |
- return 1
|
| |
+ raise ScriptExecError(f"Invalid environment specified: {self.args.env}")
|
| |
|
| |
self.env = self.config['environments'][envname]
|
| |
|
| |
@@ -736,9 +761,6 @@
|
| |
delta = times["end"] - times["start"]
|
| |
print(f" Ran on {delta:.2f} seconds -- ie: {delta/60:.2f} minutes")
|
| |
|
| |
- return 0
|
| |
-
|
| |
|
| |
if __name__ == '__main__':
|
| |
- dbs = DistgitBugzillaSync()
|
| |
- sys.exit(dbs.main())
|
| |
+ DistgitBugzillaSync.main()
|
| |
In the course, clean up how execution errors are processed, i.e. use
exceptions rather than integer return codes to indicate errors.
This adds the --add-config-file, --add-email-overrides-file options and
as a side effect allows to specify any number of either which will be
applied in order to the respective configuration objects.