Skip to content

Commit

Permalink
harvester.py: See if any spices are installed before going online
Browse files Browse the repository at this point in the history
to get new metadata.

This also fixes the install paths to align with Spices.py.
  • Loading branch information
mtwebster committed Jan 4, 2023
1 parent c2870ef commit d1e9617
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions python3/cinnamon/harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ def __init__(self, spice_type):

self.index_file = os.path.join(self.cache_folder, "index.json")

self.install_folder = os.path.join(home, ".local/share/cinnamon", "%ss" % self.spice_type)

if self.themes:
self.install_folder = os.path.join(home, ".themes")
self.spices_directories = (self.install_folder, )
old_install_folder = '%s/.themes/' % home
self.spices_directories = (old_install_folder, self.install_folder)
else:
self.install_folder = os.path.join(home, ".local/share/cinnamon", "%ss" % self.spice_type)
self.spices_directories = ("/usr/share/cinnamon/%ss" % self.spice_type,
self.install_folder)
self.spices_directories = (self.install_folder, )

self.disabled = not self.anything_installed()

self._load_cache()
self._load_metadata()
Expand All @@ -172,7 +174,24 @@ def __init__(self, spice_type):
except Exception as e:
print(e)

def anything_installed(self):
for location in self.spices_directories:
path = Path(location)
if not path.exists():
continue

for spice in path.iterdir():
return True

debug("No additional %ss installed" % self.spice_type)
return False

def refresh(self, full):
self.disabled = not self.anything_installed()

if self.disabled:
return

debug("Cache stamp: %d" % get_current_timestamp())

os.makedirs(self.cache_folder, mode=0o755, exist_ok=True)
Expand Down Expand Up @@ -265,6 +284,9 @@ def _download_thumb(self, uuid, item):
f.write(r.content)

def _load_metadata(self):
if self.disabled:
return

debug("harvester: Loading metadata on installed %ss" % self.spice_type)
self.meta_map = {}

Expand Down Expand Up @@ -292,6 +314,9 @@ def _load_metadata(self):
pass

def _load_cache(self):
if self.disabled:
return

debug("harvester: Loading local %s cache" % self.spice_type)
self.index_cache = {}

Expand All @@ -310,6 +335,9 @@ def _load_cache(self):
debug(e)

def _generate_update_list(self):
if self.disabled:
return []

debug("harvester: Generating list of updated %ss" % self.spice_type)

self.updates = []
Expand Down

0 comments on commit d1e9617

Please sign in to comment.