Changeset 1d95585


Ignore:
Timestamp:
03/18/12 01:23:10 (2 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
5c4b988
Parents:
768c39c
git-author:
xkolman2 <xkolman2@…> (03/18/12 01:23:10)
git-committer:
xkolman2 <xkolman2@…> (03/18/12 01:23:10)
Message:

add automatic configuration file upgrade support
make modRana actually save options
fix a few typos

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@691 0858a4d0-ffff-46e5-938e-62b5ecb34222

Files:
2 added
8 edited
3 moved

Legend:

Unmodified
Added
Removed
  • core/paths.py

    r7d1b4b7 r1d95585  
    4444    modrana_utils.createFolderPath(self.profileFolderPath) 
    4545 
     46    # load version string 
     47    self.versionString = None 
     48    self._loadVersionString() 
     49 
    4650 
    4751  ## Important modRana folders ## 
     
    6569    path = None 
    6670    # first check if the user overrode the tracklog folder path 
    67     config = self.modrana.m.get('config', None) 
     71    config = self.modrana.configs.getUserConfig() 
    6872    if config: 
    69       path = config.getTracklogFolderPath() 
     73      path = config.get("tracklog_folder", None) 
    7074    if path == None: 
    7175    # try to get the path from device module 
     
    8387    path = None 
    8488    # first check if the user overrode the map folder path 
    85     config = self.modrana.m.get('config', None) 
     89    config = self.modrana.configs.getUserConfig() 
    8690    if config: 
    87       path = config.getMapFolderPath() 
     91      path = config.get("map_folder", None) 
    8892    if path == None: 
    8993    # try to get the path from device module 
     
    125129      return self._assurePathFolder(self.getProfilePath(), "debug_logs") 
    126130 
     131  def getVersionString(self): 
     132    """ 
     133    return current version string or None if not available 
     134    """ 
     135    return self.versionString 
     136 
     137  def _loadVersionString(self): 
     138    """ 
     139    load version string from file 
     140    """ 
     141    self.versionString = None 
     142    versionFilePath = 'version.txt' 
     143    # try read the version file 
     144    if os.path.exists(versionFilePath): 
     145      try: 
     146        f = open(self.versionFilePath, 'r') 
     147        versionString = f.read() 
     148        f.close() 
     149        # is it really string ? 
     150        versionString = str(versionString) 
     151        self.versionString = versionString 
     152      except Exception, e: 
     153        print "modRana config: loading version info failed" 
     154        print e 
     155 
    127156  def _assurePathFolder(self, path, folder): 
    128157    """combine the given path and folder and make sure the path exists, 
  • data/default_configuration_files/map_config.conf

    r69cf542 r1d95585  
    11## this config file configures the available map layers 
     2 
     3revision=1 ## configuration file revision 
    24 
    35## tile coordinates are layer name specific for now 
     
    79## all variables must be filled in 
    810 
    9 [osma] 
     11## Layers section 
     12[layers] 
     13 
     14[[osma]] 
    1015  label=OSM T@h 
    1116  url=http://tah.openstreetmap.org/Tiles/tile/ 
     
    1621  coordinates=osm 
    1722 
    18 [mapnik] 
     23[[mapnik]] 
    1924  label=OSM Mapnik 
    2025  url=http://tile.openstreetmap.org/ 
     
    2530  coordinates=osm 
    2631 
    27 [gmap] 
     32[[gmap]] 
    2833  label=Google maps 
    2934  url=http://mt1.google.com/vt/ 
     
    3439  coordinates=google 
    3540 
    36 [gsat] 
     41[[gsat]] 
    3742  label=Google satelite 
    3843  url=http://khm1.google.com/kh/v=54 
     
    4449  coordinates=google 
    4550 
    46 [gover] 
     51[[gover]] 
    4752  label=Google overlay 
    4853  url=http://mt1.google.com/vt/lyrs=h 
     
    5358  coordinates=google 
    5459 
    55 [vmap] 
     60[[vmap]] 
    5661  label=Virtual Earth-map 
    5762  url=http://tiles.virtualearth.net/tiles/r 
     
    6267  coordinates=quadtree 
    6368 
    64 [vsat] 
     69[[vsat]] 
    6570  label=Virtual Earth-sat h. 
    6671  url=http://tiles.virtualearth.net/tiles/h 
     
    7075  folder_prefix=Virtual Earth Hybrid 
    7176  coordinates=quadtree 
    72 [ymap] 
     77[[ymap]] 
    7378  label=Yahoo map 
    7479  url=http://maps.yimg.com/hx/tl?&s=256 
     
    8489  coordinates=yahoo 
    8590 
    86 [ysat] 
     91[[ysat]] 
    8792  label=Yahoo sat 
    8893  url=http://maps.yimg.com/ae/ximg?&t=a&s=256 
     
    9398  coordinates=yahoo 
    9499 
    95 [yover] 
     100[[yover]] 
    96101  label=Yahoo overlay 
    97102  url=http://maps.yimg.com/ae/ximg?&t=h&s=256 
     
    102107  coordinates=yahoo 
    103108 
    104 [cycle] 
     109[[cycle]] 
    105110  label=Cycle map 
    106111## old URL that doesn't like batch downloads 
     
    114119  coordinates=osm 
    115120 
    116 [cz_mtb] 
     121[[cz_mtb]] 
    117122  label=Czech MTB 
    118123  url=http://tchor.fi.muni.cz:8080/mtbmap_tiles/ 
     
    124129 
    125130# url not working 
    126 #[FinnTopomaps] 
     131#[[FinnTopomaps]] 
    127132#  label=Finnish topomaps 
    128133#  url=http://tableteer.nokia.com:80                                                  © NLS 20O8 …þ@topomaps.tableteer.nokia.com/_tTilesD/ 
     
    134139 
    135140#iso3d has unfortunately incompatible projection 
    136 #[cz_iso3d] 
     141#[[cz_iso3d]] 
    137142#  label=CZ Isometric 3D 
    138143#  url=http://osm.kyblsoft.cz/3dmapa/tiles/ 
  • data/default_configuration_files/user_config.conf

    rb94c15f r1d95585  
    2020 
    2121enabled=True       ## True -> config will be used, False -> config wont be used 
     22 
     23revision=1 ## configuration file revision 
    2224 
    2325## ==>Map folder configuration<== 
  • modrana.py

    r6963cec r1d95585  
    3939from core import startup 
    4040from core import paths 
     41from core import configs 
    4142from core import gs 
    4243 
     
    115116    # add the paths handling core module 
    116117    self.paths = paths.Paths(self) 
     118    # add the configs handling core module 
     119    self.configs = configs.Configs(self) 
    117120 
    118121    # load persistant options 
    119122    self.optLoadingOK= self._loadOptions() 
    120123 
    121     # load map layer info 
    122     self.loadMapLayerInfo() 
     124    # check if upgrade took place 
     125 
     126    if self.optLoadingOK: 
     127      savedVersionString = self.get('modRanaVersionString', "") 
     128      versionStringFromFile = self.paths.getVersionString() 
     129      if savedVersionString != versionStringFromFile: 
     130        print "modRana: possible upgrade detected" 
     131        self._postUpgradeCheck() 
     132 
     133    # save current version string 
     134    self.set('modRanaVersionString', self.paths.getVersionString()) 
     135 
     136    # load all configuration files 
     137    self.configs.loadAll() 
     138 
    123139    # start loading modules 
    124140    self.loadModules() 
    125141    # startup done, print some statistics 
    126142    self._startupDone() 
     143 
     144  def _postUpgradeCheck(self): 
     145    """ 
     146    perform post upgrade checks 
     147    """ 
     148    self.configs.upgradeConfigFiles() 
    127149 
    128150  ##  MODULE HANDLING ## 
     
    317339    when finished 
    318340    """ 
    319     self.beforeDie() 
    320  
    321   def beforeDie(self): 
    322       print("Shutting-down modules") 
    323       for m in self.m.values(): 
    324         m.shutdown() 
    325       time.sleep(2) # leave some times for threads to shut down 
    326       print("Shuttdown complete") 
     341    print("Shutting-down modules") 
     342    for m in self.m.values(): 
     343      m.shutdown() 
     344    self._saveOptions() 
     345    time.sleep(2) # leave some times for threads to shut down 
     346    print("Shuttdown complete") 
    327347     
    328348  ## OPTIONS SETTING AND WATCHING ## 
     
    697717 
    698718  ## MAP LAYERS ## 
    699   """map lyer information is important and needed by many modules during their initialization, 
     719  """map layer information is important and needed by many modules during their initialization, 
    700720  so it is handled here""" 
    701721  def getMapLayers(self): 
    702     return self.mapLayers 
    703  
    704   def loadMapLayerInfo(self): 
    705     mapLayers = {} 
    706     configVariables = { 
    707         'label':'label', 
    708         'url':'tiles', 
    709         'max_zoom':'maxZoom', 
    710         'min_zoom':'minZoom', 
    711         'type':'type', 
    712         'folder_prefix':'folderPrefix', 
    713         'coordinates':'coordinates', 
    714                       } 
    715     mapConfigPath = os.path.join(self.getProfilePath(),'map_config.conf') 
    716     # check if the configuration files are there already 
    717     if not os.path.exists(mapConfigPath): 
    718       # nthing in prfile folder -> try to use the default configs 
    719       print("modRana: no config in profile folder, using default map layer configuration file") 
    720       mapConfigPath = os.path.join("data/default_configuration_files",'map_config.conf') 
    721       if not os.path.exists(mapConfigPath): 
    722         # no map layer config available 
    723         print("modRana: map layer configuration file not available") 
    724         return 
    725  
    726     def allNeededIn(needed, dict): 
    727       for key in needed: 
    728         if key in dict: 
    729           continue 
    730         else: 
    731           return False 
    732       return True   
    733  
    734     try: 
    735       config = ConfigObj(mapConfigPath) 
    736       for layer in config: 
    737         if allNeededIn(configVariables.keys(), config[layer].keys()): # check if all neded keys are available 
    738           tempDict = {} 
    739           for var in configVariables: 
    740             tempDict[configVariables[var]] = config[layer][var] 
    741           tempDict['minZoom'] = int(tempDict['minZoom']) # convert strings to integers 
    742           tempDict['maxZoom'] = int(tempDict['maxZoom']) 
    743         else: 
    744           print("mapTiles: layer is badly defined/formated: %s" % layer) 
    745  
    746  
    747         mapLayers[layer] = tempDict 
    748  
    749     except Exception, e: 
    750       print("mapTiles: loading map_config.conf failed: %s" % e) 
    751  
    752     self.mapLayers = mapLayers 
    753  
     722    print "GET MAP LAYERS" 
     723    return self.configs.getMapLayers() 
    754724 
    755725  ## STARTUP TIMING ## 
  • modules/configobj/configobj.py

    r768c39c r1d95585  
    21562156                # We do this once to remove a top level dependency on the validate module 
    21572157                # Which makes importing configobj faster 
    2158                 from core.configobj.validate import VdtMissingValue 
     2158                from modules.configobj.validate import VdtMissingValue 
    21592159                self._vdtMissingValue = VdtMissingValue 
    21602160                 
  • modules/mod_config.py

    r30bff6f1 r1d95585  
    2222#--------------------------------------------------------------------------- 
    2323from base_module import ranaModule 
    24 from configobj import ConfigObj 
    2524import os 
    26 import shutil 
    2725 
    2826def getModule(m,d,i): 
     
    3331  def __init__(self, m, d, i): 
    3432    ranaModule.__init__(self, m, d, i) 
    35     self.userConfigPath = 'user_config.conf' 
    36     self.userConfig = {} 
    37  
    38     """ make sure the config files are present 
    39     in the profile folder""" 
    40     self.checkConfigs() 
    41     """parse the main configration file""" 
    42     userConfPath = os.path.join(self.modrana.getProfilePath(), 'user_config.conf') 
    43     self.parseUserConfig(userConfPath) 
    4433 
    4534  def firstTime(self): 
    4635 
    47     # *** Various hardcoded peristant variables *** 
     36    # *** Various hardcoded persistent variables *** 
    4837 
    4938    # Option: Number of threads for batch-downloading tiles 
     
    5948    # this sets the number of threads used for determining the size of the batch (from http headers) 
    6049    # NOTE: even though we are downloading only the headers, 
    61     # for a few tousand tiles this can be an untrival amount of data 
     50    # for a few thousand tiles this can be an un-trivial amount of data 
    6251    # (so use this with caution on metered connections) 
    6352    self.set('maxSizeThreads', 20) 
     
    6857    # Option: set your start position 
    6958    #self.set("pos", (49.2, 16.616667)) # Brno 
    70  
    71   def checkConfigs(self): 
    72     """assure that configuration files are available in the profile folder""" 
    73     profilePath = self.modrana.getProfilePath() 
    74     configs = ["map_config.conf", "user_config.conf"] 
    75     for config in configs: 
    76       configPath = os.path.join(profilePath, config) 
    77       if not os.path.exists(configPath): 
    78         try: 
    79           source = os.path.join("data/default_configuration_files", config) 
    80           print(" ** config:copying default configuration file to profile folder") 
    81           print(" ** from: %s" % source) 
    82           print(" ** to: %s" % configPath) 
    83           shutil.copy(source, configPath) 
    84           print(" ** DONE") 
    85         except Exception, e: 
    86           print("config: copying default configuration file to profile folder failed", e) 
    87  
    88   def getMapFolderPath(self): 
    89     """return the prefered map folder path from the user 
    90     configuration file an None if no such path is specified""" 
    91     if 'map_folder' in self.userConfig: 
    92       return self.userConfig['map_folder'] 
    93     else: 
    94       return None 
    95  
    96   def getTracklogFolderPath(self): 
    97     """return the prefered tracklog folder path from the user 
    98     configuration file an None if no such path is specified""" 
    99     if 'tracklog_folder' in self.userConfig: 
    100       return self.userConfig['tracklog_folder'] 
    101     else: 
    102       return None 
    103  
    104   def parseUserConfig(self, path): 
    105     """Par user created configuration file.""" 
    106  
    107     try: 
    108       config = ConfigObj(path) 
    109       if 'enabled' in config: 
    110         if config['enabled'] == 'True': 
    111           self.userConfig = config         
    112  
    113     except Exception, e: 
    114       print "config: loading user_config.conf failed" 
    115       print "config: check the syntax" 
    116       print "config: and if the config file is present in the main directory" 
    117       print "config: this happended:\n%s\nconfig: thats all" % e 
  • modules/mod_info.py

    r30bff6f1 r1d95585  
    3131    ranaModule.__init__(self, m, d, i) 
    3232    self.versionString = "unknown version" 
    33     self.versionFilePath = 'version.txt' 
    34     # try read the version file 
    35     if os.path.exists(self.versionFilePath): 
    36       try: 
    37         f = open(self.versionFilePath, 'r') 
    38         versionString = f.read() 
    39         f.close() 
    40         # is it really string ? 
    41         versionString = str(versionString) 
    42         self.versionString = versionString 
    43       except Exception, e: 
    44         print "loading version info failed" 
    45         print e 
    46  
     33    currentVersionString = self.modrana.paths.getVersionString() 
     34    if currentVersionString != None: 
     35      # check version string validity 
     36      self.versionString = currentVersionString 
    4737 
    4838  def drawMenu(self, cr, menuName, args=None): 
  • modules/mod_menu.py

    r7d1b4b7 r1d95585  
    4646    self.fullscreen = False 
    4747    self.mainScreenCoords = {} 
    48     self.userConfig = {} 
     48    self.userConfig = self.modrana.configs.getUserConfig() 
    4949    self.hideMapSreenButtons = False 
    5050    self.lastHideCheckTimestamp = time.time() 
     
    14191419  def firstTime(self): 
    14201420    self.set("menu",None) 
    1421     self.userConfig = self.m.get('config', None).userConfig 
    1422     # get the notification module (to implement the master overlay) 
    14231421 
    14241422    icons = self.m.get('icons', None) 
  • modules/mod_showOSD.py

    r7d1b4b7 r1d95585  
    6363    """ draw currenty active information widgets TODO: just draw object from list""" 
    6464    if self.m.get('config', {}): 
    65       config = self.m.get('config', None).userConfig 
     65      config = self.modrana.configs.getUserConfig() 
    6666 
    6767      mode = self.get('mode', None) 
Note: See TracChangeset for help on using the changeset viewer.