-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify-with-pymonetdb.py
executable file
·37 lines (31 loc) · 1.17 KB
/
verify-with-pymonetdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import argparse
import pymonetdb
argparser = argparse.ArgumentParser()
argparser.add_argument('url')
argparser.add_argument('--expect-version')
def main(args):
with pymonetdb.connect(args.url) as conn, conn.cursor() as c:
c.execute("SELECT name, value FROM sys.environment")
props = {}
for k, v in c.fetchall():
props[k] = v
for k, v in props.items():
if k in ['gdk_dbpath', 'monet_pid', 'revision', 'monet_version', 'monet_release']:
print(f"{k}={v!r}")
try:
# run this in a try block because 'peer' was introduced only in Aug2024.
c.execute('SELECT peer FROM sys.sessions WHERE sessionid = current_sessionid()')
peer = c.fetchone()[0]
print(f'peer={peer}')
except pymonetdb.Error:
pass
if args.expect_version:
expected = args.expect_version
actual = props['monet_version']
if actual != expected:
print(f'VERSION MISMATCH: expected {expected!r}, found {actual!r}')
return 1
if __name__ == "__main__":
args = argparser.parse_args()
exit(main(args) or 0)