Skip to content
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

Checks and installs pyusb and confirms compatibility with Latitude 7270 #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This project aims to enable Linux to read NFC cards the same way Windows does.
## Usage

1. Clone the repository.
1. Install python3 and python3-usb.
1. Install python3 and python3-usb ([pyusb](https://pypi.org/project/pyusb/#files)).
1. Run: `./nfc.py on` (use `sudo` if necessary).
1. Run `pcsc_scan` or whatever you prefer.
1. Enjoy!
Expand All @@ -36,6 +36,7 @@ Firmware update (done during driver installation on Windows) may be required.
* Dell Latitude 5310 2-in-1
* Dell Latitude 5480
* Dell Latitude 5491
* Dell Latitude 7270
* Dell Latitude 7280
* Dell Latitude 7290
* Dell Latitude 7390
Expand Down
31 changes: 30 additions & 1 deletion nfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import logging
import sys
import usb.core
import pkg_resources
import subprocess
#import usb.core imported later on in order to allow checking weather it is installed

class UsbDeviceMatcher:
def __init__(self, properties, handler):
Expand Down Expand Up @@ -60,6 +62,33 @@ def find(cls):
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

logger.info("Checking for dependencies...")
if "pyusb" not in {pkg.key for pkg in pkg_resources.working_set}:
logger.info("pyusb is not available.")

if (input("Seems you are missing the required library \'pyusb\'.\nWould you like to install it now? (y/N): ") == 'y'):
try:
print("> pip install pyusb")
cp = subprocess.run(["pip", "install", "pyusb"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(cp.stdout.decode())

except Exception as e:
print(str(e) + "\nERROR: There was a problem and the package could not be installed.\n"
"Try installing the library manually."
"More info here: https://pypi.org/project/pyusb/#files\n and here: https://github.com/walac/pyusb")
sys.exit()

print("Success: \'pyusb\' has been installed")

else:
logger.info("...permission denied")
sys.exit()

logger.info("pyusb is installed.")

# It is now safe to import usb
import usb.core

handler = UsbDeviceFinder.find()
if sys.argv[1] == 'on':
logger.info('Turning NFC on...')
Expand Down