Skip to content

Commit

Permalink
fixed version servicer
Browse files Browse the repository at this point in the history
  • Loading branch information
atiderko committed Dec 1, 2023
1 parent 56ace26 commit 47de798
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions fkie_node_manager_daemon/fkie_node_manager_daemon/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def detect_version(rosnode, package):
if VERSION != 'unknown':
return VERSION, DATE
try:
VERSION = pkg_version.version
DATE = pkg_version.date
VERSION = pkg_version.version if (hasattr(pkg_version.version, "decode")) else pkg_version.version
DATE = pkg_version.date if (hasattr(pkg_version.date, "decode")) else pkg_version.date
rosnode.get_logger().info("detected version: %s (%s)" % (VERSION, DATE))
except Exception:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ def stop(self):
@wamp.register("ros.daemon.get_version")
def get_version(self) -> DaemonVersion:
Log.info(f"{self.__class__.__name__}: get daemon version ")
reply = DaemonVersion(f"{self._version}", f"{self._date}")
reply = DaemonVersion(self._version, self._date)
return json.dumps(reply, cls=SelfEncoder)
48 changes: 31 additions & 17 deletions fkie_node_manager_daemon/src/fkie_node_manager_daemon/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,62 @@
from fkie_node_manager_daemon.strings import utf8
from fkie_multimaster_pylib.system.supervised_popen import SupervisedPopen

VERSION = 'unknown'
DATE = 'unknown'
VERSION = "unknown"
DATE = "unknown"


def detect_version(package):
'''
"""
Try to detect the current version from git, installed VERSION/DATE files or package.xml
'''
"""
global VERSION
global DATE
if VERSION != 'unknown':
if VERSION != "unknown":
return VERSION, DATE
version = 'unknown'
date = 'unknown'
version = "unknown"
date = "unknown"
try:
pkg_path = roslib.packages.get_pkg_dir(package)
if pkg_path is not None and os.path.isfile("%s/VERSION" % pkg_path):
try:
with open("%s/VERSION" % pkg_path) as f:
version = f.read()
version = version.strip().decode('utf-8')
version = version.strip().decode("utf-8")
with open("%s/DATE" % pkg_path) as f:
datetag = f.read().split()
if datetag:
date = datetag[0] # .decode('utf-8')
except Exception as err:
sys.stderr.write("version detection error: %s\n" % utf8(err))
elif os.path.isdir("%s/../.git" % pkg_path) and os.path.isfile('/usr/bin/git'):
elif os.path.isdir("%s/../.git" % pkg_path) and os.path.isfile("/usr/bin/git"):
try:
os.chdir(pkg_path)
ps = SupervisedPopen(['/usr/bin/git', 'describe', '--tags', '--dirty', '--always',
'--abbrev=8'], stdout=subprocess.PIPE, object_id='get git version')
ps = SupervisedPopen(
[
"/usr/bin/git",
"describe",
"--tags",
"--dirty",
"--always",
"--abbrev=8",
],
stdout=subprocess.PIPE,
object_id="get git version",
)
output = ps.stdout.read() # .decode('utf-8')
version = output.strip()
ps = SupervisedPopen(['/usr/bin/git', 'show', '-s', '--format=%ci'],
stdout=subprocess.PIPE, object_id='get git date')
ps = SupervisedPopen(
["/usr/bin/git", "show", "-s", "--format=%ci"],
stdout=subprocess.PIPE,
object_id="get git date",
)
output = ps.stdout.read().split()
if output:
date = output[0] # .decode('utf-8')
except Exception as err:
sys.stderr.write("version detection error: %s\n" % utf8(err))
else:
ppath = roslib.packages.find_resource(package, 'package.xml')
ppath = roslib.packages.find_resource(package, "package.xml")
if ppath:
doc = dom.parse(ppath[0])
version_tags = doc.getElementsByTagName("version")
Expand All @@ -91,11 +104,12 @@ def detect_version(package):
version = version
else:
sys.stderr.write(
"version detection: no version tag in package.xml found!")
"version detection: no version tag in package.xml found!"
)
else:
sys.stderr.write("version detection: package.xml not found!")
except Exception as err:
sys.stderr.write("version detection error: %s\n" % utf8(err))
VERSION = version
DATE = date
VERSION = version.decode() if (hasattr(version, "decode")) else version
DATE = date.decode() if (hasattr(date, "decode")) else date
return version, date
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ def GetVersion(self, request, context):
@wamp.register("ros.daemon.get_version")
def get_version(self) -> DaemonVersion:
Log.info(f"{self.__class__.__name__}: get daemon version ")
reply = DaemonVersion(f"{self._version}", f"{self._date}")
reply = DaemonVersion(self._version, self._date)
return json.dumps(reply, cls=SelfEncoder)

0 comments on commit 47de798

Please sign in to comment.