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