This patch makes the version string reusable between the GUI and CLI. --- chirp.py | 8 ++++++++ chirp/__init__.py | 7 +++++++ chirpw | 6 ++---- 3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/chirp.py b/chirp.py index 88c3922..28ed8f9 100755 --- a/chirp.py +++ b/chirp.py @@ -23,6 +23,11 @@ import optparse
from chirp import * from chirp import chirp_common, errors, idrp, directory, util +from chirp import print_chirp_version + +def print_version(option, opt, value, parser): + print_chirp_version() + sys.exit(0)
def fail_unsupported(): print "Operation not supported by selected radio" @@ -58,6 +63,9 @@ def store_dtcspol(option, opt, value, parser): setattr(parser.values, option.dest, value) if __name__ == "__main__": parser = OptionParser() + parser.add_option("", "--version", action="callback", + callback=print_version, nargs=0, + help="Print version and exit") parser.add_option("-s", "--serial", dest="serial", default="mmap", help="Serial port (default: mmap)") diff --git a/chirp/__init__.py b/chirp/__init__.py index 084af48..e5118d1 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -17,6 +17,7 @@ CHIRP_VERSION="0.3.0dev"
import os import sys +import platform from glob import glob
module_dir = os.path.dirname(sys.modules["chirp"].__file__) @@ -25,3 +26,9 @@ for i in glob(os.path.join(module_dir, "*.py")): name = os.path.basename(i)[:-3] if not name.startswith("__"): __all__.append(name) + +def print_chirp_version(): + """Return the versions string""" + print "CHIRP %s on %s (Python %s)" % (CHIRP_VERSION, + platform.get_platform().os_version_string(), + sys.version.split()[0]) diff --git a/chirpw b/chirpw index 88b8e4b..0fa7340 100755 --- a/chirpw +++ b/chirpw @@ -18,7 +18,7 @@ import os
from chirp import elib_intl -from chirp import platform, CHIRP_VERSION +from chirp import platform, print_chirp_version from chirpui import config
# Hack to setup environment @@ -39,9 +39,7 @@ elif not os.isatty(0): sys.stdout = log sys.stderr = log
-print "CHIRP %s on %s (Python %s)" % (CHIRP_VERSION, - platform.get_platform().os_version_string(), - sys.version.split()[0]) +print_chirp_version();
execpath = platform.get_platform().executable_path() localepath = os.path.abspath(os.path.join(execpath, "locale"))