#!/usr/bin/env python2 # -*- coding: utf-8 -*- # # mailnag-config # # Copyright 2011 - 2016 Patrick Ulbrich # Copyright 2011 Ralf Hersel # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # import gi gi.require_version('Gtk', '3.0') import os import subprocess import logging from gi.repository import Gtk from dbus.mainloop.glib import DBusGMainLoop from Mailnag.common.utils import fix_cwd, init_logging fix_cwd() from Mailnag.common.utils import set_procname, shutdown_existing_instance from Mailnag.common.dist_cfg import BIN_DIR from Mailnag.configuration.configwindow import ConfigWindow LOG_LEVEL = logging.DEBUG def main(): set_procname("mailnag-config") init_logging(enable_stdout = True, enable_syslog = False, log_level = LOG_LEVEL) confwin = ConfigWindow() Gtk.main() if confwin.daemon_enabled: try: # the launched daemon shuts down # an already running daemon print "Launching Mailnag daemon." subprocess.Popen(os.path.join(BIN_DIR, "mailnag")) except: print "ERROR: Failed to launch Mailnag daemon." else: DBusGMainLoop(set_as_default = True) # shutdown running Mailnag daemon shutdown_existing_instance() if __name__ == "__main__": main()