1"""
2Display Yandex.Disk status.
3
4Configuration parameters:
5    cache_timeout: refresh interval for this module (default 10)
6    format: display format for this module (default 'Yandex.Disk: {status}')
7    status_busy: show when Yandex.Disk is busy (default None)
8    status_off: show when Yandex.Disk isn't running (default 'Not started')
9    status_on: show when Yandex.Disk is idling (default 'Idle')
10
11Format placeholders:
12    {status} Yandex.Disk status
13
14Color options:
15    color_bad: Not started
16    color_degraded: Idle
17    color_good: Busy
18
19Requires:
20    yandex-disk: command line interface for Yandex.Disk
21
22@author Vladimir Potapev (github:vpotapev)
23@license BSD
24
25SAMPLE OUTPUT
26{'color': '#FFFF00', 'full_text': 'Yandex.Disk: Busy'}
27
28idle
29{'color': '#00FF00', 'full_text': 'Yandex.Disk: Idle'}
30
31off
32{'color': '#FF0000', 'full_text': 'Yandex.Disk: Not started'}
33"""
34
35STRING_NOT_INSTALLED = "not installed"
36
37
38class Py3status:
39    """
40    """
41
42    # available configuration parameters
43    cache_timeout = 10
44    format = "Yandex.Disk: {status}"
45    status_busy = None
46    status_off = "Not started"
47    status_on = "Idle"
48
49    def post_config_hook(self):
50        if not self.py3.check_commands("yandex-disk"):
51            raise Exception(STRING_NOT_INSTALLED)
52
53    def yandexdisk_status(self):
54        status = self.py3.command_output("yandex-disk status").splitlines()[0]
55
56        if status == "Error: daemon not started":
57            color = self.py3.COLOR_BAD
58            status = self.status_off
59        elif status == "Synchronization core status: idle":
60            color = self.py3.COLOR_GOOD
61            status = self.status_on
62        else:
63            color = self.py3.COLOR_DEGRADED
64            if self.status_busy is not None:
65                status = self.status_busy
66
67        return {
68            "cached_until": self.py3.time_in(self.cache_timeout),
69            "color": color,
70            "full_text": self.py3.safe_format(self.format, {"status": status}),
71        }
72
73
74if __name__ == "__main__":
75    """
76    Run module in test mode.
77    """
78    from py3status.module_test import module_test
79
80    module_test(Py3status)
81