def main(): """ Main function of the program """ logger = get_logger("qbit") config = Config(APP_CONFIG_FILE) try: config.validate() conf = config.load() toaster = TorrentToaster(conf['toaster']) systray = QbitTray(conf['qbittorrent'], toaster) systray.icon.start() handler = TorrentHandler(conf, toaster) observer = Observer() observer.schedule(handler, conf['folders']['src']) observer.start() logger.info("Watcher started") systray.run(observer) except (ConfigError, QbitError): raise MainError
""" Manage a systray (icon in taskbar) for windows """ import logging import time from subprocess import Popen, CalledProcessError from qbit_watcher.logger import get_logger from qbit_watcher.qbittorrent import QBittorrent from qbit_watcher.settings import APP_LOGFILE, APP_README, APP_BARETAIL, NOTEPAD, APP_ICON_SYSTRAY from infi.systray import SysTrayIcon LOGGER = get_logger(__name__) class QbitTray: def __init__(self, conf, toaster): self.conf = conf self.toaster = toaster self.icon_path = APP_ICON_SYSTRAY if not self.icon_path.is_file(): self.icon_path = None self.icon = self.setup() def setup(self): menu_options = ( ("Clean torrents older than %d days" % (self.conf["clean_older_than"]), None, lambda x: self.clean_torrents()), ("Open log file", None, QbitTray.open_log_file), ("Open README", None, QbitTray.open_readme), )