bumblebee-status/bumblebee-status
tobi-wan-kenobi dc3881d99e [core] Make logging work in (hopefully) all situations
* Unless debugging has been enabled, log to stderr (i.e. do *not* try to
open a file)
* When debugging into a file, choose a location that is likely to be
writeable by the user (i.e. the user's home directory)
* Location of the logfile can also be specified
    
fixes #62
2017-04-04 15:15:50 +02:00

75 lines
2 KiB
Python
Executable file

#!/usr/bin/env python
import os
import sys
import logging
import bumblebee.theme
import bumblebee.engine
import bumblebee.config
import bumblebee.output
import bumblebee.input
import bumblebee.modules.error
def main():
config = bumblebee.config.Config(sys.argv[1:])
if config.debug():
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(levelname)-8s %(message)s",
filename=os.path.expanduser(config.logfile())
)
else:
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(levelname)-8s %(message)s",
stream=sys.stderr
)
theme = bumblebee.theme.Theme(config.theme())
output = bumblebee.output.I3BarOutput(theme=theme)
inp = bumblebee.input.I3BarInput()
engine = None
try:
engine = bumblebee.engine.Engine(
config=config,
output=output,
inp=inp,
)
engine.run()
except BaseException as e:
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)
error.set("exception occurred: {}".format(e))
widget = error.widgets()[0]
widget.link_module(error)
output.draw(widget, error)
output.flush()
output.end()
time.sleep(1)
# try:
# except KeyboardInterrupt as error:
# inp.stop()
# sys.exit(0)
# except bumblebee.error.BaseError as error:
# inp.stop()
# sys.stderr.write("fatal: {}\n".format(error))
# sys.exit(1)
# except Exception as error:
# inp.stop()
# sys.stderr.write("fatal: {}\n".format(error))
# sys.exit(2)
if __name__ == "__main__":
main()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4