Skip to content

Commit

Permalink
Feature/lobster version flag for tools (#129)
Browse files Browse the repository at this point in the history
Co-authored-by: Kedar Navare <[email protected]>
  • Loading branch information
kedarnn and Kedar Navare authored Dec 10, 2024
1 parent 0f8095e commit e026b8a
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lobster/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
7 changes: 5 additions & 2 deletions lobster/tools/codebeamer/codebeamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/core/ci_report/ci_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/core/html_report/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/core/online_report/online_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/core/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions lobster/tools/cpp/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/cpptest/cpptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion lobster/tools/gtest/gtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lobster/tools/trlc/trlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"),
Expand Down
45 changes: 45 additions & 0 deletions lobster/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
import sys
from argparse import ArgumentParser

VERSION_TUPLE = (0, 9, 21)
VERSION_SUFFIX = "dev"
Expand All @@ -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

0 comments on commit e026b8a

Please sign in to comment.