<s> import os , sys <EOL> from scudcloud . resources import Resources <EOL> import scudcloud . scudcloud as sca <EOL> from scudcloud . version import __version__ <EOL> import fcntl , platform , signal , tempfile <EOL> from sip import SIP_VERSION_STR <EOL> from PyQt4 import QtGui , QtCore <EOL> from PyQt4 . Qt import PYQT_VERSION_STR <EOL> from PyQt4 . QtCore import QT_VERSION_STR <EOL> from PyQt4 . QtNetwork import QLocalServer , QLocalSocket <EOL> win = None <EOL> def main ( ) : <EOL> global win <EOL> signal . signal ( signal . SIGINT , exit ) <EOL> args = parse_arguments ( ) <EOL> appKey = "<STR_LIT>" <EOL> socket = QLocalSocket ( ) <EOL> socket . connectToServer ( appKey ) <EOL> if socket . isOpen ( ) : <EOL> socket . close ( ) <EOL> socket . deleteLater ( ) <EOL> return <NUM_LIT:0> <EOL> socket . deleteLater ( ) <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> app . setApplicationName ( Resources . APP_NAME ) <EOL> app . setWindowIcon ( QtGui . QIcon ( Resources . get_path ( '<STR_LIT>' ) ) ) <EOL> try : <EOL> settings_path = load_settings ( args . confdir ) <EOL> except : <EOL> print ( "<STR_LIT>" + args . confdir + "<STR_LIT>" ) <EOL> raise SystemExit ( ) <EOL> minimized = True if args . minimized is True else None <EOL> win = sca . ScudCloud ( debug = args . debug , minimized = minimized , settings_path = settings_path ) <EOL> app . commitDataRequest . connect ( win . setForceClose , type = QtCore . Qt . DirectConnection ) <EOL> server = QLocalServer ( ) <EOL> server . newConnection . connect ( restore ) <EOL> server . listen ( appKey ) <EOL> win . restore ( ) <EOL> if win . minimized is None : <EOL> win . show ( ) <EOL> sys . exit ( app . exec_ ( ) ) <EOL> def restore ( ) : <EOL> global win <EOL> win . setWindowFlags ( win . windowFlags ( ) | QtCore . Qt . WindowStaysOnTopHint ) <EOL> win . showNormal ( ) <EOL> win . setWindowFlags ( win . windowFlags ( ) & ~ QtCore . Qt . WindowStaysOnTopHint ) <EOL> win . showNormal ( ) <EOL> win . activateWindow ( ) <EOL> def load_settings ( confdir ) : <EOL> if not os . path . isdir ( confdir ) : <EOL> os . makedirs ( confdir ) <EOL> if confdir not in sys . path : <EOL> sys . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ confdir ] <EOL> return confdir <EOL> def parse_arguments ( ) : <EOL> from argparse import ArgumentParser <EOL> from os . path import expanduser <EOL> if '<STR_LIT>' in os . environ and os . environ [ '<STR_LIT>' ] : <EOL> default_confdir = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> else : <EOL> default_confdir = '<STR_LIT>' <EOL> parser = ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , default = default_confdir , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , type = bool , default = False , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , type = bool , default = False , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> if args . version : <EOL> versions ( ) <EOL> sys . exit ( ) <EOL> args . confdir = expanduser ( args . confdir ) <EOL> return args <EOL> def versions ( ) : <EOL> print ( "<STR_LIT>" , __version__ ) <EOL> print ( "<STR_LIT>" , platform . python_version ( ) ) <EOL> print ( "<STR_LIT>" , QT_VERSION_STR ) <EOL> print ( "<STR_LIT>" , PYQT_VERSION_STR ) <EOL> print ( "<STR_LIT>" , SIP_VERSION_STR ) <EOL> def exit ( * args ) : <EOL> if win is not None : <EOL> win . exit ( ) <EOL> else : <EOL> QtGui . QApplication . quit ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
