Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
import solaar.ui as ui
import solaar.listener as listener
listener.setup_scanner(ui.status_changed, ui.error_dialog)
import solaar.upower as _upower
if args.restart_on_wake_up:
_upower.watch(listener.start_all, listener.stop_all)
else:
_upower.watch(listener.ping_all)
# main UI event loop
ui.run_loop(listener.start_all, listener.stop_all)
except Exception as e:
import sys
sys.exit('%s: error: %s' % (NAME.lower(), e))
def run(cli_args=None, hidraw_path=None):
if cli_args:
action = cli_args[0]
args = _cli_parser.parse_args(cli_args)
else:
args = _cli_parser.parse_args()
# Python 3 has an undocumented 'feature' that breaks parsing empty args
# http://bugs.python.org/issue16308
if not 'cmd' in args:
_cli_parser.print_usage(_sys.stderr)
_sys.stderr.write('%s: error: too few arguments\n' % NAME.lower())
_sys.exit(2)
action = args.action
assert action in actions
try:
c = list(_receivers(hidraw_path))
if not c:
raise Exception('Logitech receiver not found')
from importlib import import_module
m = import_module('.' + action, package=__name__)
m.run(c, args, _find_receiver, _find_device)
except AssertionError as e:
from traceback import extract_tb
tb_last = extract_tb(_sys.exc_info()[2])[-1]
_sys.exit('%s: assertion failed: %s line %d' % (NAME.lower(), tb_last[0], tb_last[1]))
def _create_parser():
parser = _argparse.ArgumentParser(prog=NAME.lower(), add_help=False,
epilog='For details on individual actions, run `%s --help`.' % NAME.lower())
subparsers = parser.add_subparsers(title='actions',
help='optional action to perform')
sp = subparsers.add_parser('show', help='show information about devices')
sp.add_argument('device', nargs='?', default='all',
help='device to show information about; may be a device number (1..6), a serial, '
'a substring of a device\'s name, or "all" (the default)')
sp.set_defaults(action='show')
sp = subparsers.add_parser('config', help='read/write device-specific settings',
epilog='Please note that configuration only works on active devices.')
sp.add_argument('device',
help='device to configure; may be a device number (1..6), a device serial, '
'or at least 3 characters of a device\'s name')
sp.add_argument('setting', nargs='?',
help='device-specific setting; leave empty to list available settings')
#
#
#
from __future__ import absolute_import, division, print_function, unicode_literals
#
#
#
import fcntl as _fcntl
import os.path as _path
import os as _os
from solaar import NAME
_program = NAME.lower()
del NAME
from logging import getLogger, DEBUG as _DEBUG
_log = getLogger(__name__)
del getLogger
def check():
"""Select a file lock location and try to acquire it.
Suitable locations are $XDG_RUNTIME_DIR, /run/lock, /var/lock, and $TMPDIR.
The first one found and writable is used.
"""
# ensure no more than a single instance runs at a time
lock_fd = None
for p in _os.environ.get('XDG_RUNTIME_DIR'), '/run/lock', '/var/lock', _os.environ.get('TMPDIR', '/tmp'):
# pick the first temporary writable folder
def _parse_arguments():
import argparse
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__)
arg_parser.add_argument('--help-actions', action='store_true',
help='print help for the optional actions')
arg_parser.add_argument('action', nargs=argparse.REMAINDER, choices=_cli.actions,
help='optional actions to perform')
args = arg_parser.parse_args()
if args.help_actions:
_cli.print_help()
def _create_parser():
parser = _argparse.ArgumentParser(prog=NAME.lower(), add_help=False,
epilog='For details on individual actions, run `%s --help`.' % NAME.lower())
subparsers = parser.add_subparsers(title='actions',
help='optional action to perform')
sp = subparsers.add_parser('show', help='show information about devices')
sp.add_argument('device', nargs='?', default='all',
help='device to show information about; may be a device number (1..6), a serial, '
'a substring of a device\'s name, or "all" (the default)')
sp.set_defaults(action='show')
sp = subparsers.add_parser('config', help='read/write device-specific settings',
epilog='Please note that configuration only works on active devices.')
sp.add_argument('device',
help='device to configure; may be a device number (1..6), a device serial, '
'or at least 3 characters of a device\'s name')
sp.add_argument('setting', nargs='?',