update error handling
This commit is contained in:
parent
d43b236319
commit
8ba6fcfa82
1 changed files with 21 additions and 10 deletions
31
bin/rzr
31
bin/rzr
|
|
@ -3,7 +3,6 @@
|
||||||
from argparse import RawTextHelpFormatter
|
from argparse import RawTextHelpFormatter
|
||||||
from colour import Color
|
from colour import Color
|
||||||
from openrazer.client import DeviceManager
|
from openrazer.client import DeviceManager
|
||||||
from openrazer.client import constants as razer_constants
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
@ -63,7 +62,7 @@ def apply_lightmap(device_profile):
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
if not device:
|
if not device:
|
||||||
error("device '{}' not found".format(device_profile["name"]))
|
error("device '{}' not available".format(device_profile["name"]))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Open lightmap
|
# Open lightmap
|
||||||
|
|
@ -72,11 +71,19 @@ def apply_lightmap(device_profile):
|
||||||
"{}/{}.toml".format(lightmap_directory, device_profile["lightmap"])
|
"{}/{}.toml".format(lightmap_directory, device_profile["lightmap"])
|
||||||
)
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
error("the lightmap '{}' doesn't exist".format(device_profile["lightmap"]))
|
error(
|
||||||
|
"the lightmap '{}' for device '{}' doesn't exist".format(
|
||||||
|
device_profile["lightmap"], device_profile["name"]
|
||||||
|
)
|
||||||
|
)
|
||||||
list_lightmaps()
|
list_lightmaps()
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error("failed to load lightmap '{}': {}".format(device_profile["lightmap"], e))
|
error(
|
||||||
|
"failed to load lightmap '{}' for device '{}': {}".format(
|
||||||
|
device_profile["lightmap"], device_profile["name"], e
|
||||||
|
)
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Set light colors
|
# Set light colors
|
||||||
|
|
@ -88,13 +95,17 @@ def apply_lightmap(device_profile):
|
||||||
] = color_tuple
|
] = color_tuple
|
||||||
except KeyError:
|
except KeyError:
|
||||||
error(
|
error(
|
||||||
"light '{}' is not available in lightmap '{}'".format(
|
"light '{}' is not available in lightmap '{}' for device '{}'".format(
|
||||||
light, device_profile["lightmap"]
|
light, device_profile["lightmap"], device_profile["name"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error("failed to set light '{}': {}".format(light, e))
|
error(
|
||||||
|
"failed to set light '{}' for device '{}': {}".format(
|
||||||
|
light, device_profile["name"], e
|
||||||
|
)
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Apply light colors
|
# Apply light colors
|
||||||
|
|
@ -161,6 +172,9 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
global device_manager, lightmap_directory, profile_directory
|
global device_manager, lightmap_directory, profile_directory
|
||||||
|
|
||||||
|
# Print greeter
|
||||||
|
print_greeter()
|
||||||
|
|
||||||
# Create device manager
|
# Create device manager
|
||||||
try:
|
try:
|
||||||
device_manager = DeviceManager()
|
device_manager = DeviceManager()
|
||||||
|
|
@ -195,9 +209,6 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Print greeter
|
|
||||||
print_greeter()
|
|
||||||
|
|
||||||
# Check if directories exist
|
# Check if directories exist
|
||||||
directories_available = True
|
directories_available = True
|
||||||
lightmap_directory = args.lightmap_directory
|
lightmap_directory = args.lightmap_directory
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue