-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cache from version control and create caching module #27
- Loading branch information
Showing
5 changed files
with
82 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ __pycache__/ | |
htmlcov/ | ||
dist/ | ||
*.egg-info/ | ||
.tox/ | ||
.tox/ | ||
|
||
tests/data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import os | ||
|
||
CACHE_DIR = "./tests/data/" | ||
CACHE_PATH = CACHE_DIR + "data.json" | ||
|
||
|
||
def get_info(obj): | ||
"""Load client-side info for an Earth Engine object. | ||
Info is retrieved (if available) from a local JSON file using the serialized | ||
object as the key. If the data does not exist locally, it is loaded from Earth | ||
Engine servers and stored for future use. | ||
""" | ||
serialized = obj.serialize() | ||
|
||
if not os.path.isdir("./tests/data"): | ||
os.mkdir("./tests/data") | ||
|
||
try: | ||
with open("./tests/data/data.json") as src: | ||
existing_data = json.load(src) | ||
|
||
# File is missing or unreadable | ||
except (FileNotFoundError, json.JSONDecodeError): | ||
existing_data = {} | ||
with open("./tests/data/data.json", "w") as dst: | ||
json.dump(existing_data, dst) | ||
|
||
# File exists, but info does not | ||
if serialized not in existing_data: | ||
with open("./tests/data/data.json", "w") as dst: | ||
existing_data[serialized] = obj.getInfo() | ||
json.dump(existing_data, dst, indent=2) | ||
|
||
return existing_data[serialized] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.