-
Notifications
You must be signed in to change notification settings - Fork 1.1k
machine: Retrieve an unique identifier if one is known. #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,17 @@ | |
|
|
||
|
|
||
| def unique_id(): | ||
| for base in ("/etc", "/var/lib/dbus"): | ||
| try: | ||
| with open(base + "/machine-id", "rb") as source: | ||
| data = source.read(32) | ||
| if len(data) == 32: | ||
| for byte in data: | ||
| if byte not in b"0123456789abcdef": | ||
| break | ||
| # unhexlify might not be available | ||
| return bytes([int(data[i : i + 2], 16) for i in range(0, len(data), 2)]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest replacing |
||
| except OSError as e: | ||
| if "ENOENT" not in str(e): | ||
| raise | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to just do |
||
| return b"upy-non-unique" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| metadata(version="0.2.2") | ||
| metadata(version="0.2.3") | ||
|
|
||
| # Originally written by Paul Sokolovsky. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest keeping the
len(data) == 32check but removing the hex char validation loop.(If the file exists and has at least 32 bytes, it's highly likely to be a well formed hex number.)