Cleanup
This commit is contained in:
parent
c2a1f787a2
commit
46f9597e2e
@ -263,6 +263,9 @@ class Commander(CommandLine):
|
||||
r = self.api.survey(self.ship)
|
||||
pprint(r)
|
||||
|
||||
def do_surveys(self):
|
||||
pprint(list(self.store.all('Survey')))
|
||||
|
||||
def do_extract(self, survey_str=''):
|
||||
if not self.has_ship(): return
|
||||
survey = None
|
||||
|
@ -39,6 +39,9 @@ class Base:
|
||||
def update(self, d):
|
||||
pass
|
||||
|
||||
def is_expired(self):
|
||||
return False
|
||||
|
||||
def load(self, d):
|
||||
self.__dict__ = d
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Survey(SystemMember):
|
||||
|
||||
def path(self):
|
||||
sector, system, waypoint, signature = self.symbol.split('-')
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{waypoint}-{signature}.{self.ext()}'
|
||||
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
||||
|
||||
|
||||
def is_expired(self):
|
||||
|
@ -23,6 +23,8 @@ class Store:
|
||||
self.data = {m: {} for m in self.models}
|
||||
self.system_members = {}
|
||||
self.dirty_objects = set()
|
||||
self.cleanup_interval = 600
|
||||
self.last_cleanup = 0
|
||||
|
||||
def init_models(self):
|
||||
self.models = all_subclasses(Base)
|
||||
@ -126,7 +128,25 @@ class Store:
|
||||
if typ is None or type(m) == typ:
|
||||
yield m
|
||||
|
||||
def cleanup(self):
|
||||
if time() > self.last_cleanup + self.cleanup_interval:
|
||||
return
|
||||
start_time = time()
|
||||
expired = list()
|
||||
for t in self.data:
|
||||
for o in self.all(t):
|
||||
if o.is_expired():
|
||||
expired.append(o)
|
||||
for o in expired:
|
||||
path = o.path()
|
||||
if isfile(path):
|
||||
os.remove(path)
|
||||
del self.data[type(o)][o.symbol]
|
||||
dur = time() - start_time
|
||||
# print(f'cleaned {len(expired)} in {dur:.03f} seconds')
|
||||
|
||||
def flush(self):
|
||||
self.cleanup()
|
||||
it = 0
|
||||
start_time = time()
|
||||
for obj in self.dirty_objects:
|
||||
|
Loading…
Reference in New Issue
Block a user