Ignore:
Timestamp:
12/18/12 10:08:43 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Added support for a secondary instance (#157)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r298 r373  
    22
    33import const
     4from util import secondaryInstallation
    45
    56import os
    67import sys
     8import traceback
    79import ConfigParser
    810
    911## @package mlx.config
    10 # 
     12#
    1113# The handling of the configuration.
    1214#
     
    2224
    2325configPath = os.path.join(os.path.expanduser("~"),
    24                           "mlx.config" if os.name=="nt" else ".mlxrc")
     26                          "mlx.config" if os.name=="nt" else ".mlxrc") + \
     27                          ("-secondary" if secondaryInstallation else "")
    2528
    2629#-------------------------------------------------------------------------------
     
    5457        """Check if the given hotkey is not equal to the other one."""
    5558        return not self==other
    56        
     59
    5760    def __str__(self):
    5861        """Construct the hotkey to a string."""
     
    6972    # The name of the section of the checklists
    7073    SECTION="checklists"
    71    
     74
    7275    @staticmethod
    7376    def fromConfig(config, aircraftType):
     
    108111        """Determine if the checklist is not equal to the given other one."""
    109112        return not self==other
    110        
     113
    111114    def __len__(self):
    112115        """Get the length of the file list."""
     
    127130    # The name of the section of the approach callouts
    128131    SECTION="callouts"
    129    
     132
    130133    @staticmethod
    131134    def fromConfig(config, aircraftType):
     
    145148                break
    146149
    147         return ApproachCallouts(mapping)   
     150        return ApproachCallouts(mapping)
    148151
    149152    def __init__(self, mapping = None):
     
    211214
    212215    _messageTypesSection = "messageTypes"
    213    
     216
    214217    def __init__(self):
    215218        """Construct the configuration with default values."""
     
    222225        self._hideMinimizedWindow = True
    223226        self._quitOnClose = False
    224         self._onlineGateSystem = True
    225         self._onlineACARS = True
     227        self._onlineGateSystem = not secondaryInstallation
     228        self._onlineACARS = not secondaryInstallation
    226229        self._flareTimeFromFS = False
    227230        self._syncFSTime = False
     
    232235        self._pirepDirectory = None
    233236
    234         self._enableSounds = True
     237        self._enableSounds = not secondaryInstallation
    235238
    236239        self._pilotControlsSounds = True
     
    242245        self._enableChecklists = False
    243246        self._checklistHotkey = Hotkey(ctrl = True, shift = True, key = "0")
    244                
    245         self._autoUpdate = True       
     247
     248        self._autoUpdate = True
    246249        self._updateURL = Config.DEFAULT_UPDATE_URL
     250        if secondaryInstallation:
     251            self._updateURL += "/exp"
    247252
    248253        self._messageTypeLevels = {}
     
    253258            self._checklists[aircraftType] = Checklist()
    254259            self._approachCallouts[aircraftType] = ApproachCallouts()
    255            
     260
    256261        self._modified = False
    257262
     
    315320            self._hideMinimizedWindow = hideMinimizedWindow
    316321            self._modified = True
    317    
     322
    318323    @property
    319324    def quitOnClose(self):
     
    329334            self._quitOnClose = quitOnClose
    330335            self._modified = True
    331    
     336
    332337    @property
    333338    def onlineGateSystem(self):
     
    462467        return level==const.MESSAGELEVEL_FS or \
    463468               level==const.MESSAGELEVEL_BOTH
    464        
     469
    465470    def setMessageTypeLevel(self, messageType, level):
    466471        """Set the level of the given message type."""
     
    482487            self._modified = True
    483488
    484     @property 
     489    @property
    485490    def pilotControlsSounds(self):
    486491        """Get whether the pilot controls the background sounds."""
     
    529534            self._speedbrakeAtTD = speedbrakeAtTD
    530535            self._modified = True
    531        
     536
    532537    @property
    533538    def enableChecklists(self):
     
    600605    def load(self):
    601606        """Load the configuration from its default location."""
    602         config = ConfigParser.RawConfigParser()
    603         config.read(configPath)
     607        try:
     608            config = ConfigParser.RawConfigParser()
     609            config.read(configPath)
     610        except:
     611            traceback.print_exc()
     612            return
    604613
    605614        self._pilotID = self._get(config, "login", "id", "")
     
    615624        self._quitOnClose = self._getBoolean(config, "general",
    616625                                             "quitOnClose", False)
    617        
     626
    618627        self._onlineGateSystem = self._getBoolean(config, "general",
    619628                                                  "onlineGateSystem",
    620                                                   True)
     629                                                  not secondaryInstallation)
    621630        self._onlineACARS = self._getBoolean(config, "general",
    622                                              "onlineACARS", True)
     631                                             "onlineACARS",
     632                                             not secondaryInstallation)
    623633        self._flareTimeFromFS = self._getBoolean(config, "general",
    624634                                                 "flareTimeFromFS",
     
    644654                self._getMessageTypeLevel(config, messageType)
    645655
    646         self._enableSounds = self._getBoolean(config, "sounds",
    647                                               "enable", True)
     656        self._enableSounds = self._getBoolean(config, "sounds", "enable",
     657                                              not secondaryInstallation)
    648658        self._pilotControlsSounds = self._getBoolean(config, "sounds",
    649659                                                     "pilotControls", True)
     
    659669        self._checklistHotkey.set(self._get(config, "sounds",
    660670                                            "checklistHotkey", "CS0"))
    661            
     671
    662672        self._autoUpdate = self._getBoolean(config, "update", "auto", True)
    663673        self._updateURL = self._get(config, "update", "url",
    664                                     Config.DEFAULT_UPDATE_URL)
     674                                    Config.DEFAULT_UPDATE_URL +
     675                                    ("/exp" if secondaryInstallation else ""))
    665676
    666677        for aircraftType in const.aircraftTypes:
     
    714725            if messageType in self._messageTypeLevels:
    715726                option = self._getMessageTypeLevelOptionName(messageType)
    716                 level = self._messageTypeLevels[messageType]               
     727                level = self._messageTypeLevels[messageType]
    717728                config.set(Config._messageTypesSection, option,
    718729                           const.messageLevel2string(level))
     
    733744        config.set("sounds", "checklistHotkey",
    734745                   str(self._checklistHotkey))
    735        
     746
    736747        config.add_section("update")
    737748        config.set("update", "auto",
     
    760771               if config.has_option(section, option) \
    761772               else default
    762    
     773
    763774    def _get(self, config, section, option, default):
    764775        """Get the given option as a string, if found in the given config,
     
    774785            value = config.get(Config._messageTypesSection, option)
    775786            return const.string2messageLevel(value)
     787        elif secondaryInstallation:
     788            return const.MESSAGELEVEL_NONE
    776789        elif messageType in [const.MESSAGETYPE_LOGGER_ERROR,
    777790                             const.MESSAGETYPE_FAULT,
    778791                             const.MESSAGETYPE_NOGO,
    779792                             const.MESSAGETYPE_GATE_SYSTEM,
    780                              const.MESSAGETYPE_HELP]:           
     793                             const.MESSAGETYPE_HELP]:
    781794            return const.MESSAGELEVEL_BOTH
    782795        else:
Note: See TracChangeset for help on using the changeset viewer.