forked from ni/nimi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
115 lines (89 loc) · 3.67 KB
/
__init__.py
File metadata and controls
115 lines (89 loc) · 3.67 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
# This file was generated
__version__ = '1.4.10.dev0'
from nifake.enums import * # noqa: F403,F401,H303
from nifake.errors import DriverWarning # noqa: F401
from nifake.errors import Error # noqa: F401
from nifake.grpc_session_options import * # noqa: F403,F401,H303
from nifake.session import Session # noqa: F401
from nifake.custom_struct import CustomStruct # noqa: F401
from nifake.custom_struct import struct_CustomStruct # noqa: F401
from nifake.custom_struct_typedef import CustomStructTypedef # noqa: F401
from nifake.custom_struct_typedef import struct_CustomStructTypedef # noqa: F401
from nifake.custom_struct_nested_typedef import CustomStructNestedTypedef # noqa: F401
from nifake.custom_struct_nested_typedef import struct_CustomStructNestedTypedef # noqa: F401
def get_diagnostic_information():
'''Get diagnostic information about the system state that is suitable for printing or logging
returns: dict
note: Python bitness may be incorrect when running in a virtual environment
'''
import importlib.metadata
import os
import platform
import struct
import sys
def is_python_64bit():
return (struct.calcsize("P") == 8)
def is_os_64bit():
return platform.machine().endswith('64')
def is_venv():
return 'VIRTUAL_ENV' in os.environ
info = {}
info['os'] = {}
info['python'] = {}
info['driver'] = {}
info['module'] = {}
if platform.system() == 'Windows':
try:
import winreg as winreg
except ImportError:
import _winreg as winreg
os_name = 'Windows'
try:
driver_version_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\National Instruments\NI-FAKE\CurrentVersion")
driver_version = winreg.QueryValueEx(driver_version_key, "Version")[0]
except WindowsError:
driver_version = 'Unknown'
elif platform.system() == 'Linux':
os_name = 'Linux'
driver_version = 'Unknown'
else:
raise SystemError('Unsupported platform: {}'.format(platform.system()))
installed_packages_names = [
name
for name_list in importlib.metadata.packages_distributions().values()
for name in name_list
]
installed_packages_names = set(installed_packages_names)
installed_packages_list = [
{'name': name, 'version': importlib.metadata.distribution(name).version}
for name in sorted(installed_packages_names)
]
info['os']['name'] = os_name
info['os']['version'] = platform.version()
info['os']['bits'] = '64' if is_os_64bit() else '32'
info['driver']['name'] = "NI-FAKE"
info['driver']['version'] = driver_version
info['module']['name'] = 'nifake'
info['module']['version'] = "1.4.10.dev0"
info['python']['version'] = sys.version
info['python']['bits'] = '64' if is_python_64bit() else '32'
info['python']['is_venv'] = is_venv()
info['python']['packages'] = installed_packages_list
return info
def print_diagnostic_information():
'''Print diagnostic information in a format suitable for issue report
note: Python bitness may be incorrect when running in a virtual environment
'''
info = get_diagnostic_information()
row_format = ' {:<10} {}'
for type in ['OS', 'Driver', 'Module', 'Python']:
typename = type.lower()
print(type + ':')
for item in info[typename]:
if item != 'packages':
print(row_format.format(item.title() + ':', info[typename][item]))
print(' Installed Packages:')
for p in info['python']['packages']:
print((' ' * 8) + p['name'] + '==' + p['version'])
return info