solaar: add --hidraw option again

This options allows the devices list to be restricted which got removed
in:

    commit 3b75b69970
    Author: Daniel Pavel <daniel.pavel@gmail.com>
    Date:   Fri Aug 9 12:25:47 2013 +0200

        merged solaar-cli functionality into main solaar binary

solaar-cli is still busted, but since it is deprecated, it's probably
fine.
This commit is contained in:
Peter Wu
2013-08-20 13:16:12 +02:00
parent f144816256
commit 024a71b618
2 changed files with 8 additions and 4 deletions

View File

@@ -76,10 +76,12 @@ _cli_parser, actions = _create_parser()
print_help = _cli_parser.print_help
def _receivers():
def _receivers(dev_path=None):
from logitech_receiver import Receiver
from logitech_receiver.base import receivers
for dev_info in receivers():
if dev_path is not None and dev_path != dev_info.path:
continue
try:
r = Receiver.open(dev_info)
if _log.isEnabledFor(_DEBUG):
@@ -130,7 +132,7 @@ def _find_device(receivers, name):
raise Exception("no device found matching '%s'" % name)
def run(cli_args=None):
def run(cli_args=None, hidraw_path=None):
if cli_args:
action = cli_args[0]
args = _cli_parser.parse_args(cli_args)
@@ -146,7 +148,7 @@ def run(cli_args=None):
assert action in actions
try:
c = list(_receivers())
c = list(_receivers(hidraw_path))
if not c:
raise Exception('Logitech receiver not found')

View File

@@ -42,6 +42,8 @@ def _parse_arguments():
arg_parser = argparse.ArgumentParser(prog=NAME.lower())
arg_parser.add_argument('-d', '--debug', action='count', default=0,
help='print logging messages, for debugging purposes (may be repeated for extra verbosity)')
arg_parser.add_argument('-D', '--hidraw', action='store', dest='hidraw_path', metavar='PATH',
help='unifying receiver to use; the first detected receiver if unspecified. Example: /dev/hidraw2')
arg_parser.add_argument('--restart-on-wake-up', action='store_true',
help='restart Solaar on sleep wake-up (experimental)')
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
@@ -81,7 +83,7 @@ def main():
args = _parse_arguments()
if not args: return
if args.action: return _cli.run(args.action)
if args.action: return _cli.run(args.action, args.hidraw_path)
_require('gi.repository', 'python-gi')
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')