Minor fixes for usage/troubleshooting hints and Windows

pull/8/head^2
Ben Sartori 6 months ago
parent e3a0d805e6
commit aba522f665
  1. 30
      lednamebadge.py

@ -596,9 +596,9 @@ class WriteLibUsb(WriteMethod):
return True return True
def close(self): def close(self):
for k, d in self.devices.items(): if self.dev:
d[1].reset() self.dev.reset()
WriteLibUsb.usb.util.dispose_resources(d[1]) WriteLibUsb.usb.util.dispose_resources(self.dev)
self.description = None self.description = None
self.dev = None self.dev = None
self.endpoint = None self.endpoint = None
@ -617,10 +617,8 @@ class WriteLibUsb(WriteMethod):
d.set_configuration() d.set_configuration()
except WriteLibUsb.usb.core.USBError: except WriteLibUsb.usb.core.USBError:
# TODO: use all the nice output in _find_write_method(), somehow. # TODO: use all the nice output in _find_write_method(), somehow.
print("No write access to device!") print("No read access to device list!")
print("Maybe, you have to run this program with administrator rights.") LedNameBadge._print_sudo_hints()
if sys.platform.startswith('linux'):
print("* Try with sudo or add a udev rule like described in README.md.")
sys.exit(1) sys.exit(1)
cfg = d.get_active_configuration()[0, 0] cfg = d.get_active_configuration()[0, 0]
@ -657,9 +655,7 @@ class WriteLibUsb(WriteMethod):
except WriteLibUsb.usb.core.USBError: except WriteLibUsb.usb.core.USBError:
# TODO: use all the nice output in _find_write_method(), somehow. # TODO: use all the nice output in _find_write_method(), somehow.
print("No write access to device!") print("No write access to device!")
print("Maybe, you have to run this program with administrator rights.") LedNameBadge._print_sudo_hints()
if sys.platform.startswith('linux'):
print("* Try with sudo or add a udev rule like described in README.md.")
sys.exit(1) sys.exit(1)
print("Write using %s via libusb" % (self.description,)) print("Write using %s via libusb" % (self.description,))
@ -941,8 +937,8 @@ class LedNameBadge:
if device_id != 'auto': if device_id != 'auto':
print("* Have you given the right device_id?") print("* Have you given the right device_id?")
print(" Find the available device ids with option -D list") print(" Find the available device ids with option -D list")
print("* If it is connected and still do not work, maybe you have to run") print("* If it is connected and still do not work:")
print(" this program as root.") LedNameBadge._print_sudo_hints()
sys.exit(1) sys.exit(1)
@staticmethod @staticmethod
@ -1017,6 +1013,16 @@ class LedNameBadge:
print(" (or similar, suitable for your distro; the exact command and package name might be different):") print(" (or similar, suitable for your distro; the exact command and package name might be different):")
print(" $ sudo apt install %s" % (pm_package,)) print(" $ sudo apt install %s" % (pm_package,))
@staticmethod
def _print_sudo_hints():
print("Maybe, you have to run this program with administrator rights.")
if sys.platform.startswith('win'):
print("* Open start menu, type 'cmd', click 'Run as Administrator'")
if sys.platform.startswith('linux'):
print("* If Try with sudo or")
print("* If you run the program from a virtual env, you may need to open a root shell beforehand.")
print("* Best: add a udev rule like described in README.md.")
def main(): def main():
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,

Loading…
Cancel
Save