Skip to content

Commit

Permalink
GH #755 - Adding platforms to zato --version.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuch committed Dec 4, 2023
1 parent 11a6112 commit 3e5df40
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions code/.version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,51 @@
import inspect
import json
import os
import platform
from subprocess import PIPE, run as subprocess_run

# ################################################################################################################################
# ################################################################################################################################

# Cannot use built in __file__ because we are execfile'd
_file = inspect.currentframe().f_code.co_filename

# ################################################################################################################################
# ################################################################################################################################

# Prepare all the directories needed
curdir = os.path.dirname(os.path.abspath(_file))
release_info_dir = os.path.join(curdir, 'release-info')
git_repo_dir = os.path.abspath(os.path.join(release_info_dir, '..'))

# ################################################################################################################################
# ################################################################################################################################

#
# This is Zato version information
#
release = open(os.path.join(release_info_dir, 'release.json')).read()
release = json.loads(release)

# ################################################################################################################################
# ################################################################################################################################

platform_system = platform.system().lower()

is_windows = 'windows' in platform_system
is_linux = 'linux' in platform_system # noqa: E272

# ################################################################################################################################
# ################################################################################################################################

#
# This is last git commit ID.
#
# Make sure to use -C to specify the git directory instead of navigating to it directly;
# the latter may result in spurious pip errors, such as:
# "error in zato-agent setup command: Distribution contains no modules or packages for namespace package 'zato'"
#
git_command_date = ['git', 'log', '-1', "--pretty=%cd", "--date=format:%Y.%m.%d"]
git_command_date = ['git', 'log', '-1', '--pretty=%cd', '--date=format:%Y.%m.%d']
git_command_revision = ['git', 'rev-parse', '--short', 'HEAD']

try:
Expand All @@ -49,11 +70,21 @@
revision = revision.strip()

except Exception as e:
version = '3.2-nogit'

if is_windows:
suffix = 'windows'
elif is_linux:
suffix = 'linux'
else:
suffix = platform_system

version = f'3.2-nogit-{suffix}'
else:

major = release['major']
minor = release['minor']
version = '{}.{}.{}+rev.{}'.format(major, minor, date, revision)

version = f'{major}.{minor}.{date}+rev.{revision}'

# ################################################################################################################################
# ################################################################################################################################
Expand Down

0 comments on commit 3e5df40

Please sign in to comment.