Created
August 2, 2021 17:07
-
-
Save knu2xs/d8c67e2cef79628622aaae6ee9dd0447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pro_at_least_version(version: str) -> bool: | |
""" | |
Test the current ArcGIS Pro version to be equal or greater than. | |
Args: | |
version: Version number eg ('2', '2.1', '2.8.1') | |
Returns: | |
Boolean indicating if version is at least or greater than specified version. | |
""" | |
# late import since may or may not already be loaded | |
import arcpy | |
# get parts of the current version | |
v_lst = [int(v) for v in arcpy.GetInstallInfo()['Version'].split('.')] | |
# get parts of the version to test for | |
in_lst = [int(v) for v in version.split('.')] | |
# extend the shorter version list to match the longer | |
max_len = max((len(v_lst), len(in_lst))) | |
v_lst, in_lst = [lst + ([0] * (max_len - len(lst))) for lst in [v_lst, in_lst]] | |
# variable to store status | |
at_least = True | |
# test all the parts of the input version against the current version | |
for idx in range(0, max_len): | |
# evaluate if the part and if greater, break and report status | |
if v_lst[idx] < in_lst[idx]: | |
at_least = False | |
break | |
return at_least |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment