Skip to content

Commit

Permalink
WIP cache getting target ini settings:
Browse files Browse the repository at this point in the history
That's me debugging parent and re-realizing we were stat'ing main ini
over and over again - WIP in the sense of #353 but good enough for now.

Under #326
  • Loading branch information
Utumno committed Dec 13, 2020
1 parent 80eeec7 commit 9946a83
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
21 changes: 14 additions & 7 deletions Mopy/bash/balt.py
Expand Up @@ -908,6 +908,7 @@ class UIList(wx.Panel):
#--DnD
_dndFiles = _dndList = False
_dndColumns = ()
_target_ini = False # pass the target_ini settings on PopulateItem

def __init__(self, parent, keyPrefix, listData=None, panel=None):
wx.Panel.__init__(self, _AComponent._resolve(parent), style=wx.WANTS_CHARS)
Expand Down Expand Up @@ -1001,7 +1002,7 @@ def _select(self, item): self.panel.SetDetails(item)
def item_count(self): return self.__gList.lc_item_count()

#--Items ----------------------------------------------
def PopulateItem(self, itemDex=-1, item=None):
def PopulateItem(self, itemDex=-1, item=None, target_ini_setts=None):
"""Populate ListCtrl for specified item. Either item or itemDex must be
specified.
:param itemDex: the index of the item in the list - must be given if
Expand All @@ -1024,7 +1025,7 @@ def PopulateItem(self, itemDex=-1, item=None):
self.__gList.InsertListCtrlItem(itemDex, labelTxt, item)
else:
self.__gList._native_widget.SetItem(itemDex, colDex, labelTxt)
self.__setUI(item, itemDex)
self.__setUI(item, itemDex, target_ini_setts)

class _ListItemFormat(object):
def __init__(self):
Expand All @@ -1035,18 +1036,18 @@ def __init__(self):
self.italics = False
self.underline = False

def set_item_format(self, item, item_format):
def set_item_format(self, item, item_format, target_ini_setts):
"""Populate item_format attributes for text and background colors
and set icon, font and mouse text. Responsible (applicable if the
data_store is a FileInfo subclass) for calling getStatus (or
tweak_status in Inis) to update respective info's status."""
pass # screens, bsas

def __setUI(self, fileName, itemDex):
def __setUI(self, fileName, itemDex, target_ini_setts):
"""Set font, status icon, background text etc."""
gItem = self.__gList._native_widget.GetItem(itemDex)
df = self._ListItemFormat()
self.set_item_format(fileName, df)
self.set_item_format(fileName, df, target_ini_setts=target_ini_setts)
if df.icon_key and self.icons:
if isinstance(df.icon_key, tuple):
img = self.icons.Get(*df.icon_key)
Expand All @@ -1067,17 +1068,23 @@ def PopulateItems(self):
"""Sort items and populate entire list."""
self.mouseTexts.clear()
items = set(self.data_store.keys())
if self.__class__._target_ini:
# hack for avoiding the syscall in get_ci_settings
target_setts = self.data_store.ini.get_ci_settings()
else:
target_setts = None
#--Update existing items.
index = 0
while index < self.item_count:
item = self.GetItem(index)
if item not in items: self.__gList.RemoveItemAt(index)
else:
self.PopulateItem(itemDex=index)
self.PopulateItem(itemDex=index, target_ini_setts=target_setts)
items.remove(item)
index += 1
#--Add remaining new items
for item in items: self.PopulateItem(item=item)
for item in items:
self.PopulateItem(item=item, target_ini_setts=target_setts)
#--Sort
self.SortItems()
self.autosizeColumns()
Expand Down
23 changes: 12 additions & 11 deletions Mopy/bash/basher/__init__.py
Expand Up @@ -414,7 +414,7 @@ def GetMasterStatus(self, mi):
else:
return status # 0, Green

def set_item_format(self, mi, item_format):
def set_item_format(self, mi, item_format, target_ini_setts):
masterInfo = self.data_store[mi]
masters_name = masterInfo.curr_name
#--Font color
Expand Down Expand Up @@ -558,14 +558,15 @@ class INIList(balt.UIList):
}
def _sortValidFirst(self, items):
if settings['bash.ini.sortValid']:
items.sort(key=lambda a: self.data_store[a].tweak_status < 0)
items.sort(key=lambda a: self.data_store[a].tweak_status() < 0)
_extra_sortings = [_sortValidFirst]
#--Labels
labels = OrderedDict([
('File', lambda self, p: p.s),
('Installer', lambda self, p: self.data_store.table.getItem(
p, u'installer', u'')),
])
_target_ini = True # pass the target_ini settings on PopulateItem

@property
def current_ini_name(self): return self.panel.detailsPanel.ini_name
Expand All @@ -579,7 +580,7 @@ def CountTweakStatus(self):
not_applied = 0
invalid = 0
for ini_info in self.data_store.itervalues():
status = ini_info.tweak_status
status = ini_info.tweak_status()
if status == -10: invalid += 1
elif status == 0: not_applied += 1
elif status == 10: mismatch += 1
Expand All @@ -591,7 +592,7 @@ def ListTweaks(self):
tweaklist = _(u'Active Ini Tweaks:') + u'\n'
tweaklist += u'[spoiler]\n'
for tweak, info in sorted(self.data_store.items(), key=itemgetter(0)):
if not info.tweak_status == 20: continue
if not info.tweak_status() == 20: continue
tweaklist+= u'%s\n' % tweak
tweaklist += u'[/spoiler]\n'
return tweaklist
Expand All @@ -605,9 +606,9 @@ def _toDelete(self, items):
items = super(INIList, self)._toDelete(items)
return self.filterOutDefaultTweaks(items)

