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

Added option --no-hidraw for the case where hidraw=true is in a confi… #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
27 changes: 21 additions & 6 deletions ds4drv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ def add_arguments(self, actions):
"/etc/ds4drv.conf, whichever is found first")

backendopt = parser.add_argument_group("backend options")
backendopt.add_argument("--hidraw", action="store_true",
backendopt.add_argument("--hidraw", action="store_true", dest="hidraw",
help="Use hidraw devices. This can be used to access "
"USB and paired bluetooth devices. Note: "
"Bluetooth devices does currently not support "
"any LED functionality")
backendopt.add_argument("--no-hidraw", action="store_false", dest="hidraw")

daemonopt = parser.add_argument_group("daemon options")
daemonopt.add_argument("--daemon", action="store_true",
Expand Down Expand Up @@ -191,42 +192,54 @@ def merge_options(src, dst, defaults):


def load_options():
# Initial command line parse to get config files.
options = parser.parse_args(sys.argv[1:] + ["--next-controller"])

# Get the configs from the config file, possibly found on the command line.
config = Config()
config_paths = options.config and (options.config,) or CONFIG_FILES
for path in filter(os.path.exists, map(os.path.expanduser, config_paths)):
config.load(path)
break

config_args = config.section_to_args("ds4drv") + config.controllers()
config_options = parser.parse_args(config_args)
# Get the configs corresponding to general command line arguments.
# Store them in "options"
config_args = config.section_to_args("ds4drv")
parser.parse_args(config_args, namespace = options)

defaults, remaining_args = parser.parse_known_args(["--next-controller"])
merge_options(config_options, options, defaults)
# Parse the command line again, storing the results in "options",
# so command line arguments supersede config arguments.
# Discard controller data from original parse to avoid double counting.
options.controllers = []
parser.parse_args(sys.argv[1:] + ["--next-controller"], namespace = options)

# Merge config file and command line controller options.
controller_defaults = ControllerAction.default_controller()
for idx, controller in enumerate(config_options.controllers):
config_controllers = parser.parse_args(config.controllers()).controllers
for idx, controller in enumerate(config_controllers):
try:
org_controller = options.controllers[idx]
merge_options(controller, org_controller, controller_defaults)
except IndexError:
options.controllers.append(controller)

# Parse profile options
options.profiles = {}
for name, section in config.sections("profile"):
args = config.section_to_args(section)
profile_options = parser.parse_args(args)
profile_options.parent = options
options.profiles[name] = profile_options

# Parse bindings options
options.bindings = {}
options.bindings["global"] = config.section("bindings",
key_type=parse_button_combo)
for name, section in config.sections("bindings"):
options.bindings[name] = config.section(section,
key_type=parse_button_combo)

# Parse mapping options
for name, section in config.sections("mapping"):
mapping = config.section(section)
for key, attr in mapping.items():
Expand All @@ -235,9 +248,11 @@ def load_options():
mapping[key] = attr
parse_uinput_mapping(name, mapping)

# Fixup controller data
for controller in options.controllers:
controller.parent = options

# Fixup default_controller data
options.default_controller = ControllerAction.default_controller()
options.default_controller.parent = options

Expand Down