Skip to content

Commit

Permalink
Merge pull request #1125 from atline/version
Browse files Browse the repository at this point in the history
Add print version subcommand.
  • Loading branch information
jluebbe committed May 5, 2023
2 parents a44ea3f + d75bb63 commit 4d5fdc8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions contrib/completion/labgrid-client.bash
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ _labgrid_client()
cancel-reservation \
wait \
reservations \
version \
export"
COMPREPLY=( $(compgen -W "$subcommands" -- "$cur") )
return
Expand Down
8 changes: 7 additions & 1 deletion labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .. import Environment, Target, target_factory
from ..exceptions import NoDriverFoundError, NoResourceFoundError, InvalidConfigError
from ..resource.remote import RemotePlaceManager, RemotePlace
from ..util import diff_dict, flat_dict, filter_dict, dump, atomic_replace, Timeout
from ..util import diff_dict, flat_dict, filter_dict, dump, atomic_replace, labgrid_version, Timeout
from ..util.proxy import proxymanager
from ..util.helper import processwrapper
from ..driver import Mode, ExecutionError
Expand Down Expand Up @@ -1295,6 +1295,9 @@ async def export(self, place, target):
print("Exiting...\n", file=sys.stderr)
export.needs_target = True

def print_version(self):
print(labgrid_version())


def start_session(url, realm, extra):
from autobahn.asyncio.wamp import ApplicationRunner
Expand Down Expand Up @@ -1787,6 +1790,9 @@ def main():
subparser.add_argument('filename', help='output filename')
subparser.set_defaults(func=ClientSession.export)

subparser = subparsers.add_parser('version', help="show version")
subparser.set_defaults(func=ClientSession.print_version)

# make any leftover arguments available for some commands
args, leftover = parser.parse_known_args()
if args.command not in ['ssh', 'rsync', 'forward']:
Expand Down
9 changes: 2 additions & 7 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@

from .config import ResourceConfig
from .common import ResourceEntry, enable_tcp_nodelay
from ..util import get_free_port

try:
import pkg_resources
__version__ = pkg_resources.get_distribution('labgrid').version
except pkg_resources.DistributionNotFound:
__version__ = "unknown"
from ..util import get_free_port, labgrid_version


__version__ = labgrid_version()
exports: Dict[str, Type[ResourceEntry]] = {}
reexec = False

Expand Down
1 change: 1 addition & 0 deletions labgrid/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .yaml import load, dump
from .ssh import sshmanager
from .helper import get_free_port, get_user, re_vt100
from .version import labgrid_version
15 changes: 15 additions & 0 deletions labgrid/util/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
This module contains helper functions for working with version.
"""


def labgrid_version():
import contextlib
from importlib.metadata import PackageNotFoundError, version

lg_version = "unknown"

with contextlib.suppress(PackageNotFoundError):
lg_version = version("labgrid")

return lg_version
2 changes: 2 additions & 0 deletions man/labgrid-client.1
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ not at all.
\fBreservations\fP List current reservations
.sp
\fBexport\fP filename Export driver information to file (needs environment with drivers)
.sp
\fBversion\fP Print the labgrid version
.SH ADDING NAMED RESOURCES
.sp
If a target contains multiple Resources of the same type, named matches need to
Expand Down
2 changes: 2 additions & 0 deletions man/labgrid-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ LABGRID-CLIENT COMMANDS

``export`` filename Export driver information to file (needs environment with drivers)

``version`` Print the labgrid version

ADDING NAMED RESOURCES
----------------------
If a target contains multiple Resources of the same type, named matches need to
Expand Down

0 comments on commit 4d5fdc8

Please sign in to comment.