Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
Christmas
Commits
898e9c60
Verified
Commit
898e9c60
authored
Nov 18, 2019
by
Vojtech Myslivec
Browse files
Add support for uCI configuration
parent
20dd6e07
Changes
3
Hide whitespace changes
Inline
Side-by-side
christmas/__main__.py
View file @
898e9c60
...
...
@@ -7,18 +7,17 @@ from time import sleep
from
.helpers
import
usage
,
trap_signals
,
cleanup
from
.rainbow
import
disable_leds
,
set_led
from
.config
import
Config
from
.default_settings
import
COLORS
,
ENABLE_PROBABILITY
,
LEDS
,
SLEEP_MAX
def
blink
():
if
random
()
<
ENABLE_PROBABILITY
:
def
blink
(
conf
):
if
random
()
<
conf
.
enable_probability
:
random_state
=
"enable"
else
:
random_state
=
"disable"
random_led
=
choice
(
LEDS
)
random_color
=
choice
(
COLORS
)
random_led
=
choice
(
conf
.
leds
)
random_color
=
choice
(
conf
.
colors
)
set_led
(
random_led
,
random_state
)
set_led
(
random_led
,
random_color
)
...
...
@@ -26,12 +25,13 @@ def blink():
def
main
():
usage
()
conf
=
Config
()
trap_signals
()
disable_leds
()
while
True
:
blink
()
random_sleep
=
random
()
*
SLEEP_MAX
blink
(
conf
)
random_sleep
=
random
()
*
conf
.
sleep_max
sleep
(
random_sleep
)
cleanup
()
christmas/config.py
0 → 100644
View file @
898e9c60
"""
Config handler for christmas
"""
import
uci
from
.default_settings
import
COLORS
,
ENABLE_PROBABILITY
,
LEDS
,
SLEEP_MAX
def
get_value_from_uci
(
uci_context
,
option
):
try
:
return
uci_context
.
get
(
"christmas"
,
"christmas"
,
option
)
except
uci
.
UciExceptionNotFound
:
return
None
class
Config
:
def
__init__
(
self
):
self
.
_prepare_defaults
()
self
.
_load_uci
()
def
_prepare_defaults
(
self
):
self
.
colors
=
COLORS
self
.
enable_probability
=
ENABLE_PROBABILITY
self
.
leds
=
LEDS
self
.
sleep_max
=
SLEEP_MAX
def
_load_uci
(
self
):
with
uci
.
Uci
()
as
uci_context
:
self
.
_set_colors_from_uci
(
uci_context
)
self
.
_set_probability_from_uci
(
uci_context
)
self
.
_set_sleep_from_uci
(
uci_context
)
def
_set_colors_from_uci
(
self
,
uci_context
):
value
=
get_value_from_uci
(
uci_context
,
"colors"
)
if
value
:
self
.
colors
=
value
def
_set_probability_from_uci
(
self
,
uci_context
):
value
=
get_value_from_uci
(
uci_context
,
"enable_probability"
)
if
value
:
self
.
enable_probability
=
float
(
value
)
def
_set_sleep_from_uci
(
self
,
uci_context
):
value
=
get_value_from_uci
(
uci_context
,
"sleep_max"
)
if
value
:
self
.
sleep
=
int
(
value
)
setup.py
View file @
898e9c60
...
...
@@ -14,6 +14,9 @@ setup(
license
=
'GNU GPL v3'
,
url
=
"https://gitlab.labs.nic.cz/turris/sentinel/sview"
,
packages
=
find_packages
(),
install_requires
=
[
"pyuci"
,
],
entry_points
=
{
'console_scripts'
:
[
'christmas=christmas.__main__:main'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment