commit/StationPlaylist: josephsl: Disk I/O: small yet significant optimizations.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Fri, 21 Aug 2015 06:05:26 -0000

1 new commit in StationPlaylist:

https://bitbucket.org/nvdaaddonteam/stationplaylist/commits/28b9bb4b2e8e/
Changeset: 28b9bb4b2e8e
Branch: master
User: josephsl
Date: 2015-08-21 06:04:48+00:00
Summary: Disk I/O: small yet significant optimizations.

The default config and its validator partner is now a private data structure of
the config module. Among other things, this removes duplicate code and to check
vlaues against when saving confi database.
Also, when cpying a profile, do noot copy the file. Instead, an in-memory copy
will be performed, with disk writes reserved for save config function.
There might be a possibility of backporting this to add-on 5.x.

Affected #: 1 file

diff --git a/addon/appModules/splstudio/splconfig.py
b/addon/appModules/splstudio/splconfig.py
index 4f3219a..58108a2 100755
--- a/addon/appModules/splstudio/splconfig.py
+++ b/addon/appModules/splstudio/splconfig.py
@@ -42,6 +42,10 @@ confspec.newlines = "\r\n"
SPLConfig = None
# A pool of broadcast profiles.
SPLConfigPool = []
+# Default config spec container.
+_SPLDefaults = ConfigObj(None, configspec = confspec, encoding="UTF-8")
+_val = Validator()
+_SPLDefaults.validate(_val, copy=True)

# The following settings can be changed in profiles:

_mutatableSettings=("SayEndOfTrack","EndOfTrackTime","SaySongRamp","SongRampTime","MicAlarm")
@@ -105,23 +109,19 @@ def unlockConfig(path, profileName=None, prefill=False):
global _configLoadStatus # To be mutated only during unlock routine.
SPLConfigCheckpoint = ConfigObj(path, configspec = confspec,
encoding="UTF-8")
# 5.2 and later: check to make sure all values are correct.
- val = Validator()
- configTest = SPLConfigCheckpoint.validate(val, copy=prefill)
+ configTest = SPLConfigCheckpoint.validate(_val, copy=prefill)
if configTest != True:
- # Hack: have a dummy config obj handy just for storing default
values.
- SPLDefaults = ConfigObj(None, configspec = confspec,
encoding="UTF-8")
- SPLDefaults.validate(val, copy=True)
# Translators: Standard error title for configuration error.
title = _("Studio add-on Configuration error")
if not configTest:
# Case 1: restore settings to defaults when 5.x config
validation has failed on all values.
- resetConfig(SPLDefaults, SPLConfigCheckpoint)
+ resetConfig(_SPLDefaults, SPLConfigCheckpoint)
_configLoadStatus[profileName] = "completeReset"
elif isinstance(configTest, dict):
# Case 2: For 5.x and later, attempt to reconstruct the
failed values.
for setting in configTest:
if not configTest[setting]:
- SPLConfigCheckpoint[setting] =
SPLDefaults[setting]
+ SPLConfigCheckpoint[setting] =
_SPLDefaults[setting]
SPLConfigCheckpoint.write()
_configLoadStatus[profileName] = "partialReset"
_extraInitSteps(SPLConfigCheckpoint, profileName=profileName)
@@ -166,10 +166,16 @@ def isConfigPoolSorted():

# Perform some extra work before writing the config file.
def _preSave(conf):
- #conf["ColumnOrder"] = ",".join(conf["ColumnOrder"])
- conf["IncludedColumns"] = list(conf["IncludedColumns"])
+ # Perform global setting processing only for the normal profile.
+ if SPLConfigPool.index(conf) == 0:
+ conf["IncludedColumns"] = list(conf["IncludedColumns"])
+ # For other profiles, remove global settings before writing to disk.
+ else:
+ for setting in conf.keys():
+ if setting not in _mutatableSettings or (setting in
_mutatableSettings and conf[setting] == _SPLDefaults[setting]):
+ del conf[setting]

- # Save configuration database.
+# Save configuration database.
def saveConfig():
# Save all config profiles.
global SPLConfig, SPLConfigPool, SPLActiveProfile, SPLPrevProfile,
SPLSwitchProfile
@@ -620,13 +626,10 @@ class SPLConfigDialog(gui.SettingsDialog):
# Translators: The title of the warning dialog.
_("Warning"),wx.YES_NO|wx.NO_DEFAULT|wx.ICON_WARNING,self
)==wx.YES:
- val = Validator()
- SPLDefaults = ConfigObj(None, configspec = confspec,
encoding="UTF-8")
- SPLDefaults.validate(val, copy=True)
# Reset the selected config only.
global SPLConfig
SPLConfig =
getProfileByName(self.profiles.GetStringSelection())
- resetConfig(SPLDefaults, SPLConfig, intentional=True)
+ resetConfig(_SPLDefaults, SPLConfig, intentional=True)
self.Destroy()


@@ -698,12 +701,14 @@ class NewProfileDialog(wx.Dialog):
namePath = name + ".ini"
if not os.path.exists(SPLProfiles):
os.mkdir(SPLProfiles)
- newProfile = os.path.join(SPLProfiles, namePath)
+ newProfilePath = os.path.join(SPLProfiles, namePath)
+ SPLConfigPool.append(unlockConfig(newProfilePath,
profileName=name))
+ newProfile = SPLConfigPool[-1]
if self.copy:
- import shutil
baseProfile =
getProfileByName(self.baseProfiles.GetStringSelection())
- shutil.copy2(baseProfile.filename, newProfile)
- SPLConfigPool.append(unlockConfig(newProfile, profileName=name))
+ for setting in baseProfile:
+ if baseProfile[setting] != newProfile[setting]:
+ newProfile[setting] =
baseProfile[setting]
parent = self.Parent
parent.profiles.Append(name)
parent.profiles.Selection = parent.profiles.Count - 1

Repository URL: https://bitbucket.org/nvdaaddonteam/stationplaylist/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Other related posts:

  • » commit/StationPlaylist: josephsl: Disk I/O: small yet significant optimizations. - commits-noreply