示例#1
0
    def getConfiguration(self):
        iniPath = self._getConfigurationFilePath()
        self._parseConfigFile(iniPath)
        #
        # Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
        #
        if self._config['language']:
            setLanguage(self._config['language'])
        self._argparser = argparse.ArgumentParser(description=getMessage("argument-description"),
                                         epilog=getMessage("argument-epilog"))
        self._argparser.add_argument('--no-gui', action='store_true', help=getMessage("nogui-argument"))
        self._argparser.add_argument('-a', '--host', metavar='hostname', type=str, help=getMessage("host-argument"))
        self._argparser.add_argument('-n', '--name', metavar='username', type=str, help=getMessage("name-argument"))
        self._argparser.add_argument('-d', '--debug', action='store_true', help=getMessage("debug-argument"))
        self._argparser.add_argument('-g', '--force-gui-prompt', action='store_true', help=getMessage("force-gui-prompt-argument"))
        self._argparser.add_argument('--no-store', action='store_true', help=getMessage("no-store-argument"))
        self._argparser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help=getMessage("room-argument"))
        self._argparser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help=getMessage("password-argument"))
        self._argparser.add_argument('--player-path', metavar='path', type=str, help=getMessage("player-path-argument"))
        self._argparser.add_argument('--language', metavar='language', type=str, help=getMessage("language-argument"))
        self._argparser.add_argument('file', metavar='file', type=lambda s: unicode(s, 'utf8'), nargs='?', help=getMessage("file-argument"))
        self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("clear-gui-data-argument"))
        self._argparser.add_argument('-v', '--version', action='store_true', help=getMessage("version-argument"))
        self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("args-argument"))
        args = self._argparser.parse_args()
        if args.version:
            print getMessage("version-message").format(version, milestone)
            sys.exit()
        self._overrideConfigWithArgs(args)
        if not self._config['noGui']:
            try:
	            from syncplay.vendor.Qt import QtWidgets, IsPySide, IsPySide2
	            from syncplay.vendor.Qt.QtCore import QCoreApplication
	            from syncplay.vendor import qt5reactor
	            if not (IsPySide2 or IsPySide):
	                raise ImportError
	            if QCoreApplication.instance() is None:
	              self.app = QtWidgets.QApplication(sys.argv)
	            qt5reactor.install()
	            if isMacOS():
	                import appnope
	                appnope.nope()
            except ImportError:
                print getMessage("unable-import-gui-error")
                self._config['noGui'] = True
        if self._config['file'] and self._config['file'][:2] == "--":
            self._config['playerArgs'].insert(0, self._config['file'])
            self._config['file'] = None
        # Arguments not validated yet - booleans are still text values
        if self._config['language']:
            setLanguage(self._config['language'])
        if (self._config['forceGuiPrompt'] == "True" or not self._config['file']) and not self._config['noGui']:
            self._forceGuiPrompt()
        self._checkConfig()
        self._saveConfig(iniPath)
        if self._config['file']:
            self._config['loadedRelativePaths'] = self._loadRelativeConfiguration()
        if self._config['language']:
            setLanguage(self._config['language'])
        return self._config
示例#2
0
 def getConfiguration(self):
     iniPath = self._getConfigurationFilePath()
     self._parseConfigFile(iniPath)
     #
     # Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
     #
     if self._config['language']:
         setLanguage(self._config['language'])
     self._argparser = argparse.ArgumentParser(
         description=getMessage("argument-description"),
         epilog=getMessage("argument-epilog"))
     self._argparser.add_argument('--no-gui',
                                  action='store_true',
                                  help=getMessage("nogui-argument"))
     self._argparser.add_argument('-a',
                                  '--host',
                                  metavar='hostname',
                                  type=str,
                                  help=getMessage("host-argument"))
     self._argparser.add_argument('-n',
                                  '--name',
                                  metavar='username',
                                  type=str,
                                  help=getMessage("name-argument"))
     self._argparser.add_argument('-d',
                                  '--debug',
                                  action='store_true',
                                  help=getMessage("debug-argument"))
     self._argparser.add_argument(
         '-g',
         '--force-gui-prompt',
         action='store_true',
         help=getMessage("force-gui-prompt-argument"))
     self._argparser.add_argument('--no-store',
                                  action='store_true',
                                  help=getMessage("no-store-argument"))
     self._argparser.add_argument('-r',
                                  '--room',
                                  metavar='room',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("room-argument"))
     self._argparser.add_argument('-p',
                                  '--password',
                                  metavar='password',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("password-argument"))
     self._argparser.add_argument('--player-path',
                                  metavar='path',
                                  type=str,
                                  help=getMessage("player-path-argument"))
     self._argparser.add_argument('--language',
                                  metavar='language',
                                  type=str,
                                  help=getMessage("language-argument"))
     self._argparser.add_argument('file',
                                  metavar='file',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("file-argument"))
     self._argparser.add_argument(
         '--clear-gui-data',
         action='store_true',
         help=getMessage("clear-gui-data-argument"))
     self._argparser.add_argument('-v',
                                  '--version',
                                  action='store_true',
                                  help=getMessage("version-argument"))
     self._argparser.add_argument('_args',
                                  metavar='options',
                                  type=str,
                                  nargs='*',
                                  help=getMessage("args-argument"))
     args = self._argparser.parse_args()
     if args.version:
         print(getMessage("version-message").format(version, milestone))
         sys.exit()
     self._overrideConfigWithArgs(args)
     if not self._config['noGui']:
         try:
             from syncplay.vendor.Qt import QtWidgets, IsPySide, IsPySide2
             from syncplay.vendor.Qt.QtCore import QCoreApplication
             from syncplay.vendor import qt5reactor
             if not (IsPySide2 or IsPySide):
                 raise ImportError
             if QCoreApplication.instance() is None:
                 self.app = QtWidgets.QApplication(sys.argv)
             qt5reactor.install()
             if isMacOS():
                 import appnope
                 appnope.nope()
         except ImportError:
             try:
                 from twisted.trial import unittest
             except:
                 print(getMessage("unable-import-twisted-error"))
                 sys.exit()
             print(getMessage("unable-import-gui-error"))
             self._config['noGui'] = True
     if self._config['file'] and self._config['file'][:2] == "--":
         self._config['playerArgs'].insert(0, self._config['file'])
         self._config['file'] = None
     # Arguments not validated yet - booleans are still text values
     if self._config['language']:
         setLanguage(self._config['language'])
     if (self._config['forceGuiPrompt'] == "True"
             or not self._config['file']) and not self._config['noGui']:
         self._forceGuiPrompt()
     self._checkConfig()
     self._saveConfig(iniPath)
     if self._config['file']:
         self._config[
             'loadedRelativePaths'] = self._loadRelativeConfiguration()
     if self._config['language']:
         setLanguage(self._config['language'])
     return self._config