コード例 #1
0
def get_redshift_value(module):
    widget = module.widget()
    location = module.parameter("location", "auto")
    lat = module.parameter("lat", None)
    lon = module.parameter("lon", None)

    # Even if location method is set to manual, if we have no lat or lon,
    # fall back to the geoclue2 method.
    if location == "manual" and (lat is None or lon is None):
        location = "geoclue2"

    command = ["redshift", "-p"]
    if location == "manual":
        command.extend(["-l", "{}:{}".format(lat, lon)])
    if location == "geoclue2":
        command.extend(["-l", "geoclue2"])

    try:
        res = util.cli.execute(" ".join(command))
    except Exception:
        res = ""
    widget.set("temp", "n/a")
    widget.set("transition", "")
    widget.set("state", "day")
    for line in res.split("\n"):
        line = line.lower()
        if "temperature" in line:
            widget.set("temp", line.split(" ")[2])
        if "period" in line:
            state = line.split(" ")[1]
            if "day" in state:
                widget.set("state", "day")
            elif "night" in state:
                widget.set("state", "night")
            else:
                widget.set("state", "transition")
                match = re.search(r"(\d+)\.\d+% ([a-z]+)", line)
                widget.set("transition",
                           "({}% {})".format(match.group(1), match.group(2)))
    core.event.trigger("update", [widget.module.id], redraw_only=True)
コード例 #2
0
def testvalid_parameter():
    cfg = core.config.Config(shlex.split("-p test_module.foo=5"))
    module = SampleModule(config=cfg)
    assert module.parameter("foo") == "5"
コード例 #3
0
def test_default_is_none(empty_config):
    module = SampleModule(config=empty_config)
    assert module.parameter("foo") == None
コード例 #4
0
def test_default_parameter(empty_config):
    module = SampleModule(config=empty_config)
    assert module.parameter("foo", "default") == "default"
コード例 #5
0
def test_bigger(module):
    module.text = "this is a really really long sample text"
    maxwidth = module.parameter("scrolling.width")
    assert maxwidth < len(module.text)
    assert module.get(module.widget()) == module.text[:maxwidth]
コード例 #6
0
def test_smaller(module):
    module.text = "test"
    assert module.parameter("scrolling.width") > len(module.text)
    assert module.get(module.widget()) == module.text
コード例 #7
0
def test_never(module):
    assert module.parameter("interval") == "never"
コード例 #8
0
 def testvalid_parameter(self):
     cfg = core.config.Config(shlex.split("-p test_module.foo=5"))
     module = TestModule(config=cfg)
     self.assertEqual(5, int(module.parameter("foo")))
コード例 #9
0
 def test_default_is_none(self):
     cfg = core.config.Config([])
     module = TestModule(config=cfg)
     self.assertEqual(None, module.parameter("foo"))
コード例 #10
0
 def test_default_parameter(self):
     cfg = core.config.Config([])
     module = TestModule(config=cfg)
     self.assertEqual("default", module.parameter("foo", "default"))