def set_item_format(self, ini_name, item_format):
def set_item_format(self, ini_name, item_format, target_ini_setts):
iniInfo = self.data_store[ini_name]
status = iniInfo.tweak_status
status = iniInfo.tweak_status(target_ini_setts)
#--Image
checkMark = 0
icon = 0 # Ok tweak, not applied
Expand Down Expand Up @@ -665,7 +666,7 @@ def apply_tweaks(cls, tweak_infos, target_ini=None):
if target_ini: # if target was given calculate the status for it
stat = ini_info.getStatus(target_ini_file)
ini_info.reset_status() # iniInfos.ini may differ from target
else: stat = ini_info.tweak_status
else: stat = ini_info.tweak_status()
if stat == 20 or not ini_info.is_applicable(stat): continue
needsRefresh |= target_ini_file.applyTweakFile(
ini_info.read_ini_content())
Expand Down Expand Up @@ -881,7 +882,7 @@ def _refreshOnDrop(self):
self.RefreshUI(refreshSaves=True)

#--Populate Item
def set_item_format(self, mod_name, item_format):
def set_item_format(self, mod_name, item_format, target_ini_setts):
mod_info = self.data_store[mod_name]
#--Image
status = mod_info.getStatus()
Expand Down Expand Up @@ -1966,7 +1967,7 @@ def _unhide_wildcard():
u'Save files') + u' (' + starred + u')|' + starred

#--Populate Item
def set_item_format(self, fileName, item_format):
def set_item_format(self, fileName, item_format, target_ini_setts):
save_info = self.data_store[fileName]
#--Image
status = save_info.getStatus()
Expand Down Expand Up @@ -2227,7 +2228,7 @@ def _sortProjects(self, items):
_type_textKey = {1: 'default.text', 2: 'installers.text.complex'}

#--Item Info
def set_item_format(self, item, item_format):
def set_item_format(self, item, item_format, target_ini_setts):
inst = self.data_store[item] # type: bosh.bain.Installer
#--Text
if inst.type == 2 and len(inst.subNames) == 2:
Expand Down Expand Up @@ -3462,7 +3463,7 @@ def _karma(personData):
self.data_store[name_][2].split(u'\n', 1)[0][:75]),
])

def set_item_format(self, item, item_format):
def set_item_format(self, item, item_format, target_ini_setts):
item_format.icon_key = u'karma%+d' % self.data_store[item][1]

#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Mopy/bash/basher/ini_links.py
Expand Up @@ -72,7 +72,7 @@ class INI_ListErrors(EnabledLink):
_help = _(u'Lists any errors in the tweak file causing it to be invalid.')

def _enable(self):
return any(imap(lambda inf: inf.tweak_status < 0,
return any(imap(lambda inf: inf.tweak_status() < 0,
self.iselected_infos()))

def Execute(self):
Expand Down
15 changes: 8 additions & 7 deletions Mopy/bash/bosh/__init__.py
Expand Up @@ -911,9 +911,9 @@ def _reset_cache(self, stat_tuple, load_cache):
super(INIInfo, self)._reset_cache(stat_tuple, load_cache)
if load_cache: self._status = None ##: is the if check needed here?

@property
def tweak_status(self):
if self._status is None: self.getStatus()
def tweak_status(self, target_ini_settings=None):
if self._status is None:
self.getStatus(target_ini_settings=target_ini_settings)
return self._status

@property
Expand All @@ -925,11 +925,11 @@ def _incompatible(self, other):
return not isinstance(other, OBSEIniFile)

def is_applicable(self, stat=None):
stat = stat or self.tweak_status
stat = stat or self.tweak_status()
return stat != -20 and (
bass.settings['bash.ini.allowNewLines'] or stat != -10)

def getStatus(self, target_ini=None):
def getStatus(self, target_ini=None, target_ini_settings=None):
"""Returns status of the ini tweak:
20: installed (green with check)
15: mismatches (green with dot) - mismatches are with another tweak from same installer that is applied
Expand All @@ -948,7 +948,8 @@ def _status(s):
return _status(-20)
match = False
mismatch = 0
ini_settings = target_ini.get_ci_settings()
ini_settings = target_ini_settings if target_ini_settings is not None \
else target_ini.get_ci_settings()
self_installer = infos.table.getItem(self.abs_path.tail, u'installer')
for section_key in tweak_settings:
if section_key not in ini_settings:
Expand Down Expand Up @@ -2947,7 +2948,7 @@ def rightFileType(cls, fileName):
def bash_dir(self): return self.store_dir.join(u'Bash')

def refresh(self, refresh_infos=True, booting=False):
self._refreshLocalSave()
if not booting: self._refreshLocalSave() # otherwise we just did this
return refresh_infos and FileInfos.refresh(self, booting=booting)

def _rename_operation(self, oldName, newName):
Expand Down

0 comments on commit 9946a83

Please sign in to comment.