-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly support Python ver startup abort
Refactor ksconf.cli and ksconf.__main__ so that ksconf can explain that you're Python is old and bad in a graceful way that doesn't require me strip back out all the cool Python 3 stuff we've done so far. This means that ksconf.__main__ modules should remain Python 2.7 (possibly 2.6, if module.__main__ even worked in that version??) *just* so we can show a graceful error message if/when somebody tries to run this on an old version of Python. TL;DR: Trying to have our cake, and eat it too.
- Loading branch information
Showing
2 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# PYTHON_ARGCOMPLETE_OK | ||
# | ||
# Unlike the rest of ksconf, this file should remain Python 2.7 compatible | ||
# This is just enough to gracefully report our presence in an unsupported | ||
# version of Python, if we happen to get installed there. Try really hard | ||
# to avoid showing Python compiler errors as those are really confusing. | ||
|
||
""" KSCONF - Ksconf Splunk CONFig tool | ||
Optionally supports argcomplete for commandline argument (tab) completion. | ||
Install & register with: | ||
pip install argcomplete | ||
activate-global-python-argcomplete (in ~/.bashrc) | ||
""" | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import sys | ||
|
||
if sys.version_info < (3, 7): # noqa | ||
from ksconf.consts import EXIT_CODE_BAD_PY_VERSION | ||
|
||
# Can't actually import 'consts' because it loads 'enum'; so we cheat | ||
EXIT_CODE_BAD_PY_VERSION = 121 | ||
sys.stderr.write( | ||
"ABORT! ksconf cannot run here because it requires Python 3.7 or later!\n\n" | ||
"Check to see if you have multiple version of Python installed.\n" | ||
"If you need Python 2.7 or 3.6 support, consider downgrading to an earlier release.\n" | ||
"Releases 0.9.x support these older Python versions.\n\n" | ||
"If you installed this with pip, try running:\n\n" | ||
" pip install -U 'kintyre-splunk-conf>=0.9,<=0.10'\n") | ||
sys.exit(EXIT_CODE_BAD_PY_VERSION) | ||
|
||
from ksconf.cli import cli | ||
|
||
if __name__ == '__main__': # pragma: no cover | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters