apply default profile if existent and no command was given
This commit is contained in:
parent
06234ed222
commit
edf24b41aa
1 changed files with 46 additions and 36 deletions
78
bin/rzr
78
bin/rzr
|
|
@ -9,6 +9,7 @@ import argparse
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import toml
|
import toml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def print_logo():
|
def print_logo():
|
||||||
|
|
@ -30,7 +31,7 @@ def print_logo():
|
||||||
|
|
||||||
|
|
||||||
def error(msg):
|
def error(msg):
|
||||||
print("ERROR: {}".format(msg))
|
print("ERROR: {}".format(msg), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def get_color_tuple(color_string):
|
def get_color_tuple(color_string):
|
||||||
|
|
@ -52,7 +53,7 @@ def get_color_tuple(color_string):
|
||||||
return color_tuple
|
return color_tuple
|
||||||
|
|
||||||
|
|
||||||
def apply_lightmap(device_profile):
|
def apply_device_profile(device_profile):
|
||||||
|
|
||||||
global device_manager, lightmap_directory
|
global device_manager, lightmap_directory
|
||||||
|
|
||||||
|
|
@ -116,6 +117,25 @@ def apply_lightmap(device_profile):
|
||||||
device.fx.advanced.draw()
|
device.fx.advanced.draw()
|
||||||
|
|
||||||
|
|
||||||
|
def apply_profile(name):
|
||||||
|
|
||||||
|
global profile_directory
|
||||||
|
|
||||||
|
try:
|
||||||
|
profile = toml.load("{}/{}.toml".format(profile_directory, name))
|
||||||
|
except FileNotFoundError:
|
||||||
|
error("the profile '{}' doesn't exist".format(name))
|
||||||
|
list_profiles()
|
||||||
|
exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
error("couldn't load profile '{}': {}".format(name, e))
|
||||||
|
exit(1)
|
||||||
|
for device in profile:
|
||||||
|
apply_device_profile(profile[device])
|
||||||
|
|
||||||
|
print("Profile '{}' applied".format(name))
|
||||||
|
|
||||||
|
|
||||||
def iterate_lights():
|
def iterate_lights():
|
||||||
|
|
||||||
global device_manager
|
global device_manager
|
||||||
|
|
@ -161,7 +181,7 @@ def list_lightmaps():
|
||||||
|
|
||||||
if len(os.listdir(lightmap_directory)) > 0:
|
if len(os.listdir(lightmap_directory)) > 0:
|
||||||
print("Available lightmaps:")
|
print("Available lightmaps:")
|
||||||
for lightmap_file in os.listdir(lightmap_directory):
|
for lightmap_file in sorted(os.listdir(lightmap_directory)):
|
||||||
print(" - {}".format(lightmap_file[:-5]))
|
print(" - {}".format(lightmap_file[:-5]))
|
||||||
else:
|
else:
|
||||||
print("No lightmaps available")
|
print("No lightmaps available")
|
||||||
|
|
@ -173,7 +193,7 @@ def list_profiles():
|
||||||
|
|
||||||
if len(os.listdir(profile_directory)) > 0:
|
if len(os.listdir(profile_directory)) > 0:
|
||||||
print("Available profiles:")
|
print("Available profiles:")
|
||||||
for profile_file in os.listdir(profile_directory):
|
for profile_file in sorted(os.listdir(profile_directory)):
|
||||||
print(" - {}".format(profile_file[:-5]))
|
print(" - {}".format(profile_file[:-5]))
|
||||||
else:
|
else:
|
||||||
print("No profiles available")
|
print("No profiles available")
|
||||||
|
|
@ -212,10 +232,6 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.command:
|
|
||||||
parser.print_help()
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
# Create device manager
|
# Create device manager
|
||||||
try:
|
try:
|
||||||
device_manager = DeviceManager()
|
device_manager = DeviceManager()
|
||||||
|
|
@ -230,24 +246,32 @@ if __name__ == "__main__":
|
||||||
profile_directory = args.profile_directory
|
profile_directory = args.profile_directory
|
||||||
|
|
||||||
if not os.path.exists(lightmap_directory):
|
if not os.path.exists(lightmap_directory):
|
||||||
error(
|
error("lightmap directory '{}' doesn't exist".format(lightmap_directory))
|
||||||
"lightmap directory '{}' doesn't exist, please create it".format(
|
create = input("Create the directory? [y/N] ")
|
||||||
lightmap_directory
|
if create in ["y", "Y"]:
|
||||||
)
|
Path(lightmap_directory).mkdir(parents=True, exist_ok=True)
|
||||||
)
|
else:
|
||||||
directories_available = False
|
directories_available = False
|
||||||
if not os.path.exists(profile_directory):
|
if not os.path.exists(profile_directory):
|
||||||
error(
|
error("profile directory '{}' doesn't exist".format(profile_directory))
|
||||||
"profile directory '{}' doesn't exist, please create it".format(
|
create = input("Create the directory? [y/N] ")
|
||||||
profile_directory
|
if create in ["y", "Y"]:
|
||||||
)
|
Path(profile_directory).mkdir(parents=True, exist_ok=True)
|
||||||
)
|
else:
|
||||||
directories_available = False
|
directories_available = False
|
||||||
if not directories_available:
|
if not directories_available:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
if not args.command:
|
||||||
|
|
||||||
|
# Apply 'default' profile if existent, else print help
|
||||||
|
if "default.toml" in os.listdir(profile_directory):
|
||||||
|
apply_profile("default")
|
||||||
|
else:
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
if args.command == "list-devices":
|
elif args.command == "list-devices":
|
||||||
list_devices()
|
list_devices()
|
||||||
elif args.command == "list-lightmaps":
|
elif args.command == "list-lightmaps":
|
||||||
list_lightmaps()
|
list_lightmaps()
|
||||||
|
|
@ -256,18 +280,4 @@ if __name__ == "__main__":
|
||||||
elif args.command == "iterate-lights":
|
elif args.command == "iterate-lights":
|
||||||
iterate_lights()
|
iterate_lights()
|
||||||
elif args.command:
|
elif args.command:
|
||||||
# Load profile
|
apply_profile(args.command)
|
||||||
try:
|
|
||||||
profile = toml.load("{}/{}.toml".format(profile_directory, args.command))
|
|
||||||
except FileNotFoundError:
|
|
||||||
error("the profile '{}' doesn't exist".format(args.command))
|
|
||||||
list_profiles()
|
|
||||||
exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
print(type(e))
|
|
||||||
error("couldn't load profile '{}': {}".format(args.command, e))
|
|
||||||
exit(1)
|
|
||||||
for device in profile:
|
|
||||||
apply_lightmap(profile[device])
|
|
||||||
|
|
||||||
print("Profile '{}' applied".format(args.command))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue