From 2c61072cdc158804908909671ab67d91d280b774 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sat, 18 Apr 2020 18:49:42 +0200 Subject: [PATCH 1/2] Use template to generate file with __version__ Fix #252 --- .tito/templates/__init__.py.tpl | 22 ++++++++++++++++++++++ .tito/tito.props | 4 ++++ src/tito/__init__.py | 7 +++++++ 3 files changed, 33 insertions(+) create mode 100644 .tito/templates/__init__.py.tpl diff --git a/.tito/templates/__init__.py.tpl b/.tito/templates/__init__.py.tpl new file mode 100644 index 0000000..3bec099 --- /dev/null +++ b/.tito/templates/__init__.py.tpl @@ -0,0 +1,22 @@ +# Copyright (c) 2008-2009 Red Hat, Inc. +# +# This software is licensed to you under the GNU General Public License, +# version 2 (GPLv2). There is NO WARRANTY for this software, express or +# implied, including the implied warranties of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 +# along with this software; if not, see +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. +# +# Red Hat trademarks are not licensed under GPLv2. No permission is +# granted to use or replicate Red Hat trademarks that are incorporated +# in this software or its documentation. + + +# WARNING: This file is generated from a tito template, do not edit it directly! + + +""" +Infrastructure for building Spacewalk and Satellite packages from git tags. +""" + +__version__ = '$version' diff --git a/.tito/tito.props b/.tito/tito.props index 644482f..189edfd 100644 --- a/.tito/tito.props +++ b/.tito/tito.props @@ -8,3 +8,7 @@ disttag = el5 [tag2] disttag = el5 + +[version_template] +destination_file = src/tito/__init__.py +template_file = .tito/templates/__init__.py.tpl diff --git a/src/tito/__init__.py b/src/tito/__init__.py index 42207ca..79bb597 100644 --- a/src/tito/__init__.py +++ b/src/tito/__init__.py @@ -10,6 +10,13 @@ # Red Hat trademarks are not licensed under GPLv2. No permission is # granted to use or replicate Red Hat trademarks that are incorporated # in this software or its documentation. + + +# WARNING: This file is generated from a tito template, do not edit it directly! + + """ Infrastructure for building Spacewalk and Satellite packages from git tags. """ + +__version__ = '0.6.13' From 0407099f24e40b2a0565868d6d1434e43c0bb25b Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sat, 18 Apr 2020 19:32:24 +0200 Subject: [PATCH 2/2] Implement --version parameter Fix #187 --- src/tito/cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tito/cli.py b/src/tito/cli.py index 2df1119..e027cec 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -20,6 +20,7 @@ import errno from optparse import OptionParser, SUPPRESS_HELP +from tito import __version__ from tito.common import find_git_root, error_out, debug, get_class_by_name, \ DEFAULT_BUILDER, BUILDCONFIG_SECTION, DEFAULT_TAGGER, \ create_builder, get_project_name, get_relative_project_dir, \ @@ -32,6 +33,7 @@ from tito.exception import TitoException # before we try to dynamically import them based on a string name. import tito.tagger # NOQA +PROGNAME = "tito" TITO_PROPS = "tito.props" RELEASERS_CONF_FILENAME = "releasers.conf" ASSUMED_NO_TAR_GZ_PROPS = """ @@ -194,6 +196,10 @@ class CLI(object): """ def main(self, argv): + if "--version" in sys.argv: + print(" ".join([PROGNAME, __version__])) + sys.exit(0) + if len(argv) < 1 or not argv[0] in CLI_MODULES.keys(): self._usage() sys.exit(1)