Coding style.
- Simplify thread safe code since no longer usings threads. - Don't store pickle_path unnecessarily. Save memory. - Change Row's style to match Column.
This commit is contained in:
parent
a2aaa201c5
commit
4742d152c8
3 changed files with 21 additions and 22 deletions
|
|
@ -91,7 +91,7 @@ class Entry:
|
|||
self.path = path
|
||||
self.summary = summary
|
||||
self.highlighted = highlighted
|
||||
self.widgets = results
|
||||
self.results = results
|
||||
if set_results:
|
||||
# FIX: this is missed for entries appended later
|
||||
for result in results:
|
||||
|
|
@ -104,25 +104,24 @@ class Entry:
|
|||
return self.path == other.path
|
||||
|
||||
def __len__(self):
|
||||
return len(self.widgets)
|
||||
return len(self.results)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.widgets[index]
|
||||
return self.results[index]
|
||||
|
||||
def appearance_min(self):
|
||||
appearance = self.appearance_cache
|
||||
if appearance is None or self.last_width != self.summary._max_width:
|
||||
if self.appearance_cache is None \
|
||||
or self.last_width != self.summary._max_width:
|
||||
self.last_width = self.summary._max_width
|
||||
if self.highlighted is not None:
|
||||
self.widget[self.highlighted].is_highlighted = True
|
||||
new_appearance = self.widget.appearance_min()
|
||||
self.results[self.highlighted].is_highlighted = True
|
||||
row_appearance = self.widget.appearance_min()
|
||||
path = tools.path_colored(self.path)
|
||||
padding = " " * (self.last_width - len(self.widget) + 1)
|
||||
new_appearance[0] = new_appearance[0] + padding + path
|
||||
self.appearance_cache = appearance = new_appearance
|
||||
padding = " " * (self.last_width - len(self.results) + 1)
|
||||
self.appearance_cache = [row_appearance[0] + padding + path]
|
||||
if self.highlighted is not None:
|
||||
self.widget[self.highlighted].is_highlighted = False
|
||||
return appearance
|
||||
self.results[self.highlighted].is_highlighted = False
|
||||
return self.appearance_cache
|
||||
|
||||
def as_html(self):
|
||||
html_parts = []
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
# Licensed under the Artistic License 2.0.
|
||||
|
||||
import asyncio
|
||||
import collections
|
||||
import contextlib
|
||||
import itertools
|
||||
import os
|
||||
|
|
@ -77,11 +76,10 @@ def appearance_as_html(appearance):
|
|||
"\n<pre>" + "<br>".join(lines) + "</pre>")
|
||||
|
||||
|
||||
class Row(collections.UserList):
|
||||
class Row:
|
||||
|
||||
def __init__(self, widgets, widths_func=even_widths):
|
||||
collections.UserList.__init__(self, widgets)
|
||||
self.widgets = self.data
|
||||
self.widgets = widgets
|
||||
self.widths_func = widths_func
|
||||
|
||||
def appearance(self, dimensions):
|
||||
|
|
|
|||
|
|
@ -545,11 +545,13 @@ class Result:
|
|||
self.path = path
|
||||
self.tool = tool
|
||||
self.compression = None
|
||||
self.pickle_path = os.path.join(CACHE_PATH, path + "-" + tool.__name__)
|
||||
self.scroll_position = (0, 0)
|
||||
self.status = Status.pending
|
||||
self.is_highlighted = False
|
||||
|
||||
def pickle_path(self):
|
||||
return os.path.join(CACHE_PATH, self.path + "-" + self.tool.__name__)
|
||||
|
||||
@property
|
||||
@lru_cache_with_eviction(maxsize=50)
|
||||
def result(self):
|
||||
|
|
@ -558,15 +560,15 @@ class Result:
|
|||
return unknown_label
|
||||
try:
|
||||
with compression_open_func(self.compression)(
|
||||
self.pickle_path, "rb") as pickle_file:
|
||||
self.pickle_path(), "rb") as pickle_file:
|
||||
return pickle.load(pickle_file)
|
||||
except FileNotFoundError:
|
||||
return unknown_label
|
||||
|
||||
@result.setter
|
||||
def result(self, value):
|
||||
os.makedirs(os.path.dirname(self.pickle_path), exist_ok=True)
|
||||
dump_pickle_safe(value, self.pickle_path,
|
||||
os.makedirs(os.path.dirname(self.pickle_path()), exist_ok=True)
|
||||
dump_pickle_safe(value, self.pickle_path(),
|
||||
open=compression_open_func(self.compression))
|
||||
Result.result.fget.evict(self)
|
||||
|
||||
|
|
@ -610,11 +612,11 @@ class Result:
|
|||
STATUS_TO_TERMSTR[self.status]])
|
||||
|
||||
def get_pages_dir(self):
|
||||
return self.pickle_path + ".pages"
|
||||
return self.pickle_path() + ".pages"
|
||||
|
||||
def delete(self):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.remove(self.pickle_path)
|
||||
os.remove(self.pickle_path())
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
shutil.rmtree(self.get_pages_dir())
|
||||
Result.result.fget.evict(self)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue