-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract version utils and use semver for version comparison (#4844)
* Use semver for version comparison, extract versioning logic to vertion_utils
- Loading branch information
Showing
8 changed files
with
120 additions
and
167 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# (C) Datadog, Inc. 2019 | ||
# All rights reserved | ||
# Licensed under Simplified BSD License (see LICENSE) | ||
import re | ||
|
||
import semver | ||
|
||
V8_3 = semver.parse("8.3.0") | ||
V9 = semver.parse("9.0.0") | ||
V9_1 = semver.parse("9.1.0") | ||
V9_2 = semver.parse("9.2.0") | ||
V9_4 = semver.parse("9.4.0") | ||
V9_6 = semver.parse("9.6.0") | ||
V10 = semver.parse("10.0.0") | ||
|
||
|
||
def get_version(db): | ||
cursor = db.cursor() | ||
cursor.execute('SHOW SERVER_VERSION;') | ||
raw_version = cursor.fetchone()[0] | ||
try: | ||
version_parts = raw_version.split(' ')[0].split('.') | ||
version = [int(part) for part in version_parts] | ||
while len(version) < 3: | ||
version.append(0) | ||
return semver.VersionInfo(*version) | ||
except Exception: | ||
# Postgres might be in development, with format \d+[beta|rc]\d+ | ||
match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version) | ||
if match: | ||
version = list(match.groups()) | ||
# We found a valid development version | ||
if len(version) == 3: | ||
# Replace development tag with a negative number to properly compare versions | ||
version[1] = -1 | ||
version = [int(part) for part in version] | ||
return semver.VersionInfo(*version) | ||
raise Exception("Cannot determine which version is {}".format(raw_version)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
psycopg2-binary==2.8.4 | ||
semver==2.9.0 |
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
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
Oops, something went wrong.