mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 22:53:55 +08:00
* too many if
* unused
* whitespace
* key
* sefldrive/car/*
* no more gctx
* lower
* start abstracting common events
* all cars
* start small
* all cars
* reverse gear
* wrongCarMode
* wrongGear
* espDisabled
* steerUnvailable
* make linter happy
* c isn't used
* fix esp_disabled in VW
* update ref
* more red
* more cleanup
* fix subaru
* update ref
old-commit-hash: e8cb6ea06a
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import shutil
|
|
import threading
|
|
from selfdrive.swaglog import cloudlog
|
|
from selfdrive.loggerd.config import ROOT, get_available_bytes, get_available_percent
|
|
from selfdrive.loggerd.uploader import listdir_by_creation
|
|
|
|
MIN_BYTES = 5 * 1024 * 1024 * 1024
|
|
MIN_PERCENT = 10
|
|
|
|
|
|
def deleter_thread(exit_event):
|
|
while not exit_event.is_set():
|
|
out_of_bytes = get_available_bytes(default=MIN_BYTES + 1) < MIN_BYTES
|
|
out_of_percent = get_available_percent(default=MIN_PERCENT + 1) < MIN_PERCENT
|
|
|
|
if out_of_percent or out_of_bytes:
|
|
# remove the earliest directory we can
|
|
dirs = listdir_by_creation(ROOT)
|
|
for delete_dir in dirs:
|
|
delete_path = os.path.join(ROOT, delete_dir)
|
|
|
|
if any(name.endswith(".lock") for name in os.listdir(delete_path)):
|
|
continue
|
|
|
|
try:
|
|
cloudlog.info("deleting %s" % delete_path)
|
|
shutil.rmtree(delete_path)
|
|
break
|
|
except OSError:
|
|
cloudlog.exception("issue deleting %s" % delete_path)
|
|
exit_event.wait(.1)
|
|
else:
|
|
exit_event.wait(30)
|
|
|
|
|
|
def main():
|
|
deleter_thread(threading.Event())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|