2016-12-04 08:37:01 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-04-02 08:31:23 +02:00
|
|
|
import os
|
2016-12-04 08:37:01 +01:00
|
|
|
import sys
|
2017-04-02 08:31:23 +02:00
|
|
|
import logging
|
2018-05-06 10:31:46 +02:00
|
|
|
import signal
|
2016-12-08 11:31:20 +01:00
|
|
|
import bumblebee.theme
|
2016-12-04 08:37:01 +01:00
|
|
|
import bumblebee.engine
|
|
|
|
import bumblebee.config
|
2016-12-04 16:14:43 +01:00
|
|
|
import bumblebee.output
|
2016-12-09 19:29:16 +01:00
|
|
|
import bumblebee.input
|
2017-04-02 08:56:44 +02:00
|
|
|
import bumblebee.modules.error
|
2016-12-04 08:37:01 +01:00
|
|
|
|
2017-09-18 20:14:17 +02:00
|
|
|
try:
|
|
|
|
reload(sys)
|
|
|
|
sys.setdefaultencoding('UTF8')
|
|
|
|
except Exception:
|
|
|
|
pass
|
2017-09-16 12:22:20 +02:00
|
|
|
|
|
|
|
|
2016-12-04 08:37:01 +01:00
|
|
|
def main():
|
2018-05-06 10:31:46 +02:00
|
|
|
def sig_USR1_handler(signum,stack):
|
|
|
|
engine.write_output()
|
|
|
|
|
2016-12-04 08:37:01 +01:00
|
|
|
config = bumblebee.config.Config(sys.argv[1:])
|
2017-04-04 15:15:50 +02:00
|
|
|
|
|
|
|
if config.debug():
|
2017-12-19 18:29:39 +01:00
|
|
|
if config.logfile() in ["stdout", "stderr"]:
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG,
|
|
|
|
format="[%(asctime)s] %(levelname)-8s %(message)s",
|
|
|
|
stream=sys.stdout if config.logfile() == "stdout" else sys.stderr
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG,
|
|
|
|
format="[%(asctime)s] %(levelname)-8s %(message)s",
|
|
|
|
filename=config.logfile()
|
|
|
|
)
|
2017-04-04 15:15:50 +02:00
|
|
|
|
2018-04-29 16:12:39 +02:00
|
|
|
theme = bumblebee.theme.Theme(config.theme(), config.iconset())
|
2018-09-22 14:40:32 +02:00
|
|
|
output = bumblebee.output.I3BarOutput(theme=theme, config=config)
|
2016-12-09 19:29:16 +01:00
|
|
|
inp = bumblebee.input.I3BarInput()
|
2017-04-02 08:31:23 +02:00
|
|
|
engine = None
|
2016-12-04 08:37:01 +01:00
|
|
|
|
2017-04-02 08:31:23 +02:00
|
|
|
try:
|
|
|
|
engine = bumblebee.engine.Engine(
|
|
|
|
config=config,
|
|
|
|
output=output,
|
|
|
|
inp=inp,
|
2018-05-30 10:42:31 +02:00
|
|
|
theme=theme,
|
2017-04-02 08:31:23 +02:00
|
|
|
)
|
2018-05-06 10:31:46 +02:00
|
|
|
signal.signal(10,sig_USR1_handler)
|
2017-04-02 08:31:23 +02:00
|
|
|
engine.run()
|
2017-05-13 20:28:11 +02:00
|
|
|
except KeyboardInterrupt as error:
|
|
|
|
inp.stop()
|
|
|
|
sys.exit(0)
|
2017-04-02 08:31:23 +02:00
|
|
|
except BaseException as e:
|
2017-06-16 15:36:56 +02:00
|
|
|
if not engine: raise
|
2017-06-10 14:08:49 +02:00
|
|
|
module = engine.current_module()
|
2017-04-02 08:31:23 +02:00
|
|
|
logging.exception(e)
|
|
|
|
if output.started():
|
|
|
|
output.flush()
|
|
|
|
output.end()
|
|
|
|
else:
|
|
|
|
output.start()
|
|
|
|
import time
|
|
|
|
while True:
|
|
|
|
output.begin()
|
|
|
|
error = bumblebee.modules.error.Module(engine, config)
|
2017-06-10 14:08:49 +02:00
|
|
|
error.set("exception occurred: {} in {}".format(e, module))
|
2017-04-02 08:31:23 +02:00
|
|
|
widget = error.widgets()[0]
|
|
|
|
widget.link_module(error)
|
|
|
|
output.draw(widget, error)
|
|
|
|
output.flush()
|
|
|
|
output.end()
|
|
|
|
time.sleep(1)
|
2016-12-09 19:29:16 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
2016-12-04 08:37:01 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|