Changeset 40:aaf5cd877e21 for src/mlx
- Timestamp:
- 03/09/12 19:00:30 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/config.py
r36 r40 1 1 # Configuration and related stuff 2 3 #------------------------------------------------------------------------------- 4 5 import os 6 import ConfigParser 7 8 #------------------------------------------------------------------------------- 9 10 configPath = os.path.join(os.path.expanduser("~"), 11 "mlx.config" if os.name=="nt" else ".mlxrc") 2 12 3 13 #------------------------------------------------------------------------------- … … 5 15 class Config(object): 6 16 """Our configuration.""" 17 DEFAULT_UPDATE_URL = "http://mlx.varadiistvan.hu/update" 18 7 19 def __init__(self): 8 20 """Construct the configuration with default values.""" 9 self.autoUpdate = True 10 11 self.updateURL = \ 12 "http://mlx.varadiistvan.hu/update" 21 22 self._autoUpdate = True 23 self._updateURL = Config.DEFAULT_UPDATE_URL 24 25 self._modified = False 26 27 @property 28 def autoUpdate(self): 29 """Get if an automatic update is needed.""" 30 return self._autoUpdate 31 32 @autoUpdate.setter 33 def autoUpdate(self, autoUpdate): 34 """Set if an automatic update is needed.""" 35 if autoUpdate!=self._autoUpdate: 36 self._autoUpdate = autoUpdate 37 self._modified = True 38 39 @property 40 def updateURL(self): 41 """Get the update URL.""" 42 return self._updateURL 43 44 @updateURL.setter 45 def updateURL(self, updateURL): 46 """Set the update URL.""" 47 if updateURL!=self._updateURL: 48 self._updateURL = updateURL 49 self._modified = True 50 51 def load(self): 52 """Load the configuration from its default location.""" 53 config = ConfigParser.RawConfigParser() 54 config.read(configPath) 55 56 self._autoUpdate = self._getBoolean(config, "update", "auto", True) 57 self._updateURL = self._get(config, "update", "url", 58 Config.DEFAULT_UPDATE_URL) 59 self._modified = False 60 61 def save(self): 62 """Save the configuration file if it has been modified.""" 63 if not self._modified: 64 return 65 66 config = ConfigParser.RawConfigParser() 67 68 config.add_section("update") 69 config.set("update", "auto", self._autoUpdate) 70 config.set("update", "url", self._updateURL) 71 72 try: 73 with open(configPath, "wt") as f: 74 config.write(f) 75 self._modified = False 76 except Exception, e: 77 print >> sys.stderr("Failed to update config: " + str(e)) 78 79 def _getBoolean(self, config, section, option, default): 80 """Get the given option as a boolean, if found in the given config, 81 otherwise the default.""" 82 return config.getboolean(section, option) \ 83 if config.has_option(section, option) \ 84 else default 85 86 def _get(self, config, section, option, default): 87 """Get the given option as a string, if found in the given config, 88 otherwise the default.""" 89 return config.get(section, option) \ 90 if config.has_option(section, option) \ 91 else default 13 92 14 93 #------------------------------------------------------------------------------- -
src/mlx/mlx.py
r38 r40 30 30 31 31 config = Config() 32 config.load() 33 32 34 gui = GUI(programDirectory, config) 33 35 … … 44 46 sys.stderr = sys.__stderr__ 45 47 48 config.save() 49 46 50 if gui.toRestart: 47 51 programPath = os.path.join(os.path.dirname(sys.argv[0]),
Note:
See TracChangeset
for help on using the changeset viewer.