Skip to content

Commit

Permalink
Merge branch 'JoshuaSBrown-synack_w004_42_attempt3' of https://github…
Browse files Browse the repository at this point in the history
….com/ORNL/DataFed into JoshuaSBrown-synack_w004_42_attempt3
  • Loading branch information
JoshuaSBrown committed Aug 25, 2023
2 parents 7b1b4ef + 5f25219 commit 079838a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmake/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ set(DATAFED_AUTHZ_PATCH 0)

set(DATAFED_PYTHON_CLIENT_MAJOR 2)
set(DATAFED_PYTHON_CLIENT_MINOR 0)
set(DATAFED_PYTHON_CLIENT_PATCH 0)
set(DATAFED_PYTHON_CLIENT_PATCH 3)
7 changes: 3 additions & 4 deletions python/datafed_pkg/datafed/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run():
release_version += f"{Version_pb2.DATAFED_RELEASE_DAY}."
release_version += f"{Version_pb2.DATAFED_RELEASE_HOUR}."
release_version += f"{Version_pb2.DATAFED_RELEASE_MINUTE}"
_print_msg(1, "Welcome to DataFed CLI, version {}".format(__version__))
_print_msg(1, f"Welcome to DataFed CLI, version {VERSION.__version__}")
_print_msg(
1, " Release, version {}".format(release_version)
)
Expand Down Expand Up @@ -2201,12 +2201,11 @@ def _help_cli(ctx, command):
"""

if not command:
click.echo("DataFed _cli, version {}\n".format(version))
click.echo("DataFed _cli, version {}\n".format(VERSION.__version__))
click.echo(ctx.parent.get_help())
else:
first = True
for c in command:
# print( c )
if first:
first = False
subcmd = _cli.get_command(_cli, c)
Expand Down Expand Up @@ -3038,7 +3037,7 @@ def _initialize(opts):
# print("_initialize, opts:", opts )

if "version" in opts and opts["version"]:
click.echo(version)
click.echo(VERSION.__version__)
_interactive = False
raise SystemExit()

Expand Down
59 changes: 45 additions & 14 deletions python/datafed_pkg/datafed/MessageLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@


import os
import xmlrpc.client
import zmq
from . import Version_pb2
from . import SDMS_Anon_pb2 as anon
from . import SDMS_Auth_pb2 as auth
from . import Connection
from . import VERSION


# Check with pypi if a newer release is available
def get_latest_version(package_name):
try:
client = xmlrpc.client.ServerProxy('https://pypi.org/pypi')
releases = client.package_releases(package_name)

if not releases:
return None

return releases[0]
except Exception as e:
print(f"Unable to connect to pypi: {e}")
return None

##
# @class API
Expand Down Expand Up @@ -148,6 +165,7 @@ def __init__(
else:
self._keys_valid = True
self._keys_loaded = True
print
except:
pub, priv = zmq.curve_keypair()
_client_pub_key = pub.decode("utf-8")
Expand All @@ -166,27 +184,40 @@ def __init__(
self._conn.registerProtocol(anon)
self._conn.registerProtocol(auth)

# Make a request to pypi
package_name = 'datafed' # Replace with the package name you want to check
latest_version_on_pypi = get_latest_version(package_name)

if latest_version_on_pypi:
pypi_major, pypi_minor, pypi_patch = latest_version_on_pypi.split('.')
major, minor, patch = VERSION.__version__.split('.')

if pypi_major != major or pypi_minor > minor or pypi_patch > patch:
self.new_client_avail = latest_version_on_pypi
else:
self.new_client_avail = False
else:
self.new_client_avail = False

# Check for compatible protocol versions
reply, mt = self.sendRecv(anon.VersionRequest(), 10000)
if reply == None:
raise Exception("Timeout waiting for server connection.")
if reply is None:
raise Exception("Timeout waiting for server connection. Make sure"
"the right ports are open.")

if reply.api_major != Version_pb2.DATAFED_COMMON_PROTOCOL_API_MAJOR:
error_msg = ("Incompatible server api detected {}.{}.{} consider "
"upgrading the datafed python client.".format(
reply.api_major, reply.api_minor, reply.api_patch
))
if self.new_client_avail:
error_msg +=("\nConsider upgrading the datafed python client as"
f" a new version is available {latest_version_on_pypi} that"
" should be compatible with the API.")
raise Exception(
"Incompatible server api detected {}.{}.{}".format(
reply.api_major, reply.api_minor, reply.api_patch
)

)

# if reply.major != Version_pb2.VER_MAJOR or reply.mapi_major != Version_pb2.VER_MAPI_MAJOR or \
# reply.mapi_minor < Version_pb2.VER_MAPI_MINOR or reply.mapi_minor > ( Version_pb2.VER_MAPI_MINOR + 9 ):
# raise Exception( "Incompatible server version {}.{}.{}.{}.{}".format(reply.major,reply.mapi_major,reply.mapi_minor,reply.client_py))

# if reply.client_py > Version_pb2.VER_CLIENT_PY:
# self.new_client_avail = "{}.{}.{}:{}".format(reply.major,reply.mapi_major,reply.mapi_minor,reply.client_py)
# else:
# self.new_client_avail = False

if client_token:
self.manualAuthByToken(client_token)
else:
Expand Down
4 changes: 0 additions & 4 deletions python/datafed_pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

from datafed.VERSION import __version__

# read the contents of VERSION file
# with open(path.join(this_directory, 'VERSION'), encoding='utf-8') as f:
# version = f.read()

setuptools.setup(
name="datafed",
version=__version__,
Expand Down

0 comments on commit 079838a

Please sign in to comment.