Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

actualize code for updated version of winregistry #24

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
Expand Down
20 changes: 11 additions & 9 deletions machineid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
from sys import platform

try:
from winregistry import WinRegistry
import winregistry
except ImportError:
WinRegistry = None
winregistry = None

class MachineIdNotFound(RuntimeError):
"""
Expand Down Expand Up @@ -64,14 +64,16 @@ def __read__(path: str) -> str:
except IOError:
return None

def __reg__(registry: str, key: str) -> str:
def __reg__(key_name: str, value_name: str) -> str:
if winregistry is None:
return None
try:
with WinRegistry() as reg:
return reg.read_entry(registry, key) \
.value \
.strip()
with winregistry.open_value(key_name, value_name) as reg:
if reg.data and isinstance(reg.data, str):
return reg.data.strip()
except OSError:
return None
pass
return None

def id(winregistry: bool = True) -> str:
"""
Expand All @@ -82,7 +84,7 @@ def id(winregistry: bool = True) -> str:
if platform == 'darwin':
id = __exec__("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'")
elif platform in ('win32', 'cygwin', 'msys'):
if winregistry and WinRegistry is not None:
if winregistry and winregistry is not None:
id = __reg__(r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
else:
id = __exec__("powershell.exe -ExecutionPolicy bypass -command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
author=__author__,
author_email='oss@keygen.sh',
license='MIT',
install_requires=['winregistry; sys_platform == "win32"'],
install_requires=['winregistry>=2.01; sys_platform == "win32"'],
ezekg marked this conversation as resolved.
Show resolved Hide resolved
packages=['machineid'],
package_data={
'machineid': ['py.typed'],
Expand Down