diff --git a/CHANGELOG.md b/CHANGELOG.md index 21fecb20..1d7e3327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,19 @@ * `lobster-codebeamer` * `lobster-report` +* Add support to view version for lobster tools for following tools: + - `lobster-ci-report` + - `lobster-codebeamer` + - `lobster-cpp` + - `lobster-cpptest` + - `lobster-gtest` + - `lobster-html-report` + - `lobster-json` + - `lobster-online-report` + - `lobster-python` + - `lobster-report` + - `lobster-trlc` + * `lobster-gtest` accepts XML nodes other than `testcase`, but ignores them. ### 0.9.19 diff --git a/lobster/tool.py b/lobster/tool.py index a9e42869..435f3811 100644 --- a/lobster/tool.py +++ b/lobster/tool.py @@ -25,7 +25,7 @@ from abc import ABCMeta, abstractmethod from functools import partial -from lobster.version import FULL_NAME +from lobster.version import FULL_NAME, get_version from lobster.errors import Message_Handler from lobster.location import File_Reference from lobster.items import Requirement, Implementation, Activity @@ -94,6 +94,7 @@ def __init__(self, name, description, extensions, official): self.add_argument = self.g_tool.add_argument + @get_version def process_commandline_options(self): options = self.ap.parse_args() diff --git a/lobster/tools/codebeamer/codebeamer.py b/lobster/tools/codebeamer/codebeamer.py index dfca5949..fd2ad674 100755 --- a/lobster/tools/codebeamer/codebeamer.py +++ b/lobster/tools/codebeamer/codebeamer.py @@ -49,6 +49,7 @@ from lobster.location import Codebeamer_Reference from lobster.errors import Message_Handler, LOBSTER_Error from lobster.io import lobster_read, lobster_write +from lobster.version import get_version TOKEN = 'token' REFERENCES = 'references' @@ -403,10 +404,12 @@ def parse_cb_config(file_name): return json_config +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: codebeamer_req.Dummy_Requirement - ap = argparse.ArgumentParser() - modes = ap.add_mutually_exclusive_group(required=True) modes.add_argument("--import-tagged", metavar="LOBSTER_FILE", diff --git a/lobster/tools/core/ci_report/ci_report.py b/lobster/tools/core/ci_report/ci_report.py index 996e1c23..1d951efd 100755 --- a/lobster/tools/core/ci_report/ci_report.py +++ b/lobster/tools/core/ci_report/ci_report.py @@ -23,11 +23,15 @@ from lobster.report import Report from lobster.items import Tracing_Status +from lobster.version import get_version +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: core_ci_report_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("lobster_report", nargs="?", default="report.lobster") diff --git a/lobster/tools/core/html_report/html_report.py b/lobster/tools/core/html_report/html_report.py index 400e0c6b..2bf7c141 100755 --- a/lobster/tools/core/html_report/html_report.py +++ b/lobster/tools/core/html_report/html_report.py @@ -32,6 +32,7 @@ Codebeamer_Reference) from lobster.items import (Tracing_Status, Item, Requirement, Implementation, Activity) +from lobster.version import get_version LOBSTER_GH = "https://github.com/bmw-software-engineering/lobster" @@ -454,9 +455,12 @@ def write_html(fd, report, dot, high_contrast): fd.write(doc.render() + "\n") +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: core_html_report_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("lobster_report", nargs="?", default="report.lobster") diff --git a/lobster/tools/core/online_report/online_report.py b/lobster/tools/core/online_report/online_report.py index 10c99ccd..dcd278c6 100755 --- a/lobster/tools/core/online_report/online_report.py +++ b/lobster/tools/core/online_report/online_report.py @@ -26,6 +26,7 @@ from lobster.report import Report from lobster.location import File_Reference, Github_Reference +from lobster.version import get_version class Parse_Error(Exception): @@ -141,9 +142,12 @@ def parse_git_root(cfg): return gh_root +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: core_online_report_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("lobster_report", nargs="?", default="report.lobster") diff --git a/lobster/tools/core/report/report.py b/lobster/tools/core/report/report.py index 96618683..48f0b943 100755 --- a/lobster/tools/core/report/report.py +++ b/lobster/tools/core/report/report.py @@ -24,11 +24,15 @@ from lobster.exceptions import LOBSTER_Exception from lobster.errors import LOBSTER_Error from lobster.report import Report +from lobster.version import get_version +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: core_report_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("--lobster-config", metavar="FILE", default="lobster.conf") diff --git a/lobster/tools/cpp/cpp.py b/lobster/tools/cpp/cpp.py index 93e22f6f..4820bf96 100755 --- a/lobster/tools/cpp/cpp.py +++ b/lobster/tools/cpp/cpp.py @@ -26,7 +26,7 @@ from lobster.items import Tracing_Tag, Implementation from lobster.location import File_Reference from lobster.io import lobster_write - +from lobster.version import get_version FILE_LINE_PATTERN = r"(.*):(\d+):\d+:" KIND_PATTERN = r"(function|main function|method)" @@ -48,9 +48,12 @@ SUFFIX) +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: cpp_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("files", nargs="+", metavar="FILE|DIR") diff --git a/lobster/tools/cpptest/cpptest.py b/lobster/tools/cpptest/cpptest.py index 4dfb10b0..5b2bc30a 100644 --- a/lobster/tools/cpptest/cpptest.py +++ b/lobster/tools/cpptest/cpptest.py @@ -30,6 +30,7 @@ from lobster.tools.cpptest.parser.constants import Constants from lobster.tools.cpptest.parser.requirements_parser import \ ParserForRequirements +from lobster.version import get_version OUTPUT = "output" CODEBEAMER_URL = "codebeamer_url" @@ -366,13 +367,16 @@ def lobster_cpptest(file_dir_list: list, config_dict: dict): ) +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): """ Main function to parse arguments, read configuration and launch lobster_cpptest. """ # lobster-trace: cpptest_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("files", nargs="+", metavar="FILE|DIR") diff --git a/lobster/tools/gtest/gtest.py b/lobster/tools/gtest/gtest.py index 5bbbe3c5..66b29316 100755 --- a/lobster/tools/gtest/gtest.py +++ b/lobster/tools/gtest/gtest.py @@ -25,11 +25,14 @@ from lobster.items import Tracing_Tag, Activity from lobster.location import Void_Reference, File_Reference from lobster.io import lobster_write +from lobster.version import get_version +ap = argparse.ArgumentParser() + +@get_version(ap) def main(): # lobster-trace: gtest_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("files", nargs="+", metavar="FILE|DIR") diff --git a/lobster/tools/python/python.py b/lobster/tools/python/python.py index 5d6cb123..06d4bc07 100755 --- a/lobster/tools/python/python.py +++ b/lobster/tools/python/python.py @@ -30,6 +30,7 @@ from lobster.items import Tracing_Tag, Implementation, Activity from lobster.location import File_Reference from lobster.io import lobster_write +from lobster.version import get_version LOBSTER_TRACE_PREFIX = "# lobster-trace: " LOBSTER_JUST_PREFIX = "# lobster-exclude: " @@ -443,9 +444,12 @@ def process_file(file_name, options): raise +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): # lobster-trace: python_req.Dummy_Requirement - ap = argparse.ArgumentParser() ap.add_argument("files", nargs="+", metavar="FILE|DIR") diff --git a/lobster/tools/trlc/trlc.py b/lobster/tools/trlc/trlc.py index 6b00d8c9..8f72d869 100644 --- a/lobster/tools/trlc/trlc.py +++ b/lobster/tools/trlc/trlc.py @@ -33,6 +33,7 @@ from lobster.items import Tracing_Tag, Requirement from lobster.location import File_Reference from lobster.io import lobster_write +from lobster.version import get_version class Config_Parser(Parser_Base): @@ -362,8 +363,11 @@ def parse_directive(self): self.parse_tuple_type(n_typ) +ap = argparse.ArgumentParser() + + +@get_version(ap) def main(): - ap = argparse.ArgumentParser() ap.add_argument("--config-file", help=("name of lobster-trlc config file, " "by default %(default)s"), diff --git a/lobster/version.py b/lobster/version.py index bf577149..b3584d2a 100644 --- a/lobster/version.py +++ b/lobster/version.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Affero General Public # License along with this program. If not, see # . +import sys +from argparse import ArgumentParser VERSION_TUPLE = (0, 9, 21) VERSION_SUFFIX = "dev" @@ -25,3 +27,46 @@ ) FULL_NAME = "LOBSTER %s" % LOBSTER_VERSION + + +def get_version(obj): + """ + This decorator function is used on function wherever we are parsing + the command line arguments which then adds a version argument to the function. + If a version flag is passed to the command line arguments then the LOBSTER version + is printed. + Parameters + ---------- + obj - obj can be an ArgumentParser object or a Function object. + + Returns - Nothing + ------- + + """ + if isinstance(obj, ArgumentParser): + obj.add_argument("-v, --version", action="store_true", + default=None, + help="Get version for the tool") + + def version(func): + def execution(): + if (len(sys.argv) > 1 and + (sys.argv[1] == "--version" or sys.argv[1] == "-v")): + print(FULL_NAME) + return sys.exit(0) + else: + return func() + return execution + return version + else: + def version(func): + if not isinstance(obj, ArgumentParser): + func.ap.add_argument("-v, --version", action="store_true", + default=None, + help="Get version for the tool") + if (len(sys.argv) > 1 and + (sys.argv[1] == "--version" or sys.argv[1] == "-v")): + print(FULL_NAME) + return sys.exit(0) + return obj(func) + return version