Presets can be read from stdin and written to stdout

This commit is contained in:
Shy 2017-03-25 14:54:54 +01:00
parent 3696c8fe1c
commit 8cbb604ff0

View file

@ -237,7 +237,7 @@ class C4Room:
cmd = []
for light in self.lights:
if colorscheme.color_for(light.topic):
if magic != None: # Send color to ghost, but skip masters
if magic != "none" and magic != '0': # Send color to ghost, but skip masters
if light.is_master: continue
mode_id, error = Fluffy().mode_id(magic)
@ -644,6 +644,9 @@ class ColorScheme:
def from_file(self, preset):
"""Load ColorScheme from file."""
if preset == '-':
fd = sys.stdin
else:
import os
cfg_dir = self._get_cfg_dir()
if not cfg_dir:
@ -715,6 +718,9 @@ class ColorScheme:
print("I'm sorry Dave. I'm afraid I can't do that. The name \"{}\" is reserved. Please choose a different one.".format(name))
return False
if name == '-':
fd = sys.stdout
else:
import os
cfg_dir = self._get_cfg_dir(create=True) # Create config dir if missing
@ -751,6 +757,7 @@ class ColorScheme:
else:
fd.write("{} = {}\n".format(light.topic, light.color))
if name != '-':
fd.close()
print("Wrote preset \"{}\"".format(name))
@ -773,7 +780,7 @@ class Fluffy:
return (self.modes[name.lower()], False)
# Fallback
return (1, True)
return (0, True)
class RemotePresets:
@ -983,8 +990,8 @@ if __name__ == "__main__":
"-f", "--fnordcenter", type=str, dest="f_color", metavar="PRESET",
help="apply local colorscheme PRESET to Fnordcenter")
group_cl.add_argument(
"-m", "--magic", type=str, metavar="MODE",
help="EXPERIMENTAL: blend into preset (needs a running instance of fluffyd on the network). MODE is either \"fade\", \"wave\" or \"emp\".")
"-m", "--magic", type=str, default="fade", metavar="MODE",
help="EXPERIMENTAL: blend into preset (needs a running instance of fluffyd on the network). MODE is either \"fade\", \"wave\", \"emp\" or \"none\".")
group_cl.add_argument(
"-l", "--list-presets", action="store_true",
help="list locally available presets")