-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathshared.py
More file actions
138 lines (110 loc) · 3.88 KB
/
Copy pathshared.py
File metadata and controls
138 lines (110 loc) · 3.88 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# pylint: disable=invalid-name
import enum
import sys
from time import time
from typing import Callable
from pathlib import Path
from Scripts._build import BUILD
VERSION = "0.3.1"
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
current_dir = Path(sys.executable).parent
resource_dir = Path(sys._MEIPASS) / Path("resources")
else:
current_dir = Path(__file__).parent.parent
resource_dir = current_dir / Path("resources")
class USBDeviceSpeeds(enum.IntEnum):
LowSpeed = 0
FullSpeed = 1
HighSpeed = 2
SuperSpeed = 3
# The integer value of this only applies for macOS
SuperSpeedPlus = 4
# This is not an actual value
Unknown = 9999
def __str__(self) -> str:
return _usb_protocol_names[self]
def __bool__(self) -> bool:
return True
class USBPhysicalPortTypes(enum.IntEnum):
USBTypeA = 0
USBTypeMiniAB = 1
ExpressCard = 2
USB3TypeA = 3
USB3TypeB = 4
USB3TypeMicroB = 5
USB3TypeMicroAB = 6
USB3TypePowerB = 7
USB3TypeC_USB2Only = 8
USB3TypeC_WithSwitch = 9
USB3TypeC_WithoutSwitch = 10
Internal = 255
def __str__(self) -> str:
return _usb_physical_port_types[self]
def __bool__(self) -> bool:
return True
class USBControllerTypes(enum.IntEnum):
UHCI = int("0x00", 16)
OHCI = int("0x10", 16)
EHCI = int("0x20", 16)
XHCI = int("0x30", 16)
Unknown = 9999
def __str__(self) -> str:
return _usb_controller_types[self]
def __bool__(self) -> bool:
return True
_usb_controller_types = {
USBControllerTypes.UHCI: "USB 1.1 (UHCI)",
USBControllerTypes.OHCI: "USB 1.1 (OHCI)",
USBControllerTypes.EHCI: "USB 2.0 (EHCI)",
USBControllerTypes.XHCI: "USB 3.0 (XHCI)",
USBControllerTypes.Unknown: "Unknown",
}
_usb_physical_port_types = {
USBPhysicalPortTypes.USBTypeA: "Type A",
USBPhysicalPortTypes.USBTypeMiniAB: "Type Mini-AB",
USBPhysicalPortTypes.ExpressCard: "ExpressCard",
USBPhysicalPortTypes.USB3TypeA: "USB 3 Type A",
USBPhysicalPortTypes.USB3TypeB: "USB 3 Type B",
USBPhysicalPortTypes.USB3TypeMicroB: "USB 3 Type Micro-B",
USBPhysicalPortTypes.USB3TypeMicroAB: "USB 3 Type Micro-AB",
USBPhysicalPortTypes.USB3TypePowerB: "USB 3 Type Power-B",
USBPhysicalPortTypes.USB3TypeC_USB2Only: "Type C - USB 2 only",
USBPhysicalPortTypes.USB3TypeC_WithSwitch: "Type C - with switch",
USBPhysicalPortTypes.USB3TypeC_WithoutSwitch: "Type C - without switch",
USBPhysicalPortTypes.Internal: "Internal",
}
_short_names = True
_usb_protocol_names_full = {
USBDeviceSpeeds.LowSpeed: "USB 1.1 (Low Speed)",
USBDeviceSpeeds.FullSpeed: "USB 1.1 (Full Speed)",
USBDeviceSpeeds.HighSpeed: "USB 2.0 (High Speed)",
USBDeviceSpeeds.SuperSpeed: "USB 3.0/USB 3.1 Gen 1/USB 3.2 Gen 1x1 (SuperSpeed)",
USBDeviceSpeeds.SuperSpeedPlus: "USB 3.1 Gen 2/USB 3.2 Gen 2×1 (SuperSpeed+)",
USBDeviceSpeeds.Unknown: "Unknown",
}
_usb_protocol_names_short = {
USBDeviceSpeeds.LowSpeed: "USB 1.1",
USBDeviceSpeeds.FullSpeed: "USB 1.1",
USBDeviceSpeeds.HighSpeed: "USB 2.0",
USBDeviceSpeeds.SuperSpeed: "USB 3.0",
USBDeviceSpeeds.SuperSpeedPlus: "USB 3.1 Gen 2",
USBDeviceSpeeds.Unknown: "Unknown",
}
_usb_protocol_names = _usb_protocol_names_short if _short_names else _usb_protocol_names_full
def time_it(func: Callable, text: str, *args, **kwargs):
start = time()
result = func(*args, **kwargs)
end = time()
input(f"{text} took {end - start}, press enter to continue".strip())
return result
debugging = False
def debug(str):
if debugging:
input(f"DEBUG: {str}\nPress enter to continue")
test_mode = False and debugging
if test_mode:
debug_dump_path = Path(input("Debug dump path: ").strip().replace("'", "").replace('"', ""))
else:
debug_dump_path = None
# def speed_to_name(speed: USBDeviceSpeeds):
# return _usb_protocol_names[speed]