mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 07:23:37 +08:00
Syncing latest changes between public/private.
This commit is contained in:
parent
3f23969f40
commit
8ce3984404
@ -205,44 +205,44 @@ def update_cache(makefile_dirs: List[str]) -> None:
|
|||||||
# Ok, we've got 2 lists of filenames that we need to cache in the cloud.
|
# Ok, we've got 2 lists of filenames that we need to cache in the cloud.
|
||||||
# First, however, let's look up modtimes for everything and if everything
|
# First, however, let's look up modtimes for everything and if everything
|
||||||
# is exactly the same as last time we can skip this step.
|
# is exactly the same as last time we can skip this step.
|
||||||
mtimes = _gen_modtimes(fnames1 + fnames2)
|
hashes = _gen_hashes(fnames1 + fnames2)
|
||||||
if os.path.isfile(UPLOAD_STATE_CACHE_FILE):
|
if os.path.isfile(UPLOAD_STATE_CACHE_FILE):
|
||||||
with open(UPLOAD_STATE_CACHE_FILE) as infile:
|
with open(UPLOAD_STATE_CACHE_FILE) as infile:
|
||||||
mtimes_existing = infile.read()
|
hashes_existing = infile.read()
|
||||||
else:
|
else:
|
||||||
mtimes_existing = ''
|
hashes_existing = ''
|
||||||
if mtimes == mtimes_existing:
|
if hashes == hashes_existing:
|
||||||
print(
|
print(
|
||||||
f'{CLRBLU}Efrocache state unchanged;'
|
f'{CLRBLU}Efrocache state unchanged;'
|
||||||
f' skipping cache push.{CLREND}',
|
f' skipping cache push.{CLREND}',
|
||||||
flush=True)
|
flush=True)
|
||||||
else:
|
else:
|
||||||
_upload_cache(fnames1, fnames2, mtimes, mtimes_existing)
|
_upload_cache(fnames1, fnames2, hashes, hashes_existing)
|
||||||
|
|
||||||
print(f'{CLRBLU}Efrocache update successful!{CLREND}')
|
print(f'{CLRBLU}Efrocache update successful!{CLREND}')
|
||||||
|
|
||||||
# Write the cache state so we can skip the next run if nothing changes.
|
# Write the cache state so we can skip the next run if nothing changes.
|
||||||
os.makedirs(os.path.dirname(UPLOAD_STATE_CACHE_FILE), exist_ok=True)
|
os.makedirs(os.path.dirname(UPLOAD_STATE_CACHE_FILE), exist_ok=True)
|
||||||
with open(UPLOAD_STATE_CACHE_FILE, 'w') as outfile:
|
with open(UPLOAD_STATE_CACHE_FILE, 'w') as outfile:
|
||||||
outfile.write(mtimes)
|
outfile.write(hashes)
|
||||||
|
|
||||||
|
|
||||||
def _upload_cache(fnames1: List[str], fnames2: List[str], mtimes_str: str,
|
def _upload_cache(fnames1: List[str], fnames2: List[str], hashes_str: str,
|
||||||
mtimes_existing_str: str) -> None:
|
hashes_existing_str: str) -> None:
|
||||||
from efrotools import run
|
from efrotools import run
|
||||||
|
|
||||||
# First, if we've run before, print the files causing us to re-run:
|
# First, if we've run before, print the files causing us to re-run:
|
||||||
if mtimes_existing_str != '':
|
if hashes_existing_str != '':
|
||||||
changed_files: Set[str] = set()
|
changed_files: Set[str] = set()
|
||||||
mtimes = json.loads(mtimes_str)
|
hashes = json.loads(hashes_str)
|
||||||
mtimes_existing = json.loads(mtimes_existing_str)
|
hashes_existing = json.loads(hashes_existing_str)
|
||||||
for fname, ftime in mtimes.items():
|
for fname, ftime in hashes.items():
|
||||||
if ftime != mtimes_existing.get(fname, ''):
|
if ftime != hashes_existing.get(fname, ''):
|
||||||
changed_files.add(fname)
|
changed_files.add(fname)
|
||||||
|
|
||||||
# We've covered modifications and additions; add deletions:
|
# We've covered modifications and additions; add deletions:
|
||||||
for fname in mtimes_existing:
|
for fname in hashes_existing:
|
||||||
if fname not in mtimes:
|
if fname not in hashes:
|
||||||
changed_files.add(fname)
|
changed_files.add(fname)
|
||||||
print(f'{CLRBLU}Updating cache with'
|
print(f'{CLRBLU}Updating cache with'
|
||||||
f' {len(changed_files)} changes:{CLREND}')
|
f' {len(changed_files)} changes:{CLREND}')
|
||||||
@ -270,10 +270,10 @@ def _upload_cache(fnames1: List[str], fnames2: List[str], mtimes_str: str,
|
|||||||
' "cd files.ballistica.net/cache/ba1 && python3 genstartercache.py"')
|
' "cd files.ballistica.net/cache/ba1 && python3 genstartercache.py"')
|
||||||
|
|
||||||
|
|
||||||
def _gen_modtimes(fnames: List[str]) -> str:
|
def _gen_hashes(fnames: List[str]) -> str:
|
||||||
fdict: Dict[str, float] = {}
|
fdict: Dict[str, str] = {}
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
fdict[fname] = os.path.getmtime(fname)
|
fdict[fname] = str(os.path.getmtime(fname))
|
||||||
return json.dumps(fdict, separators=(',', ':'))
|
return json.dumps(fdict, separators=(',', ':'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user