#!/usr/bin/env python3 import fcntl, os, sys, signal, tempfile from PyQt4 import QtGui # Flexible install dir (we assume that 'lib' and 'resources' will be subdirs) INSTALL_DIR = os.path.dirname(os.path.realpath(__file__)) # Append the lib directory in our installation path to get remaining libraries. sys.path.append(os.path.join(INSTALL_DIR, 'lib')) from resources import Resources from scudcloud import ScudCloud # The ScudCloud QMainWindow win = None VERSION = '1.0.82' def main(): global win Resources.INSTALL_DIR = INSTALL_DIR signal.signal(signal.SIGINT, exit) lock() app = QtGui.QApplication(sys.argv) app.setApplicationName(Resources.APP_NAME) app.setWindowIcon(QtGui.QIcon(Resources.get_path('scudcloud.png'))) args = parse_arguments() ScudCloud.debug = args.debug ScudCloud.minimized = True if args.minimized is True else None ScudCloud.plugins = False if args.no_plugins is True else True try: settings_path = load_settings(args.confdir) except: print("Configuration directory "+args.confdir+" could not be created! Exiting...") raise SystemExit() win = ScudCloud(settings_path=settings_path) win.restore() if win.minimized is None: win.show() sys.exit(app.exec_()) def lock(): global fp if 'XDG_RUNTIME_DIR' in os.environ and os.environ['XDG_RUNTIME_DIR']: runtime_dir = os.environ['XDG_RUNTIME_DIR'] else: runtime_dir = tempfile.gettempdir() pid_file = runtime_dir+'/'+Resources.APP_NAME+'.pid' fp = open(pid_file, 'w') try: fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: # Another instance is running warning = QtGui.QApplication(sys.argv) QtGui.QMessageBox.warning(None, "ScudCloud", warning.tr("Another instance of ScudCloud is already running.")) sys.exit(0) def load_settings(confdir): if not os.path.isdir(confdir): os.makedirs(confdir) if confdir not in sys.path: sys.path[0:0] = [confdir] return confdir def parse_arguments(): from argparse import ArgumentParser from os.path import expanduser if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/scudcloud' else: default_confdir = '~/.config/scudcloud' parser = ArgumentParser() parser.add_argument('--confdir', dest='confdir', metavar='dir', default=default_confdir, help="change the configuration directory") parser.add_argument('--debug', dest='debug', type=bool, default=False, help="enable webkit debug console (default: False)") parser.add_argument('--minimized', dest='minimized', type=bool, default=False, help="start minimized to tray (default: False)") parser.add_argument('--no_plugins', dest='no_plugins', type=bool, default=False, help="disable web plugins (default: False)") parser.add_argument('--version', action="store_true", help="print version and exit") args = parser.parse_args() if args.version: print("ScudCloud "+VERSION) sys.exit() args.confdir = expanduser(args.confdir) return args def exit(*args): if win is not None: win.exit() else: QtGui.QApplication.quit() if __name__ == '__main__': main()