[chirp_devel] [PATCH 5/9] Refactor version display into chirp module (#2343)

Zach Welch
Tue Feb 24 23:26:49 PST 2015


# HG changeset patch
# User Zach Welch <zach at mandolincreekfarm.com>

Refactor version display into chirp module (#2343)

This patch makes the version string reusable between the GUI and CLI.

diff --git a/chirp/version.py b/chirp/version.py
new file mode 100644
index 0000000..b54706c
--- /dev/null
+++ b/chirp/version.py
@@ -0,0 +1,34 @@
+# Copyright 2008 Dan Smith <dsmith at danplanet.com>
+# Copyright 2015  Zachary T Welch  <zach at mandolincreekfarm.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from chirp import CHIRP_VERSION
+import argparse
+import platform
+import sys
+
+
+class VersionAction(argparse.Action):
+    def __call__(self, parser, namespace, value, option_string=None):
+        args = (CHIRP_VERSION,
+                platform.get_platform().os_version_string(),
+                sys.version.split()[0])
+        print "CHIRP %s on %s (Python %s)" % args
+        sys.exit(1)
+
+
+def add_argument(parser):
+    parser.add_argument("--version", action=VersionAction, nargs=0,
+                        help="Print version and exit")
diff --git a/chirpc b/chirpc
index 6a25e50..c3ff224 100755
--- a/chirpc
+++ b/chirpc
@@ -62,6 +62,7 @@ class DTCSPolarityAction(argparse.Action):
 
 if __name__ == "__main__":
 	parser = argparse.ArgumentParser()
+	version.add_argument(parser)
 	parser.add_argument("-s", "--serial", dest="serial",
 			  default="mmap",
 			  help="Serial port (default: mmap)")
diff --git a/chirpw b/chirpw
index a3a316c..4f53e0d 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, version
 from chirpui import config
 
 # Hack to setup environment
@@ -40,10 +40,6 @@ 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])
-
 execpath = platform.get_platform().executable_path()
 localepath = os.path.abspath(os.path.join(execpath, "locale"))
 if not os.path.exists(localepath):
@@ -127,6 +123,7 @@ from chirpui import mainapp, config
 
 parser = argparse.ArgumentParser()
 parser.add_argument("files", metavar="file", nargs='*', help="File to open")
+version.add_argument(parser)
 parser.add_argument("--profile", action="store_true",
                     help="Enable profiling")
 args = parser.parse_args()




More information about the chirp_devel mailing list