Skip to content
Snippets Groups Projects
Commit 3867c5a2 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Merge box:src/pyopencl

parents cde5d84f c33b95ec
No related branches found
No related tags found
No related merge requests found
...@@ -688,33 +688,39 @@ def create_some_context(interactive=True, answers=None): ...@@ -688,33 +688,39 @@ def create_some_context(interactive=True, answers=None):
if not answer: if not answer:
platform = platforms[0] platform = platforms[0]
else: else:
platform = None
try: try:
choice = int(answer) int_choice = int(answer)
except ValueError: except ValueError:
pass
else:
if 0 <= int_choice < len(platforms):
platform = platforms[int_choice]
if platform is None:
answer = answer.lower() answer = answer.lower()
platform = None
for i, pf in enumerate(platforms): for i, pf in enumerate(platforms):
if answer in pf.name.lower(): if answer in pf.name.lower():
platform = pf platform = pf
if platform is None: if platform is None:
raise RuntimeError("input did not match any platform") raise RuntimeError("input did not match any platform")
else:
platform = platforms[choice]
devices = platform.get_devices() devices = platform.get_devices()
def parse_device(choice): def parse_device(choice):
try: try:
choice = int(choice) int_choice = int(choice)
except ValueError: except ValueError:
choice = choice.lower() pass
for i, dev in enumerate(devices):
if choice in dev.name.lower():
return dev
raise RuntimeError("input did not match any platform")
else: else:
return devices[choice] if 0 <= int_choice < len(devices):
return devices[int_choice]
choice = choice.lower()
for i, dev in enumerate(devices):
if choice in dev.name.lower():
return dev
raise RuntimeError("input did not match any platform")
if not devices: if not devices:
raise Error("no devices found") raise Error("no devices found")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment