Revert "Try clearing the cache iff the summary pickle doesn't load."
This reverts commit a04c19c760.
- This caused problems when the api of the pickled objects changed.
This commit is contained in:
parent
5a26b9fd13
commit
e63dd40320
2 changed files with 18 additions and 9 deletions
|
|
@ -219,12 +219,13 @@ class MainTestCase(unittest.TestCase):
|
||||||
# tmp_total = _tmp_total()
|
# tmp_total = _tmp_total()
|
||||||
foo_path = os.path.join(root_path, "foo")
|
foo_path = os.path.join(root_path, "foo")
|
||||||
open(foo_path, "w").close()
|
open(foo_path, "w").close()
|
||||||
|
__main__.manage_cache(root_path)
|
||||||
with __main__.chdir(root_path):
|
with __main__.chdir(root_path):
|
||||||
with contextlib.redirect_stdout(io.StringIO()):
|
with contextlib.redirect_stdout(io.StringIO()):
|
||||||
__main__.main(root_path, loop, worker_count=2,
|
__main__.main(root_path, loop, worker_count=2,
|
||||||
is_being_tested=True)
|
is_being_tested=True)
|
||||||
for file_name in ["summary.pickle", "log", "foo-metadata",
|
for file_name in ["summary.pickle", "creation_time", "log",
|
||||||
"foo-contents"]:
|
"foo-metadata", "foo-contents"]:
|
||||||
self.assertTrue(os.path.exists(".vigil/" + file_name))
|
self.assertTrue(os.path.exists(".vigil/" + file_name))
|
||||||
self.assertEqual(_mount_total(), mount_total)
|
self.assertEqual(_mount_total(), mount_total)
|
||||||
# self.assertEqual(_tmp_total(), tmp_total)
|
# self.assertEqual(_tmp_total(), tmp_total)
|
||||||
|
|
|
||||||
|
|
@ -930,13 +930,7 @@ def load_state(pickle_path, jobs_added_event, appearance_changed_event,
|
||||||
try:
|
try:
|
||||||
with gzip.open(pickle_path, "rb") as file_:
|
with gzip.open(pickle_path, "rb") as file_:
|
||||||
screen = pickle.load(file_)
|
screen = pickle.load(file_)
|
||||||
except (FileNotFoundError, AttributeError):
|
except FileNotFoundError:
|
||||||
cache_path = os.path.join(root_path, tools.CACHE_PATH)
|
|
||||||
if os.path.exists(cache_path):
|
|
||||||
print("Vigil has been updated, so clearing the cache and"
|
|
||||||
" recalculating all results...")
|
|
||||||
shutil.rmtree(cache_path, ignore_errors=True)
|
|
||||||
os.mkdir(cache_path)
|
|
||||||
summary = Summary(root_path, jobs_added_event)
|
summary = Summary(root_path, jobs_added_event)
|
||||||
log = Log(appearance_changed_event)
|
log = Log(appearance_changed_event)
|
||||||
screen = Screen(summary, log, appearance_changed_event, loop)
|
screen = Screen(summary, log, appearance_changed_event, loop)
|
||||||
|
|
@ -1013,6 +1007,19 @@ def chdir(path):
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
|
|
||||||
|
def manage_cache(root_path):
|
||||||
|
cache_path = os.path.join(root_path, tools.CACHE_PATH)
|
||||||
|
timestamp_path = os.path.join(cache_path, "creation_time")
|
||||||
|
if os.path.exists(cache_path) and \
|
||||||
|
os.stat(__file__).st_mtime > os.stat(timestamp_path).st_mtime:
|
||||||
|
print("Vigil has been updated, so clearing the cache and"
|
||||||
|
" recalculating all results...")
|
||||||
|
shutil.rmtree(cache_path)
|
||||||
|
if not os.path.exists(cache_path):
|
||||||
|
os.mkdir(cache_path)
|
||||||
|
open(timestamp_path, "w").close()
|
||||||
|
|
||||||
|
|
||||||
def check_arguments():
|
def check_arguments():
|
||||||
cmdline_help = __doc__ + USAGE.replace("*", "")
|
cmdline_help = __doc__ + USAGE.replace("*", "")
|
||||||
arguments = docopt.docopt(cmdline_help, help=False)
|
arguments = docopt.docopt(cmdline_help, help=False)
|
||||||
|
|
@ -1049,6 +1056,7 @@ def check_arguments():
|
||||||
def entry_point():
|
def entry_point():
|
||||||
root_path, worker_count, editor_command, theme = check_arguments()
|
root_path, worker_count, editor_command, theme = check_arguments()
|
||||||
with terminal.console_title("vigil: " + os.path.basename(root_path)):
|
with terminal.console_title("vigil: " + os.path.basename(root_path)):
|
||||||
|
manage_cache(root_path)
|
||||||
with chdir(root_path): # FIX: Don't change directory if possible.
|
with chdir(root_path): # FIX: Don't change directory if possible.
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
main(root_path, loop, worker_count, editor_command, theme)
|
main(root_path, loop, worker_count, editor_command, theme)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue