fix console script entry point
In the course, clean up how execution errors are processed, i.e. use exceptions rather than integer return codes to indicate errors. Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
parent
bce634b199
commit
8cfa616073
2 changed files with 24 additions and 9 deletions
|
@ -401,6 +401,13 @@ def _is_retired(product, project):
|
|||
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):
|
||||
|
@ -587,8 +594,20 @@ class DistgitBugzillaSync:
|
|||
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(),
|
||||
|
@ -604,8 +623,7 @@ class DistgitBugzillaSync:
|
|||
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 +754,6 @@ class DistgitBugzillaSync:
|
|||
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()
|
||||
|
|
2
setup.py
2
setup.py
|
@ -40,7 +40,7 @@ setup(
|
|||
tests_require=TESTS_REQUIRE,
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'distgit-bugzilla-sync = distgit_bugzilla_sync.script:main',
|
||||
'distgit-bugzilla-sync = distgit_bugzilla_sync.script:DistgitBugzillaSync.main',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue